SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Web Design Addict
    Join Date
    Mar 2004
    Posts
    2,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A few questions concerning PHP form processing

    I've got to design a script that will process two forms for a car dealership. The form will consist of text fields, radio buttons, and drop down lists. I am familiar with processing information from text fields, but I am not familiar with processing info from radio buttons or drop down lists.

    What I would like to learn is to display in an e-mail the selection a person makes with either the radio button or the drop down list.

    Here are the two forms I'm working with:

    www.deronsizemore.com/quote.htm

    www.deronsizemore.com/testdrive.htm

    (Don't mind the styling on these, I didn't do it and I'm not messing with it...my job is to develop the php script to process the form)

    I'm not really looking for hand out or anything, just a boost in the right direction. If someone has a good reference site or something that would be awesome!

    Thanks,
    Deron
    Deron Sizemore
    ----------
    My Sites: LogoGala | Golf Ledger (coming soon)
    Twitter: Deron Sizemore

  2. #2
    SitePoint Guru MikeBigg's Avatar
    Join Date
    Jun 2004
    Location
    Reading, UK
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Deron,

    in the code for one of those pages (ote the change of select to select_method):

    PHP Code:
    <select name="select_method" size="1">     
      <
    option value="purchase-cash">Purchase Cash</option>
      <
    option value="purchase-finance">Purchase Finance</option>
      <
    option value="lease">Lease</option>
      <
    option value="undecided">Undecided</option>
    </
    select
    "select_method" will be passed to the script with one of the 4 values.

    Does this help?

    Mike

  3. #3
    SitePoint Addict RRWH's Avatar
    Join Date
    May 2005
    Posts
    269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the 2nd half of your question can be found by looking at the example at http://www.w3schools.com/html/html_forms.asp

    from that page,

    <form>
    <input type="radio" name="sex" value="male"> Male
    <br>
    <input type="radio" name="sex" value="female"> Female
    </form>

    if you echo $sex you will get back the value of the selected box (male or female in this example)

    Od course, It is assumed that you use the appropriate $_GET['sex'] or $_POST['sex']

  4. #4
    Web Design Addict
    Join Date
    Mar 2004
    Posts
    2,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MikeBigg
    Deron,

    in the code for one of those pages (ote the change of select to select_method):

    PHP Code:
    <select name="select_method" size="1">
    <option value="purchase-cash">Purchase - Cash</option>
    <option value="purchase-finance">Purchase - Finance</option>
    <option value="lease">Lease</option>
    <option value="undecided">Undecided</option>
    </select>

    "select_method" will be passed to the script with one of the 4 values.

    Does this help?

    Mike
    I will change that as you said. It doesn't really help me though I don't think. I'm more or less needing help with the php part of the code. The form html was given to me and I was asked to create something to process the form and have the info sent to an e-mail address. I'm familiar with processing just regular text fields, but not familiar with how to process drop down lists or the radio buttons with PHP. (Example with the test drive form: If their method of payment is "Lease" and the person selects "lease" from the drop down menu, what do I need to get the e-mail to show they selected "lease"? Same goes for the AM or PM with the radio buttons)


    Quote Originally Posted by RRWH
    the 2nd half of your question can be found by looking at the example at http://www.w3schools.com/html/html_forms.asp

    from that page,

    <form>
    <input type="radio" name="sex" value="male"> Male
    <br>
    <input type="radio" name="sex" value="female"> Female
    </form>

    if you echo $sex you will get back the value of the selected box (male or female in this example)

    Od course, It is assumed that you use the appropriate $_GET['sex'] or $_POST['sex']
    Thanks RRWH. I understand what you're doing about half way. You lost me with "...appropriate $_GET['sex'] or $_POST['sex']" What is the difference in these two and where do I need to put them at?

    I think its going to need to go somewhere here in the test drive form?:
    Code:
    <form name="form1" id="form1" method="post" action="">
    Deron Sizemore
    ----------
    My Sites: LogoGala | Golf Ledger (coming soon)
    Twitter: Deron Sizemore

  5. #5
    SitePoint Addict RRWH's Avatar
    Join Date
    May 2005
    Posts
    269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <form name="form1" id="form1" method="post" action="">
    the method="post" is important to you on the processing end - this is where you would use the $_POST['name']; to read back the info that was put into the form.

    To expand further for you on the dropdown list - you would use $_POST['select_method']; to get the actual value that was selected -

    the $_POST['name'] is the name of the variable in the web form, regardless if it is a text field, radio button, checkbox, select list. the backend script really doesn't care about how the variable is populated - and that seems to be where you are getting stuck.

  6. #6
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As RRWH points out, your form handler script could look like this...
    PHP Code:
    // Grab the values you just submitted via the form and assign to variables 
    $year $_GET["year"];
    $make $_GET["make"];
    $colorExt $_GET["colorExt"];
    $paymentType $_GET["paymentType"];
    etc.... 

  7. #7
    Web Design Addict
    Join Date
    Mar 2004
    Posts
    2,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by RRWH
    Code:
    <form name="form1" id="form1" method="post" action="">
    the method="post" is important to you on the processing end - this is where you would use the $_POST['name']; to read back the info that was put into the form.

    To expand further for you on the dropdown list - you would use $_POST['select_method']; to get the actual value that was selected -

    the $_POST['name'] is the name of the variable in the web form, regardless if it is a text field, radio button, checkbox, select list. the backend script really doesn't care about how the variable is populated - and that seems to be where you are getting stuck.

    Okay...I think i'm starting to catch on with it. Only question I have no is where you've said to use $_POST['name'], Philm has wrote $_GET['name']?

    What is the difference or is there any? Which should I use? I ask the same question to you as well Phlim if you get here before RRWH does...?

    I'm going to attempt later today to put this script together, so I will probably return with more questions on "why is this not working?!" lol. (because I never pointed out before, but I know very very little php)

    Thanks for the help guys...its really appreciated!
    Deron Sizemore
    ----------
    My Sites: LogoGala | Golf Ledger (coming soon)
    Twitter: Deron Sizemore

  8. #8
    SitePoint Guru MikeBigg's Avatar
    Join Date
    Jun 2004
    Location
    Reading, UK
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $_POST contains variables that are sent to the server as a result of a post. Typically this would be a data from web form as in your current requirements.

    The $_GET array is populated as a result of a GET reuest to the server. Typically this would be the parameters sent as part of the URL, every thing after the ? in the URL is parsed into the array.

    Mike
    Last edited by MikeBigg; Jun 3, 2005 at 16:22.

  9. #9
    SitePoint Member
    Join Date
    Jun 2005
    Location
    South Coast of England
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As a rule of thumb, try to use GET to access data and POST to modify data. A GET request can be bookmarked as all the required info is in the URL.
    www.fonant.com - Quality web sites


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •