help with basic PHP assignment

Discussion in 'PHP' started by TrillionBuks, Mar 10, 2008.

  1. #1
    I am applying for an internship and they gave me an assignment to complete. They know I have a background in C and have absolutely no experience with PHP. They want me to demonstrate the ability to find the answer to a problem not necessarily demonstrate my knowledge of coding. The following are the parameters of the assignment:

    Create a form that gathers all the information and sends an email with all info upon submitting it.

    Form Structure:

    first_name, last_name, email and phone.

    All fields should be required.

    Validate the email.

    Validate the phone structure.

    This is a tremendous opportunity for me to learn and gain valuable experience. Any help is truly appreciated. Thanks.
     
    TrillionBuks, Mar 10, 2008 IP
  2. CodyRo

    CodyRo Peon

    Messages:
    365
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <form action="blah.php" method="post">
    First Name: <input type="text" name="first_name" /><br />
    Last Name: <input type="text" name="last_name" /><br />
    E-Mail: <input type="text" name="email" /><br />
    Phone: <input type="text" name="phone" />
    </form>
    
    PHP:
    
    <?php
    
    if (isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['email']) && isset($_POST['phone']) && !empty($_POST['first_name']) &7 !empty($_POST['last_name']) && !empty($_POST['email']) && !empty($_POST['phone'))
    {
    
    $errors = array();
    
    if (!ereg("^[^@ ]+@[^@ ]+\.[^@ ]+$", $_POST['email'])
    {
        $errors[] = "Invalid E-Mail Address!";
    }
    
    if (!ereg("((\(\d{3}\)?)|(\d{3}))([\s-./]?)(\d{3})([\s-./]?)(\d{4})", $_POST['phone'])
    {
        $errors[] = "Invalid Phone Number!";
    }
    
    if (!empty($errors))
    {
        foreach ($errors as $error)
    {
        echo $error . "<br />";
    }
    } else {
        echo "First Name: " . $_POST['first_name'] . "<br />";
        echo "Last Name: " . $_POST['last_name'] . "<br />";
        echo "E-Mail : " . $_POST['email'] . "<br />";
        echo "Phone: " . $_POST['phone'] . "<br />";
    }
    }
    ?>
    
    PHP:
    Kind of sloppy.. and I didn't test the REGEX I just nabbed them from RegexLib.
     
    CodyRo, Mar 10, 2008 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Now that CodyRo did most of the work for you, don't forget to split the prize money half half.

    Peace,
     
    Barti1987, Mar 10, 2008 IP