Grow your CSS skills. Land your dream job.

Contact Form Required Field?

  • # September 1, 2009 at 2:08 pm

    I’m using the Nice & Simple Contact form and it works perfectly but I need some help with something else.

    How do I make an entry field required to be filled out before submission? You know, where the user gets an error message saying, "Please fill out your name & email."

    The PHP is exactly what Chris gave us other than edits to the To and From emails. If anyone could help, I’d greatly appreciate it!! I’m only familiar with editing PHP and not creating it.

    Rob
    # September 1, 2009 at 4:29 pm

    I would do – personally and if statement.

    Code:
    if($requiredfield) {

    //it is true – form submitted

    } else {

    //it is false form re-displayed with a message at the top like “fill it in properly” :)

    }

    If you know PHP a little, that will make sense, if not then you might need to give us some code lol

    # September 1, 2009 at 4:48 pm

    Thanks Rob!

    Well, I guess I don’t know as much as I thought I did because I’m a little confused.

    Here’s my PHP

    Code:
    < ?php

    $EmailFrom = "TESTING";
    $EmailTo = "sarah@ontheedgedesign.com";
    $Subject = "Mine Shaft Contact Form";
    $Name = Trim(stripslashes($_POST['Name']));
    $Email = Trim(stripslashes($_POST['Email']));
    $Message = Trim(stripslashes($_POST['Message']));

    // validation
    $validationOK=true;
    if (!$validationOK) {
    print "“;
    exit;
    }

    // prepare email body text
    $Body = “”;
    $Body .= “Name: “;
    $Body .= $Name;
    $Body .= “n”;
    $Body .= “Email: “;
    $Body .= $Email;
    $Body .= “n”;
    $Body .= “Message: “;
    $Body .= $Message;
    $Body .= “n”;

    // send email
    $success = mail($EmailTo, $Subject, $Body, “From: < $EmailFrom>“);

    // redirect to success page
    if ($success){
    print ““;
    }
    else{
    print ““;
    }

    ?>

    And here is the form in my HTML

    Code:

    We would love to hear your thoughts or comments.
    Please feel free to send a message below.








    # September 2, 2009 at 5:12 am

    I have a javascript file at the top of my contact page that colour codes the bits that need filled in before posting.

    if you would like to see this let me know:

    some prefer some other ways to do it, I did not want anything intrusive for the person filling in the form……

    # September 2, 2009 at 12:08 pm

    Yeah I’d love to see it. I don’t really care how it’s done as long as it works.

    # September 2, 2009 at 3:33 pm
    "slacey" wrote:
    Yeah I’d love to see it. I don’t really care how it’s done as long as it works.

    ok this is the javascript in the head tag:

    Code:

    here is my form:

    Code:
    Contact Form








    Validation, to help prevent spam:


         
       

    now it will work as is, but your form may not look like this, however you can change it, it is quite easy to understand…..

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".