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 8937467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:25:16+00:00 2026-06-15T10:25:16+00:00

Can anyon help with this please? I’m new to php and trying to develop

  • 0

Can anyon help with this please?

I’m new to php and trying to develop validation rules for a simple contact form.

How can I stop the selectfields reseting when other parts of the form fail validation?

Code is below:

<?php


    $error      = '';
    $title      = '';
    $firstname  = '';
    $surname    = '';
    $email      = '';
    $phone      = '';
    $comments   = '';
    $how        = '';
    $verify     = '';

    if(isset($_POST['contactus'])) {

    $title      = $_POST['title'];
    $firstname  = $_POST['firstname'];
    $surname    = $_POST['surname'];
    $email      = $_POST['email'];
    $phone      = $_POST['phone'];
    $comments   = $_POST['comments'];
    $how        = $_POST['how'];
    $verify     = $_POST['verify'];

    ini_set("sendmail_from", $email_from, "enquiries@blah.com");


    // Errors

    if(trim($title) == '') {
        $error = '<div class="error_message">Please enter your Title.</div>';
    }
    else if(trim($firstname) == '') {
        $error = '<div class="error_message">Please enter your First name.</div>';
    }
    else if(trim($surname) == '') {
        $error = '<div class="error_message">Please enter your Surname.</div>';
    }
    else if(!validEmail($email)){
    $error = '<div class="error_message">Please enter a valid email address.</div>';
    $email = '';
    }
    if($error == '') {

        if(get_magic_quotes_gpc()) {
            $comments = stripslashes($comments);
        }


    $address = "enquiries@blah.com";

    $e_subject = 'Care at Home Enquiry from ' . $title . $surname . '.';

    $e_body = "You have been contacted by $name with regards to an Advantage Nurses general enquiry, contact details and message are as follows.\r\n\n";
    $e_content = "Title: " . $title  .
                 "\r\n\nFirst name:" . $firstname  .
                 "\r\n\nSurname: " . $surname  .  
                 "\r\n\nEmail: " . $email  . 
                 "\r\n\nPhone: " . $phone  . 
                 "\r\n\nEnquiry: " . $comments .
                 "\r\n\nHow Did You Hear About Us: " . $how;

    //$e_reply = "\r\n\nYou can contact $name via email, $email or via phone $phone";

    $msg = $body . $e_content . $e_reply;

    if(mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n"))
    {
        // Email has sent successfully, echo a success page.

         echo "<div id='succsess_page'>";
         echo "<h1>Enquiry Submitted.</h1>";
         echo "<p>Thank you <strong>$title $surname</strong>, your enquiry has been submitted to us.<br /><br /> A member of our Team will contact you within 48 hours.</p>";
         echo "</div>";
     } else echo "Error. Mail not sent";

    }
}

    if(!isset($_POST['contactus']) || $error != '') // Do not edit.
    {

?>

  • 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-15T10:25:16+00:00Added an answer on June 15, 2026 at 10:25 am

    It’s much more elegant if you define your option values in an array:

    $titles = array('Mr', 'Miss', 'Mrs');
    

    Within the HTML:

    <select name="title" id="title">
        <?php foreach($titles as $title): ?>
    
        <option value="<?php echo $title; ?>" if(isset($_POST['title']) $_POST['title'] == $title) echo 'selected="selected"';><?php echo $title; ?></option>
    
        <?php endforeach; ?>
    </select>
    

    Warning 1: Your code is vulnerable to XSS, you should not print raw user input back to the page, pass it through htmlspecialchars().

    Warning 2: It’s also vulnerable to mail header injection attacks. You should validate the $email that you insert into the headers, or not insert any user input at all into the headers.

    Because of these, I have removed your site link from the question. I recommend taking your page offline until the vulnerabilities are fixed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can anyone help me with this please. I am trying to build a priority
Can anyone help me spot the problem on this PLEASE? I'm eternally grateful for
Can anyone please help me with this...I'm not very good with regular expressions and
Can anyone help with this... vector<unsigned int> *vVec = new vector<unsigned int>; vVec .reserve(frankReservedSpace);
Can anyone help in this php page navigation script switch on counting normal serial
Can anyone help me with this problem please? I have 2 databases on the
Can anyone help on this please? That error message is not displaying based on
Can anyone help me with this please. I want to do something like this.
Can anyone help me with this please I want to be able to rotate
Can anyone help - this is driving me mad. I am calling a mysql

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.