|
Posted by 4sak3n 0ne on 09/04/07 20:37
On Sep 4, 8:00 am, Kevin Davis <kevin.da...@kevincdavis.net> wrote:
> Hello,
>
> I'm a new person when it comes to PHP and I have a quick question.
>
> I would like to create a form that will allow the user to add more
> information using the same form in case they have (similar to various
> employment sites).
>
> What would be the best way of using form arrays for that function?
>
> Thank you,
> Kevin
I would have an input with a name that is translated to an array.
Have some javascript create the additional inputs...
<form action="something.php" method="post">
<input type="text" name="inputbox[]" value="" />
<input type="text" name="inputbox[]" value="" />
</form>
When this is posted, you can use a foreach loop to run through it. If
you use this method, be sure to check for empty values, because once
the form has been created, its added to the array, empty or not.
if(isset($_POST['inputbox'])){
echo "<h2>Output:</h2>";
echo "<ul>\n";
foreach($_POST['inputbox'] as $v){
echo (!empty($v)) ? "<li>{$v}</li>\n" : "";
}
echo "</ul>\n";
}
Navigation:
[Reply to this message]
|