Jump to content

filling an array from html form


mrplatts

Recommended Posts

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

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
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 28

I'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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.