jwwceo Posted September 29, 2006 Share Posted September 29, 2006 I have a bunch of dynamic form fields which are posted on my php page. The field names are being posted with a variable in them like this<input type ='checkbox'......name='color{$colorid}'....> so each checkbox has it's own id. I think this is working ok, but when I try to get this value on the next page I am having a hard time retrieving the value.I am trying this:if(isset($_POST['color$colorid'])) and if(isset($_POST['color.$colorid'])), but I can't get the right syntax.what am I doing wrong???James Quote Link to comment Share on other sites More sharing options...
printf Posted September 29, 2006 Share Posted September 29, 2006 You should be using...[code]<input type ='checkbox' name='color[<?=$colorid;?>]' value='some_value' />[/code]It makes it much easier, because PHP will load that into an array! is_set does not allow variable assignments, use ! empty () instead![code=php:0]<?if ( ! empty ( $_POST['product_id'] ) ){ $pid = intval ( $_POST['product_id'] ); echo 'Product ID: (' . $pid . ')'; if ( is_array ( $_POST['colors'][$pid] ) ) { foreach ( $_POST['colors'][$pid] AS $color ) { echo ', ' . $color; } } else { echo ', no colors selected'; }}// this is just here to show you the example$product_id = 89042567;?><form action='' method='post'>pid <input type='text' name='product_id' value='<?=$product_id;?>' /><br />Red <input type='checkbox' name='colors[<?=$product_id;?>][]' value='red' /> <br />Blue <input type='checkbox' name='colors[<?=$product_id;?>][]' value='blue' /> <br />Green <input type='checkbox' name='colors[<?=$product_id;?>][]' value='green' /> <br />Yellow <input type='checkbox' name='colors[<?=$product_id;?>][]' value='yellow' /> <br /><input type='submit' value='Select Colors' /></form>[/code]me! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.