note 42350 added to language.types.array

From: Date: Thu, 13 May 2004 06:58:05 +0000
Subject: note 42350 added to language.types.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-69546@lists.php.net to get a copy of this message
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> ---- Manual Page -- http://www.php.net/manual/en/language.types.array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42350 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42350&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42350&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69546) next »