PHP Form values not showing

Hello! My form won’t show the values unless I add them to the required = array and not everything is required. So the firname, lasname, and email will show in the email that’s sent but it won’t show the phone and message (I have other fields to add too).
I don’t know PHP at all. Please help I need this fixed asap!
Here is my code:
[php]<?php

if(!$_POST) exit;

$email = $_POST[‘email’];

//$error[] = preg_match(’/\b[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}\b/i’, $POST[‘email’]) ? ‘’ : ‘INVALID EMAIL ADDRESS’;
if(!eregi("^[a-z0-9]+([
\.-][a-z0-9]+)" ."@"."([a-z0-9]+([.-][a-z0-9]+))+"."\.[a-z]{2,}"."$",$email )){
$error.=“Invalid email address entered”;
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array(‘firname’,‘lasname’,‘email’,‘phone’,‘message’);
$required = array(‘firname’,‘lasname’,‘email’,);

$your_email = "[email protected]";
$email_subject = "Reservations Form: ".$_POST['subject'];
$email_content = "new reservation:\n";

foreach($values as $key => $value){
  if(in_array($value,$required)){
	if ($key != 'subject' && $key != '') {
	  if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
	}
	$email_content .= $value.': '.$_POST[$value]."\n";
  }
}
 
if(@mail($your_email,$email_subject,$email_content)) {
	header('Location: http://www.example.com/test/reservation-submission.html');

} else {
	echo 'ERROR!';
}

}
?>
[/php]

Here is my html form:

[code]


  1. First Name *


  2. Last Name *


  3. Email *


  4. Phone Number *


  5. Best Time To Call

    Morning
    Afternoon
    Evening




  6. Age

    25+
    21-24




  7. Rental *

    12 Passenger Van
    15 Passenger Van
    Cargo Van



  8. Pick up Location *

    Select Location
    U-Save JFK
    U-Save LGA



  9. Estimated Mileage

    Under 100
    100-500
    500+




  10. Pick Up Date *
    Calendar



  11. Pick Up Time *

    12:00 am 12:30 am
    01:00 am 01:30 am
    02:00 am 02:30 am
    03:00 am 03:30 am
    04:00 am 04:30 am
    05:00 am 05:30 am
    06:00 am 06:30 am
    07:00 am 07:30 am
    08:00 am 08:30 am
    09:00 am 09:30 am
    10:00 am 10:30 am
    11:00 am 11:30 am
    12:00 pm 12:30 pm
    01:00 pm 01:30 pm
    02:00 pm 02:30 pm
    03:00 pm 03:30 pm
    04:00 pm 04:30 pm
    05:00 pm 05:30 pm
    06:00 pm 06:30 pm
    07:00 pm 07:30 pm
    08:00 pm 08:30 pm
    09:00 pm 09:30 pm
    10:00 pm 10:30 pm
    11:00 pm 11:30 pm




  12. Drop Off Date *
    Calendar



  13. Drop Off Time *

    12:00 am 12:30 am
    01:00 am 01:30 am
    02:00 am 02:30 am
    03:00 am 03:30 am
    04:00 am 04:30 am
    05:00 am 05:30 am
    06:00 am 06:30 am
    07:00 am 07:30 am
    08:00 am 08:30 am
    09:00 am 09:30 am
    10:00 am 10:30 am
    11:00 am 11:30 am
    12:00 pm 12:30 pm
    01:00 pm 01:30 pm
    02:00 pm 02:30 pm
    03:00 pm 03:30 pm
    04:00 pm 04:30 pm
    05:00 pm 05:30 pm
    06:00 pm 06:30 pm
    07:00 pm 07:30 pm
    08:00 pm 08:30 pm
    09:00 pm 09:30 pm
    10:00 pm 10:30 pm
    11:00 pm 11:30 pm



  14.         <li><label>Additional Infomation</label>
              <textarea id="message" name="message" rows="6" cols="50"></textarea>
            </li>
            <li class="button1">
              <input type="image" name="imageField" id="imageField" src="images/reserve-now-btn.png" class="send" />
              <div class="clr"></div>
            </li>
          </ol>
        </form>[/code]
    

    I’d appreciate any help. Thanks!

OK,
Don’t need the array. as you can pick and choose what you want, the rest is ignored.
You have a lot of form variables that are not used in your code, so there is not really a QUICK FIX to this.
Given what you have shown, you will need a pretty big rewrite.
To keep this simple as possible - keeping to your code try this:

[php]

<?php if(!$_POST) exit; $email = $_POST['email']; $error = ''; $email_content = ''; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error .="Invalid email address entered"; } // loop through the post NOT THE ARRAY - Which currently held nothing if($error == '') { foreach($_POST as $key=>$value) { if ($value) == '') { $error .= 'Please fill in all required fields'; } $email_content .= $key.': '.$value."\n"; } } // everything checks out (?) if($error == '') { $your_email = $_POST['email']; $email_subject = 'Reservations'; if(@mail($your_email,$email_subject,$email_content)) { header('Location: http://www.example.com/test/reservation-submission.html'); } else { echo 'ERROR SENDING MAIL!'; } } ?>[/php]

I did this in a few minutes… but it really needs a rewrite. Couple things on your code. the reason you were not getting anything as you were cycling through ARRAY variables that were not assigned

your array
[php]$values = array(‘firname’,‘lasname’,‘email’,‘phone’,‘message’);[/php]

then looping through it:
[php]foreach($values as $key => $value){[/php]

in this example the first value ‘firstname’ is not assigned anything (yes i know you are tyring to search through the post see mine above). so the $key = ‘firstname’ and value is ‘’ (or empty string as it is not assigned)

so the following:
[php] if( empty($_POST[$value]) )[/php]
will always be empty as it wil reas as $_POST[]. You are looking for $_POST[‘firstname’], BUT to do that, you need to loop through the post variables. not the $value ARRAY.

This looks like a copy/paste code. But I might come back to it later, if no one else has taken the challenge and see if I can put something together that would work better.

Good luck.

Sponsor our Newsletter | Privacy Policy | Terms of Service