PDA

Click to See Complete Forum and Search --> : input name fields with html variables and php


damasterjo
May 12th, 2006, 03:04 PM
<?$i = 0
$num= 10
while ($i < $num) {?>
<input type="submit" name="<?$i?>order1" value="Order This">
<?$i++?> }

where then I could call like

if ($iorder1){}

???

damasterjo
May 12th, 2006, 03:12 PM
name="<?echo $i?>order1"
ok got how to change name name's now need to learn how to call to it...

and P.S. I NEED to get firefox, way better!

john tindell
May 12th, 2006, 06:17 PM
you could use hidden fields

<?$i = 0
$num= 10
while ($i < $num) {?>
<input type="hidden" name="function" value="<?php echo $i; ?>order1"/>
<input type="submit" name="<?$i?>order1" value="Order This" />
<?$i++?> }


then

if($_POST['function']=="1order1")
{
//function code
}
//.... etc

penagate
May 13th, 2006, 03:03 AM
Give your submit buttons all the same name and each a unique value (which is its caption). When the form is posted you can tell which submit button was pressed just like any other input field.

<div>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Which do you prefer?</p>
<p><input type="submit" name="fsubmit" value="Puppies"></p>
<p><input type="submit" name="fsubmit" value="Kittens"></p>
</form>
</div>

switch ($_POST['fsbumit']) {
case 'Puppies':
# ...
break;
case 'Kittens':
# ...
break;
}

If you're using XHTML remember to close the input tags with a />.