Page 1 of 1

Submit all form fields?

Posted: Fri Jan 29, 2010 11:16 am
by Sindarin
Is there something I can do instead of this:

Code: Select all

 
$row_dvd_player = strip_tags($_POST['row_dvd_player']);
$row_cd_player = strip_tags($_POST['row_cd_player']);
$row_mp3_player = strip_tags($_POST['row_mp3_player']);
 
There are like 200 fields in that form that also need to be inserted into a database! 8O

This did not work as expected:

Code: Select all

$x=0;
foreach($_POST as $key => $data) {
 
       $fields[$x]= $data;
       $x=x+1;
        echo $data.'<br/>'.$x;
  
}
 
echo 'VALUE: '.$fields[0].'<br/>';
Mind you, I have some file fields as well.

Re: Submit all form fields?

Posted: Fri Jan 29, 2010 12:02 pm
by klevis miho
Not sure for other types of input, but for checkboxes use the name="name[]" for example:

<input type="checkbox" name="test[]" value="value1" />
<input type="checkbox" name="test[]" value="value2" />

and then try a

print_r($_POST['test']);

Re: Submit all form fields?

Posted: Fri Jan 29, 2010 1:02 pm
by AbraCadaver
Not sure what you are trying to eliminate, the strip_tags(), or the variable assignments? If I get it right, this is an example:

Code: Select all

$fields = "`".implode("`,`", array_keys($_POST))."`";
$values = "'".implode("','", array_map('stripslashes', $_POST))."'";
You could write your own function to use with arr_map() as well. Add a check for magic_quotes_gpc(), quote if not numeric, etc...