Jump to content

Any ideas on handling a big big form?


mendoz

Recommended Posts

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
Share on other sites

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 = someone@email.com';

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.