note 42350 deleted from language.types.array by tomsommer
| From: | tomsommer@php.net | Date: | Sat, 03 Jul 2004 13:14:37 +0000 |
| Subject: | note 42350 deleted from language.types.array by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72415@lists.php.net to get a copy of this message | ||
Note Submitter: tomy@sorosy.com
----
If you are trying to use arrays in a form and want to handle them from PHP as well as JSCRIPT, you
do not need to follow agape_logos complicated solution below.
For PHP you need to add "name" tags to the inputs of the form, for the script you need to
add "id" tags.
<?
// Walk all the rows of the submitted table
// Should not walk through the checkboxes because only checked boxes values are submitted, not
all!
// e.g. count( $mytextfield ) != count( $update )
for ( $p = 0; $p < count( $mytextfield ); $p++ )
{
// Check if the update box is checked for this row
if ( $update[ $p ] =="on" )
{
echo( "Updated text \"" . $mytextfield[ $p ] . "\" in row
" . $p . "<br>" );
}
}
?>
<table>
<form action=" <? echo( $PHP_SELF ); ?> " method="post">
<?
$p = 0;
// Now build the table
for( [ADD FOR STUFF HERE] )
{
echo( "<tr>" );
// Add one column with text fields
// The onchange stuff will make the corresponding checkbox auto-check
echo( "<td><input type=\"text\" name=\"mytextfield[" . $p .
"]\" onchange=\"javascript:document.all.mytextfield_" . $p .
".checked=true;\"><br>" );
// Add another column with checkboxes
// These boxes will auto-check when the contents of the text field in the same row change
echo( "<td><input type=\"checkbox\" name=\"update[" . $p .
"]\" id=\"mytextfield_" . $p . "\"></td>" );
echo( "</tr>" );
$p++;
}
?>
<input type="submit" value="Update!">
</form>
</table>