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

  • SEARCH
  • Home
  • 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 6724097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:38:52+00:00 2026-05-26T09:38:52+00:00

I’m having an issue when the posting a selection value for server side validation.

  • 0

I’m having an issue when the posting a selection value for server side validation. When the user does not make a selection, therefore it is still selected on “Select…”. It still passes the empty() method, although the value is empty.

<?php

// Email Properties
$email_to = "user@domain.com";
$email_subject = "3DMark3t Contact:";
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$comments = $_POST['comments'];
$select = $_POST['select'];

function formError($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
}

// Make sure all fields are not empty
if(empty($first_name) || empty($last_name) || empty($email) ||
    empty(telephone) || empty($comments) || empty($select)) {
    // Return error
    formError('Please fill in all of the fields.');       
}

// Regex Tests
$error_message = "";

// Expressions
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($email_exp, $email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp, $first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp, $last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(!empty($error_message)) {
    formError($error_message);
}

$email_message = "3DMark3t Contact: \n";
$email_message .= "First Name: {$first_name} \n";
$email_message .= "Last Name: {$last_name} \n";
$email_message .= "Email: {$email} \n";
$email_message .= "Telephone: {$telephone} \n";
$email_message .= "Select One: {$select} \n";
$email_message .= "Comments: {$comments} \n";

// Create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  

header("Location /");

HTML:

<form name="htmlform" method="post" action="php/html_form_send.php">
    <table width="450px">
        <tr>
            <td valign="top">
                <label for="first_name">First Name *</label>
            </td>
            <td valign="top">
                <input  type="text" name="first_name" maxlength="30" size="30">
            </td>
        </tr>
        <tr>
            <td valign="top">
                <label for="last_name">Last Name *</label>
            </td>
            <td valign="top">
                <input  type="text" name="last_name" maxlength="30" size="30">
            </td>
        </tr>
        <tr>
            <td valign="top">
                <label for="email">Email Address *</label>
            </td>
            <td valign="top">
                <input  type="text" name="email" maxlength="30" size="30">
            </td>
        </tr>
        <tr>
            <td valign="top">
                <label for="telephone">Telephone Number</label>
            </td>
            <td valign="top">
                <input  type="text" name="telephone" maxlength="30" size="30">
            </td>
        </tr>
        <tr>
            <td valign="top">
                <label for="select">Select One *</label>
            </td>
            <td valign="top">
                <select name="select">
                    <option value="">Select...</option>
                    <option value="3DModels">3DModels</option>
                    <option value="Graphic Design">Graphic Design</option>
                    <option value="Web Design">Web Design</option>
                    <option value="Tutorials">Tutorials</option>
                    <option value="Report">Report</option>
                    <option value="Requests">Requests</option>
                </select>
            </td>
        </tr>
        <tr>
            <td valign="top">
                <label for="comments">Comments *</label>
            </td>
            <td valign="top">
                <textarea  name="comments" maxlength="1000" cols="32.5" rows="6"></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align:center">
             <input type="submit" value="Submit">
            </td>
        </tr>
    </table>
</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-05-26T09:38:52+00:00Added an answer on May 26, 2026 at 9:38 am

    You are testing if $_POST['formGender'] is set, but PHP will return TRUE for isset() on an empty string. No selection on your form means that $_POST['formGender'] == "", and that is considered to be "set" in the isset() check.

    Instead test if it is empty() which will both verify if the variable is defined like isset() and if it has a non-empty value.

    if(empty($_POST['formGender']))
    {
      $errorMessage .= "<li>You forgot to select your Gender!</li>";
    }
    

    Also test for empty() here instead of !isset()

     if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
     if(empty($_POST['select']) )
    

    Update

    I’m not really sure what you are trying to accomplish with this. But, 3DModels, Graphic Design, etc will not be part of the $_POST array. They are potential values of $_POST['select']. I don’t understand what your intent is here.

    if(empty($_POST['select']) )
    {
      $var3dmodels = $_POST['3DModels'];
      $vargraphic_design = $_POST['Graphic Design'];
      $varweb_design = $_POST['Web Design'];
      $vartutorials = $_POST['Tutorials'];
      $varreport = $_POST['Report'];
      $varrequests = $_POST['Requests'];
    }
    

    The source of your problem:

    I finally see where your error is. Instead of $error_message, you are using $errorMessage for $_POST['select']:

    if(empty($_POST['select']))
    {
      // Oops...
      $errorMessage .= 'The selection you made does not appear to be valid.<br />';
    
      // Should be
      $error_message .= 'The selection you made does not appear to be valid.<br />';
    }
    

    You should turn on error_reporting and display_errors in PHP.ini for development and testing only. An uninitialized variable used like $errorMessage .= ... would issue a notice, and you’d see the error on screen. Turn this off for production code.

    // Report all errors and notices
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but
Does anyone know how can I replace this 2 symbol below from the string
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I need a function that will clean a strings' special characters. I do NOT
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.