Re: Dynamic Form 'on The Fly'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bob McConnell wrote:
> From: revDAVE
>> Using a repeating region of a query, I want to generate a 'form on the
> fly'
>> So for each repeat - I have an extra form input....
>>
>> Each input name = thisline<?php echo $cnt; ?>
>>
>> So it will make names like:
>>
>> thisline1
>> thisline2
>> thisline3
>> Etc.
>>
>> For the form fields
>>
>> -------------------------
>>
>> $cnt = 1;
>> <form action="form1.php" method="post" name="test1">
>>
>> Repeat.....
>>          
>> <input name="go<?php echo $cnt; ?>" type="text" value="" size="5"
>> maxlength="5" />
>>
>>  <?php      $cnt++;     ?>
>>
>> Repeat..................
>>
>> ------------------------------------
>>
>> Q: how do I code the POST line to READ this when processing this form?
>>
>> like:
>>
>> $cnt = 1;
>>
>>  <?php echo $_POST['thisline$cnt']; ?> ???? Doesn't work...?
>>  <?php echo $_POST['thisline'].$cnt; ?>???? Doesn't work...?
>>
>> Not this either...
>> $this = 'thisline'.$cnt;
>> echo $_POST['$this'];
>>
>>
>> $cnt++
>>
>> Q: ANY Ideas?
> 
> For a text field, you use the name attribute (or id for xhtml), so how
> about:
> 
>   $_POST['go'.$cnt]
> 
> I think $_POST['go$cnt'] might also work.
> 
> Bob McConnell

What Bob said, and, may I suggest that arrays would be a better way to
go here?

This auto-assign the next array index: 1, 2, 3, etc... just like in PHP:

<input name="go[]" type="text" value="" size="5" maxlength="5" />
<input name="go[]" type="text" value="" size="5" maxlength="5" />

Then access $_POST:

echo $_POST['go'][0];
echo $_POST['go'][1];

Or in a loop using your incremental var:

echo $_POST['go'][$cnt];
	

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux