I need help creating a PHP form for a class project

Discussion in 'PHP' started by smcm, Mar 24, 2010.

  1. #1
    The Form

    *
    It will produce a form to ask the user for his or her first name, last name, and birthdate.
    *
    It will also instruct the user to mark his or her favorite programming languages from a list of four (your choice).
    *
    The birthdate should be handled by three separate fields: month (MM), day (DD), and year (YYYY).
    *
    Use <select> elements for each field.
    *
    Create an array for the month names and the last day of the month.
    *
    Use a loop to generate the items in each of the three <select> dropdown menus.
    *
    For the years, use a loop to generate years up to 18 years ago.

    Perform the following data validations

    * If a user enters a name (first or last) that includes characters that could cause problems for the script or a database, strip slashes to the input.
    * If any input is missing, allow the user to make changes before the form data is processed.
    * Prevent the user from passing data/values in through the URL/address bar.
    * Extra Credit Only: Verify the day of the month selected does not exceed the number of days in the month given.

    Processing

    * Produce a standard "Thank you" page with "Thank You [user's first name]" in the <title>.
    * In the <body>, thank the user for his/her input.
    * Display all data entered for confirmation. Display the date in the format MM/DD/YYYY.
    * Present the user's choice(s) of favorite programming languages in an unordered list. Display the message, "You did not choose any programming languages" if the programming languages array is empty. Do not allow the script to error-out.

    I am having trouble with this assignment.
     
    smcm, Mar 24, 2010 IP
  2. shockworks

    shockworks Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have you tried it? Have you already written some code od the assignment?
     
    shockworks, Mar 24, 2010 IP
  3. superdav42

    superdav42 Active Member

    Messages:
    125
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    I am having trouble helping you because I don't know where to start.
     
    superdav42, Mar 24, 2010 IP
  4. pig2cat

    pig2cat Active Member

    Messages:
    299
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #4
    -start off by making a normal html form
    http://www.tizag.com/phpT/examples/formex.php

    -for the 1-18 thing just use
    -parse the data via php with $_POST
    -take a look at the addslashes(); function

    The rest is up to you
     
    pig2cat, Mar 24, 2010 IP
  5. smcm

    smcm Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The two pieces that were giving me trouble are the year which I appreciate the help with and the array created with the months. I already created the HTML form.
     
    smcm, Mar 24, 2010 IP
  6. pig2cat

    pig2cat Active Member

    Messages:
    299
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Hi,
    for the months, use a 2d array

    
    $months = array( array("January", 31),
    //...
                   array("Novembre", 30),
                   array("Decembre", 31) 
                 ); 
    
    PHP:
    You can then call this by:
    
    echo $months[0][1]; // January
    echo $months[0][2]; // 31 days
    //etc
    echo $months[11][1]; // December
    echo $months[11][2]; // 31 days
    
    PHP:
     
    pig2cat, Mar 24, 2010 IP