Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:36:21+00:00 2026-06-16T03:36:21+00:00

My form won’t show the values unless I add them to the required =

  • 0

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).

Here is my code:

<?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 = "aasdasd@email.com";
    $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!';
    }
}
?>`

<form action="reservations.php" method="post" id="contactform">
      <ol>
        <li><label>First Name *</label>
          <input id="firname" name="firname" class="text" value="" />
        </li>
         <li><label>Last Name *</label>
          <input id="lasname" name="lasname" class="text" value="" />
        </li>
        <li><label>Email *</label>
          <input id="email" name="email" class="text" type="email" value="" />
        </li>
        <li><label>Phone Number *</label>
          <input id="phone" name="phone" class="text" value="" />
        </li>
        <li><label>Best Time To Call</label>
          <select name="best time to call" id="call" class="drop">
        <option selected="selected" value="Morning">Morning</option>
        <option value="Afternoon">Afternoon</option>
        <option value="Evening">Evening</option>
                </select>
        </li>
        <br />
        <li><label>Age</label>
          <select name="age" id="age" class="drop">
        <option selected="selected" value="25+">25+</option>
        <option value="21-24">21-24</option>
                </select>
        </li>
        <br />
        <li> <label> Rental *</label>
        <select name="rental" id="rental" class="drop">
        <option selected="selected" value="12 Passenger Van">12 Passenger Van</option>
        <option value="15 Passenger Van">15 Passenger Van</option>
        <option value="Cargo Van">Cargo Van</option>
                </select> </li>
                <br />
                <li> <label> Pick up Location *</label>
        <select name="location" id="location" class="drop">
        <option selected="selected" value="Select Location">Select Location</option>
        <option value="U-Save JFK">U-Save JFK</option>
        <option value="U-Save LGA">U-Save LGA</option>
                </select> </li>
                <br />
        <li><label>Estimated Mileage</label>
        <select name="mileage" id="mileage" class="drop">
        <option selected="selected" value="Under 100">Under 100</option>
        <option value="100-500">100-500</option>
        <option value="500+">500+</option>
                </select>
        </li>
        <br />
        <li><label>Pick Up Date *</label>
          <input id="pick-up-date" name="pick-up-date" class="date" value="MM/DD/YY" /> <a href="javascript:showCal('Calendar1')"><img class="cal" align="absmiddle" src="cal/cal.gif" border="0" alt="Calendar"></a> 
        </li>
        <br />
        <li><label>Pick Up Time *</label>
          <select class="drop" name="pick up time" id="Pick Up Time">
    <option value="12:00 am">12:00 am</option> <option value="12:30 am">12:30 am</option>
    <option value="01:00 am">01:00 am</option> <option value="01:30 am">01:30 am</option>
    <option value="02:00 am">02:00 am</option> <option value="02:30 am">02:30 am</option>
    <option value="03:00 am">03:00 am</option> <option value="03:30 am">03:30 am</option>
    <option value="04:00 am">04:00 am</option> <option value="04:30 am">04:30 am</option>
    <option value="05:00 am">05:00 am</option> <option value="05:30 am">05:30 am</option>
    <option value="06:00 am">06:00 am</option> <option value="06:30 am">06:30 am</option>
    <option value="07:00 am">07:00 am</option> <option value="07:30 am">07:30 am</option>
    <option value="08:00 am">08:00 am</option> <option value="08:30 am">08:30 am</option>
    <option value="09:00 am">09:00 am</option> <option value="09:30 am">09:30 am</option>
    <option value="10:00 am">10:00 am</option> <option value="10:30 am">10:30 am</option>
    <option value="11:00 am">11:00 am</option> <option value="11:30 am">11:30 am</option>
    <option value="12:00 pm">12:00 pm</option> <option value="12:30 pm">12:30 pm</option>
    <option value="01:00 pm">01:00 pm</option> <option value="01:30 pm">01:30 pm</option>
    <option value="02:00 pm">02:00 pm</option> <option value="02:30 pm">02:30 pm</option>
    <option value="03:00 pm">03:00 pm</option> <option value="03:30 pm">03:30 pm</option>
    <option value="04:00 pm">04:00 pm</option> <option value="04:30 pm">04:30 pm</option>
    <option value="05:00 pm">05:00 pm</option> <option value="05:30 pm">05:30 pm</option>
    <option value="06:00 pm">06:00 pm</option> <option value="06:30 pm">06:30 pm</option>
    <option value="07:00 pm">07:00 pm</option> <option value="07:30 pm">07:30 pm</option>
    <option value="08:00 pm">08:00 pm</option> <option value="08:30 pm">08:30 pm</option>
    <option value="09:00 pm">09:00 pm</option> <option value="09:30 pm">09:30 pm</option>
    <option value="10:00 pm">10:00 pm</option> <option value="10:30 pm">10:30 pm</option>
    <option value="11:00 pm">11:00 pm</option> <option value="11:30 pm">11:30 pm</option>
        </select>
        </li>
        <br />
        <li><label>Drop Off Date *</label>
          <input id="drop-off-date" name="Drop Off Date" class="date" value="MM/DD/YY" /> <a href="javascript:showCal('Calendar2')"><img class="cal" align="absmiddle" src="cal/cal.gif" border="0" alt="Calendar" /></a> 
        </li>
        <br />
        <li><label>Drop Off Time *</label>
          <select class="drop" name="Drop Off Time" id="Drop Off Time">
    <option value="12:00 am">12:00 am</option> <option value="12:30 am">12:30 am</option>
    <option value="01:00 am">01:00 am</option> <option value="01:30 am">01:30 am</option>
    <option value="02:00 am">02:00 am</option> <option value="02:30 am">02:30 am</option>
    <option value="03:00 am">03:00 am</option> <option value="03:30 am">03:30 am</option>
    <option value="04:00 am">04:00 am</option> <option value="04:30 am">04:30 am</option>
    <option value="05:00 am">05:00 am</option> <option value="05:30 am">05:30 am</option>
    <option value="06:00 am">06:00 am</option> <option value="06:30 am">06:30 am</option>
    <option value="07:00 am">07:00 am</option> <option value="07:30 am">07:30 am</option>
    <option value="08:00 am">08:00 am</option> <option value="08:30 am">08:30 am</option>
    <option value="09:00 am">09:00 am</option> <option value="09:30 am">09:30 am</option>
    <option value="10:00 am">10:00 am</option> <option value="10:30 am">10:30 am</option>
    <option value="11:00 am">11:00 am</option> <option value="11:30 am">11:30 am</option>
    <option value="12:00 pm">12:00 pm</option> <option value="12:30 pm">12:30 pm</option>
    <option value="01:00 pm">01:00 pm</option> <option value="01:30 pm">01:30 pm</option>
    <option value="02:00 pm">02:00 pm</option> <option value="02:30 pm">02:30 pm</option>
    <option value="03:00 pm">03:00 pm</option> <option value="03:30 pm">03:30 pm</option>
    <option value="04:00 pm">04:00 pm</option> <option value="04:30 pm">04:30 pm</option>
    <option value="05:00 pm">05:00 pm</option> <option value="05:30 pm">05:30 pm</option>
    <option value="06:00 pm">06:00 pm</option> <option value="06:30 pm">06:30 pm</option>
    <option value="07:00 pm">07:00 pm</option> <option value="07:30 pm">07:30 pm</option>
    <option value="08:00 pm">08:00 pm</option> <option value="08:30 pm">08:30 pm</option>
    <option value="09:00 pm">09:00 pm</option> <option value="09:30 pm">09:30 pm</option>
    <option value="10:00 pm">10:00 pm</option> <option value="10:30 pm">10:30 pm</option>
    <option value="11:00 pm">11:00 pm</option> <option value="11:30 pm">11:30 pm</option>
        </select>
        </li>
        <br />

        <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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:36:22+00:00Added an answer on June 16, 2026 at 3:36 am

    You have placed a { at the wrong location, which results in the non-required field being ignored all together.

    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; }
        }
      } // <- Good
      $email_content .= $value.': '.$_POST[$value]."\n";
    //  } <- Wrong
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I validate my form with jquery validate and everything goes fine. What won't work
Sometimes, the form won't submit because jQuery has some invalid elements that will not
Why won't this print success when I submit the form? I'm pretty sure it
Is there ASP button that won't submit post form data. Whenever I click an
Form is not giving value on controller for sql.date i am using spring and
I'm trying to create the search form with keyword highlighting, but obviously I won't
No matter what I do this form won't behave via AJAX at all. There's
How can I make sure the form won't submit if one of the validations
Excel returns a reference of the form =Sheet1!R14C1R22C71junk (junk won't normally be there, but
Please help. This form used to submit, but it won't anymore. I can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.