mendoz Posted April 1, 2007 Share Posted April 1, 2007 Hey guys. I have a form with 100+ fields (a client, don't ask) I guess I can be doing $_POSTs all day long and then a long long query. Maybe you heard about an easier method... Thanks, Dror Link to comment https://forums.phpfreaks.com/topic/45132-any-ideas-on-handling-a-big-big-form/ Share on other sites More sharing options...
tarun Posted April 1, 2007 Share Posted April 1, 2007 Have It As An Array Then Use foreach Link to comment https://forums.phpfreaks.com/topic/45132-any-ideas-on-handling-a-big-big-form/#findComment-219088 Share on other sites More sharing options...
mendoz Posted April 1, 2007 Author Share Posted April 1, 2007 Thanks man but use what as an array ??? Link to comment https://forums.phpfreaks.com/topic/45132-any-ideas-on-handling-a-big-big-form/#findComment-219089 Share on other sites More sharing options...
mendoz Posted April 1, 2007 Author Share Posted April 1, 2007 <?php foreach($_POST as $varName => $value) { $dv=$value; print "<b>$varName</b>: $dv<br>"; }; ?> seemed to work Link to comment https://forums.phpfreaks.com/topic/45132-any-ideas-on-handling-a-big-big-form/#findComment-219096 Share on other sites More sharing options...
kenrbnsn Posted April 1, 2007 Share Posted April 1, 2007 Why are you creating another variable in your loop, this will work just as well: <?php foreach($_POST as $varName => $value) echo "<b>$varName</b>: $value<br>"; ?> BTW, you shouldn't have the semi-colon after the closing "}". Ken Link to comment https://forums.phpfreaks.com/topic/45132-any-ideas-on-handling-a-big-big-form/#findComment-219100 Share on other sites More sharing options...
TheBG Posted April 1, 2007 Share Posted April 1, 2007 Here you go. This will handle any size form, check for required entries AND stop the bad guys... //************************************************************************ // // Form Handler // // $to = email address to send to // $subject = subject statement for email // $expected = ARRAY - list of expected fields // This is a BIG security check mesure which will not allow insertion of // additional fields because only the fields you are looking for will be processed! // $required = ARRAY - a list of required fields // $missing = ARRAY - empty // //************************************************************************ if (array_key_exists('submit', $_POST)) { $to = [email protected]'; $subject = 'Feedback from Web site'; // Expected fields $expected = array('name', 'email', 'phone', 'comment'); // Required fields $required = array('name', 'email'); //Missing fields $missing = array(); // process the $_POST variables foreach( $_POST as $key => $value) { $temp = is_array($value) $value : trim($value); //if empty AND required add to $missing array if( empty($temp) && in_array($key, $required)) { array_push($missing, $key); } //otherwise assign to a variable with same name as $key // BIG security check! DO NOT EDIT! elseif( in_array($key, $expected)) { ${$key}=$temp; } } Link to comment https://forums.phpfreaks.com/topic/45132-any-ideas-on-handling-a-big-big-form/#findComment-219236 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.