Email Contact Form

Discussion in 'PHP' started by FishSword, Jan 19, 2009.

  1. #1
    Hiya,

    Using PHP, how do you check multiple fields to ensure the correct information (if any) has been entered, and if not, change the label text and textbox border colour to red, and list the errors as bullet points.

    The following fields need to be checked for the following:
    • Name - Not Blank, Contains A-Z only.
    • Email - Not Blank, Correct Format.
    • Phone- Not Blank, Contains 0-9 only.
    • Type - Must be selected.
    • Location - Must be selected
    <form name="form1" method="post" action=""><label>Name:</label>
      <input name="name" type="text" id="name">
      <br>
      <br>
      <label>Email:</label>
      <input name="email" type="text" id="email">
      <br>
      <br>
      <label>Phone:</label>
      <input name="phone" type="text" id="phone">
      <br>
      <br>
      <label>Mobile:</label>
      <input name="mobile" type="text" id="mobile">
      <br>
      <br>
      <label>Type:</label>
      <select name="type" id="type">
        <option>Type 1</option>
        <option>Type 2</option>
        <option>Type 3</option>
      </select>
      <br>
      <br>
      <label>Location:</label>
      <select name="location" id="location">
        <option>Location 1</option>
        <option>Location 2</option>
        <option>Location 3</option>
      </select>
      <br>
      <br>
      <input type="submit" name="Submit" value="Submit">
    </form>
    
    Code (markup):
     
    FishSword, Jan 19, 2009 IP
  2. mendin

    mendin Active Member

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #2
    it's a long code
     
    mendin, Jan 19, 2009 IP
  3. joxtechnology

    joxtechnology Peon

    Messages:
    146
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    just use if else. when the user submit.
    <?
    if(isset($_POST['Submit'])){
    $name = $_POST['name'];

    if(strlen($name)<=0){
    echo "Enter name";
    }
    }
    ?>
    btw you can also use javascript to do this form validation
     
    joxtechnology, Jan 20, 2009 IP