grimbergen Posted June 2, 2008 Share Posted June 2, 2008 Hello, I'm trying to read dynamic form input fields but the receiving page isn't able to read it, and I can't figure out why. Here's what I'm trying to accomplish... Page 1: Creates a list of event name from my database. Next to each event are select menus for the user to select dates. I've tried various ways of constructing the select input field names, but none seem to transfer to the next page. The code looks something like this: //this code is from a while loop through $optionslist print "<input type=checkbox name='$optionslist[name]'> print $optionslist[name]; $optionyear=$optionslist[name]."yyyy"; print " <select name='$optionslist[name]mm'> <option>MM</option> $monthselect <select name='$optionslist[name]dd' > <option>DD</option> $dayselect <select name='$optionyear'> <option>YYYY</option> $yearselect "; ($monthselect, $dayselect, $yearselect are pregenerated lists of date elements) Page 2: The receiving page is supposed to receive the form post, again it is a while loop through the array of events. Again I tried various ways of naming the date form post names, but none seem to work. However the name of the event that is passed thru for the checkbox is captured properly. $optionyear=$optionsrow[name]."yyyy"; $monthinput="mm"; $dayinput="dd"; $optionname=$optionslist[name]; if ($_POST[$optionname]) print "<input type=hidden name='option$counter' value='$optionname | $_POST[$optionname]| $_POST[$optionslist[name].$monthinput]| $_POST[$optionslist[name].$dayinput]| $_POST[$optionyear'>"; (I've added in spacing to make it legible for this post) Any ideas on what I'm doing wrong? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/108416-help-with-makingreading-dynamic-_post-names/ Share on other sites More sharing options...
ag3nt42 Posted June 2, 2008 Share Posted June 2, 2008 the only thing i've noticed from looking here just briefly is you have quite a few quotes missing. ie. $something=$_POST['some']; also i noticed that your printing incorrectly wrong way: print "<input type=checkbox name='$optionslist[name]'> output: <input type=checkbox name='$optionslist[name]'> correct way: print"<input type='checkbox' name='" . $optionslist[name] . "'>"; output: <input type='checkbox' name='Optionslistname'> Quote Link to comment https://forums.phpfreaks.com/topic/108416-help-with-makingreading-dynamic-_post-names/#findComment-555955 Share on other sites More sharing options...
grimbergen Posted June 2, 2008 Author Share Posted June 2, 2008 Thanks for the review. I didn't copy the code directly and retyped it to be legible here. Though the quotes don't seem to be the issue -- when I use them with $variables in the $_POST[], they don't work anyhow. Quote Link to comment https://forums.phpfreaks.com/topic/108416-help-with-makingreading-dynamic-_post-names/#findComment-556017 Share on other sites More sharing options...
DarkWater Posted June 2, 2008 Share Posted June 2, 2008 @ag3nt42: Not quite. The "wrong" method (that he has now) should actually error him out. I'm interested as to why it isn't. Quote Link to comment https://forums.phpfreaks.com/topic/108416-help-with-makingreading-dynamic-_post-names/#findComment-556020 Share on other sites More sharing options...
grimbergen Posted June 2, 2008 Author Share Posted June 2, 2008 @ag3nt42: Not quite. The "wrong" method (that he has now) should actually error him out. I'm interested as to why it isn't. Hello DW, can you let me know which one is the wrong method? I don't receive any errors, the page renders fine, just the post variables are blank. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/108416-help-with-makingreading-dynamic-_post-names/#findComment-556031 Share on other sites More sharing options...
sasa Posted June 2, 2008 Share Posted June 2, 2008 change form part to <?php //this code is from a while loop through $optionslist print "<input type=checkbox name='chk[]' value='$optionslist[name]'>" ; print $optionslist[name]; //$optionyear=$optionslist[name]."yyyy"; print " <select name='mm[$optionslist[name]]'> <option>MM</option> $monthselect <select name='dd[$optionslist[name]]' > <option>DD</option> $dayselect <select name='yy[$optionslist[name]]'> <option>YYYY</option> $yearselect "; ?> and Page 2 to <?php if (isset($_POST['chk'])){ foreach ($_POST['chk'] as $name){ $m = $_POST['mm'][$name]; $d = $_POST['dd'][$name]; $y = $_POST['yy'][$name]; echo 'Name: ', $name,' | MM: ', $m, ' | DD: ', $d, ' | YYYY: ', $y, "<br />\n"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/108416-help-with-makingreading-dynamic-_post-names/#findComment-556033 Share on other sites More sharing options...
DarkWater Posted June 2, 2008 Share Posted June 2, 2008 print "<input type=checkbox name='$optionslist[name]'> You need to enclose arrays in { } when echoing them in double quotes...I have no idea why it's not erroring you. Quote Link to comment https://forums.phpfreaks.com/topic/108416-help-with-makingreading-dynamic-_post-names/#findComment-556036 Share on other sites More sharing options...
discomatt Posted June 2, 2008 Share Posted June 2, 2008 Not using standard coding practices will slow down the speed in which we can help you. Though PHP will fall back to a string when the constant isn't found (using a string without quotes), it will generate a 'Notice' error (assuming error reporting levels allow this), and is still technically wrong. Here are the right ways to use associative (named, string-based keys) arrays in your output/declarations <?php error_reporting( E_ALL ); $arr['val1'] = 'something'; # or $arr["val2"] = 'something else'; #or also $text = 'val3'; $arr[$text] = 'something further'; # WRONG $arr[val4] = 'another'; # As PHP is expecting val4 to be a constant # Using in returns/output echo 'This is ' . $arr["val1"] . ' or ' . $arr['val2'] . ' or even ' . $arr[$text] . '<br>'; echo "Using in a double quoted string is {$arr['val1']} different as well. {$arr[$text]} can be used as well."; ?> Returns Notice: Use of undefined constant val4 - assumed 'val4' in C:\wamp\www\test.php on line 13 This is something or something else or even something further Using in a double quoted string is something different as well. something further can be used as well. Quote Link to comment https://forums.phpfreaks.com/topic/108416-help-with-makingreading-dynamic-_post-names/#findComment-556037 Share on other sites More sharing options...
grimbergen Posted June 4, 2008 Author Share Posted June 4, 2008 Thanks for the help sasa and discomatt!!! It worked! You guys rock! Quote Link to comment https://forums.phpfreaks.com/topic/108416-help-with-makingreading-dynamic-_post-names/#findComment-557047 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.