Jump to content

newbie: checkbox array problem


helloise
 Share

Recommended Posts

i need to loop through a checkbox array and as soon as i find that one is checked i must ENable a submit botton..i have my code as: <form action="<?php echo url_for('doc/document'); ?>" method="post"><input type='hidden' name='service_id' value='<?php echo $service->getId() ?>'><table width='1000px' border='0' cellspacing='0'> <tr> <td class='td_header_2' align='left' colspan='2' width='50%'> Available products for service: <?php echo $service->getName()?> </td> </tr> <tr> <table width='600px' class='tbl_content_box' border='0' cellspacing='0'> <tr> <td width='100px'>Products:</td> <td width='100px'>Graphic</td> <td width='100px'>Text</td> </tr> </table> <table> <table width='600px' class='tbl_content_box' border='0' cellspacing='0'><?php $product_names = LpmPagePeer::getByAllProdNames($service->getId()); foreach($product_names as $product_row) { ?> <tr> <td > </td><td width='200px'><?php echo $product_row->getName(); ?></td> <td width='200px'><input type="checkbox" name="graphic[]" value="<?php echo $product_row->getId();?>" /></td> <td width='200px'><input type="checkbox" name="text[]" value="<?php echo $product_row->getId();?>" /></td> </tr> <?php } ?> </table> <table> <tr> <td> <input type='hidden' name='submit' value='Submit'> <?php $graphics_selected = $_POST['graphic']; // line 35: get error here foreach($graphics_selected as $val) //line 36: and here see errors at bottom of code pls { echo "blablabl"; } if ( (isset($graphic)) || (isset($text) )) { echo "checkboxes checked"; //show submit button } else { //hide submit botton and echo "no boxes check"; } ?> </td> </tr> </table></form>Notice: Undefined index: graphic in /home/helloises/svn_wappool/apps/lpmanager/modules/doc/templates/productSuccess.php on line 36 Warning: Invalid argument supplied for foreach() in /home/helloises/svn_wappool/apps/lpmanager/modules/doc/templates/productSuccess.php on line 37 no boxes checkis there another way of doing this??as the form opens no checkboxes are checked obviously and i want submit button DISabled, as soon as the user checks on i want it ENabledplease helpthanks

Link to comment
Share on other sites

I'm not sure you are understanding the principles of how Javascript and PHP run. PHP only runs on the server, and before the code gets rendered in the browser. Javascript run entirely in the browser, and the only way the two meet is through AJAX, but that's not necessary here. A simple form on the client side and a form handler on the server side are all that is needed, form the looks of it anyway. I think for this situation your are looking for a Javascript solution, wherein an event handler binded to an element on the page causes another event to happen, in this case the showing of a submit button. When that form gets submitted, and you pass all the elements to the PHP page for processing, the checked box and it's value will be available to you in the GET or POST arrays, at which point you can process the form and do any redirections, logic, etc that you need to do. This is all possible to do on one page, but we can get to that after you understand how to write your code.have you read through the tutorials yet on form handling?http://www.w3schools.com/php/php_forms.asp

Edited by thescientist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...