mrplatts Posted November 13, 2006 Share Posted November 13, 2006 I need to fill an array with dates from an HTML form. The user should be able to enter dates, but the number of dates could be different each time. I tried to write it with the form submitting to itself and then displaying the contents of the array in a box next to the field. however, I realize that each time that I submit the form,[POST] there is a new array created, not an additional entry into the array, only the most recent addition goes in. Is there a better way to fill an array from a web form? I'm learning a lot from reading this forum & am basically learning PHP as I go. I'm sure my code will need to be seriously re-written when I'm "done" Link to comment https://forums.phpfreaks.com/topic/27060-filling-an-array-from-html-form/ Share on other sites More sharing options...
doni49 Posted November 13, 2006 Share Posted November 13, 2006 In the form:<p>One Date per Line</p><input type="textarea" name="dates" cols="20" rows="5">Then in script:$dates = explode("\n",add_slashes($_POST['dates'])); Link to comment https://forums.phpfreaks.com/topic/27060-filling-an-array-from-html-form/#findComment-123774 Share on other sites More sharing options...
Monkeymatt Posted November 13, 2006 Share Posted November 13, 2006 A form name with [] after it will automatically fill an array on the PHP page - this could be used with javascript to get a dynamic number of dates.[code]<input type="text" name="dates[]" />[/code]would make an array:[code]$_POST['dates'][0], $_POST['dates'][1], ...[/code]Monkeymatt Link to comment https://forums.phpfreaks.com/topic/27060-filling-an-array-from-html-form/#findComment-123778 Share on other sites More sharing options...
mrplatts Posted November 13, 2006 Author Share Posted November 13, 2006 I implemented the idea above, it made sense to me... I wrote: [code]$excepts = $HTTP_POST_VARS['exceptions'];if($excepts){$excepts[] = explode("\n",add_slashes($_POST['exceptions']));foreach ($excepts as $field => $label) { list($xm, $xd, $xy) = explode("-", $label); // seperate the month, date & year $label = $xy."-".$xm."-".$xd; / reassemble in MySQL format }}[/code]And I got: Fatal error: Call to undefined function: add_slashes() in /home3/mrplatts/mrplatts-www/sched/cal_setup.html on line 28I'm not really sure if the way I wrote it puts it back into the same spot on the array. Usually I mess with it until it does what I want. Rich Link to comment https://forums.phpfreaks.com/topic/27060-filling-an-array-from-html-form/#findComment-124102 Share on other sites More sharing options...
mrplatts Posted November 13, 2006 Author Share Posted November 13, 2006 Ahaaddslashes not add_slashes Link to comment https://forums.phpfreaks.com/topic/27060-filling-an-array-from-html-form/#findComment-124132 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.