You are here: Re: adding more fields to a form « PHP Programming Language « IT news, forums, messages
Re: adding more fields to a form

Posted by Adam Plocher on 09/27/01 11:37

Johnny, I'm not sure if I understand you correctly, but you can try
this:

note.. I didn't test this code, but I think this is what you're looking
for.

<?PHP

if ($_POST['Submit'])
{
$field = $_POST['field'];

for ($i = 0; $i < count($field); $i++)
{
// echo all results
echo $field[$i] ."<br />\n";
}
}
else
{
// $fc = field count

$fc = $_POST['fc'];
if (!is_numeric($fc) || $fc == "")
{
// if fc isn't set - default it to 1
$fc = 1;
}

if ($_POST['AddField'])
{
// if AddField button was clicked - increment $fc
$fc++;
}
?>
<form action="<?PHP echo $_SERVER['PHP_SELF'];?>" method="post">
<?PHP
for ($i = 1; $i <= $fc; $i++)
{
echo "<input type=\"text\" name=\"field[". $i ."]\"
value=\"\"><br />\n";
}
?>
<input type="submit" name="AddField" value="add more fields">
<input type="submit" name="Submit" value="submit">
<input type="hidden" name="fc" value="<?PHP echo $i;?>">
</form>
<?PHP
}
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация