SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    not passing on my values?

    below is a simple switch structure that should bring up the correct next question after the user selcts from the drop down of choices. However it keep only returnig the "default" of the switch. It's I am doing something wrong in regards to sending info from the html page to the php page. Something wrong with my syntax?
    Code:
    //pass the recieved values using hidden types
    
    	print("<input type=hidden name=\"FirstName\" value=\"$FirstName\">\n");
    	print("<input type=hidden name=\"LastName\" value=\"$LastName\">\n");
    	print("<input type=hidden name=\"Comments\" value=\"$Comments\">\n");
    	print("<input type=hidden name=\"ContactHow\" value=\"$ContactHow\">\n");
    
    //_____make a switch for the form pulldown
    
    switch ($ContactHow) {
      case "Telephone":
    	print("<b>Please enter a daytime phone number where you can be reached:</b><br>\n");
    	print("<input type=text name=\"Telephone\" size=10><br>");
    	print("<input type=submit name=submit value=\"Continue\">\n");
    	break;
      case "Mail":
    	print("<b>Please enter your mailing address:</b><br>\n");
    	print("<textarea name=\"MailAddress\" rows=5 cols=40></textarea><br>\n");
    	print("<input type=submit name=submit value=\"Continue\">\n");
    	break;
      case "Email":
    	print("<b>Please enter your email address:</b><br>\n");
    	print("<input type=text name=\"Email\" size=40><br>\n");
    	print("<input type=submit name=submit value=\"continue\">\n");
    	break;
      case "Fax":
    	print("<b>Please enter your fax number</b><br>\n");
    	print("<input type=text name=\"Fax\" size=10><br>\n");
    	print("input type=submit name=submit value=\"continue\">\n");
    	break;
      	default:
    	print("<b>Please select how you want to be contacted</b><br>\n");
    	break;
      }

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Where in your script do you give $ContactHow its value?

  3. #3
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it comes from this html in whcih the user selects the type of contact method
    Code:
    <html><head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>handlecontact</title>
    
    </head><body>
    <form action="HandleContact.php" method="post">
    First Name <input name="FirstName" size="20" type="text"><br>
    Last Name <input name="LastName" size="20" type="text"><br>
    How would you prefer to be contacted?
    <select name="ContactHow"><option value="">Select One:</option><option value="Telephone">Telephone</option><option value="Mail">Mail</option><option value="Email">Email</option><option value="Fax">Fax</option></select>
    <br>
    Comments <textarea name="Comments" rows="5" cols="40"></textarea><br>
    <input name="Submit" value="Submit!" type="submit">
    </form>
    </body></html>

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    In your script, you'll have to use the $_POST array which contains the form values.
    Code PHP:
    // get the received values from the $_POST array
    $FirstName = $_POST['FirstName'];
    $LastName = $_POST['LastName'];
    $Comments = $_POST['Comments'];
    $ContactHow = $_POST['ContactHow'];
     
    //pass the recieved values using hidden types
     
    	print("<input type=hidden name=\"FirstName\" value=\"$FirstName\">\n");
    	print("<input type=hidden name=\"LastName\" value=\"$LastName\">\n");
    	print("<input type=hidden name=\"Comments\" value=\"$Comments\">\n");
    	print("<input type=hidden name=\"ContactHow\" value=\"$ContactHow\">\n");
     
    //_____make a switch for the form pulldown
     
    switch ($ContactHow) {
      case "Telephone":
    	print("<b>Please enter a daytime phone number where you can be reached:</b><br>\n");
    	print("<input type=text name=\"Telephone\" size=10><br>");
    	print("<input type=submit name=submit value=\"Continue\">\n");
    	break;
      case "Mail":
    	print("<b>Please enter your mailing address:</b><br>\n");
    	print("<textarea name=\"MailAddress\" rows=5 cols=40></textarea><br>\n");
    	print("<input type=submit name=submit value=\"Continue\">\n");
    	break;
      case "Email":
    	print("<b>Please enter your email address:</b><br>\n");
    	print("<input type=text name=\"Email\" size=40><br>\n");
    	print("<input type=submit name=submit value=\"continue\">\n");
    	break;
      case "Fax":
    	print("<b>Please enter your fax number</b><br>\n");
    	print("<input type=text name=\"Fax\" size=10><br>\n");
    	print("input type=submit name=submit value=\"continue\">\n");
    	break;
      	default:
    	print("<b>Please select how you want to be contacted</b><br>\n");
    	break;
      }

  5. #5
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks . That made it work.
    I thought this part was taking the info from the html form?
    Code:
    //pass the recieved values using hidden types
     
        print("<input type=hidden name=\"FirstName\" value=\"$FirstName\">\n");
        print("<input type=hidden name=\"LastName\" value=\"$LastName\">\n");
        print("<input type=hidden name=\"Comments\" value=\"$Comments\">\n");
        print("<input type=hidden name=\"ContactHow\" value=\"$ContactHow\">\n");

  6. #6
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    those are just variables, you need to access them first from the $_POST array, then assign them to variables, which is what the code supplied does.

    [edit] you'll probably want to secure those variables first to prevent malicious input before using them in your forms/database etc, consider mysql_real_escape_string and search on sitepoint for some detailed guides

  7. #7
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by stanp View Post
    thanks . That made it work.
    I thought this part was taking the info from the html form?
    Code:
    //pass the recieved values using hidden types
     
        print("<input type=hidden name=\"FirstName\" value=\"$FirstName\">\n");
        print("<input type=hidden name=\"LastName\" value=\"$LastName\">\n");
        print("<input type=hidden name=\"Comments\" value=\"$Comments\">\n");
        print("<input type=hidden name=\"ContactHow\" value=\"$ContactHow\">\n");
    No, this part creates hidden form fields, which before didn't contain anything, and now will contain the values passed by the form.
    I guess the first form is sent to a page that contains a second form, and the values from the first form are included in the second form as hidden fields.

  8. #8
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh I see. So I have made the hidden fields to hold the values, i just never sent the values over.
    so this $_Post is some built in function that goes to tha page passing the values and "collects" it.
    I am understanding this right?

  9. #9
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  10. #10
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    $_POST is an array, that contains the values sent by a form that has action="post".
    If you have a form with action="get", or if you send values in the query string of the url (pagename.php?param1=value1&param2=value2), then the sent values can be found in the $_GET array.
    Take a look at the link waffles posted.

  11. #11
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cool. I get ya.
    So you could in theory just keep using this on php and send values from one page to the next to the next to the next and so on and so on...
    reading the link now..
    thanks

  12. #12
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stanp View Post
    cool. I get ya.
    So you could in theory just keep using this on php and send values from one page to the next to the next to the next and so on and so on...
    reading the link now..
    thanks
    in theory yes, although the value of hidden fields are viewable in the source, so if you're doing stuff that requires some level of security its probably not advisable.

    its also probably more efficient to store data in this way in a session ($_SESSION), which is another super global, like $_POST, but allows you to store data throughout a users "session" (i.e. the time they spend on the website). This is also more secure, and you can access the data in the same way as you would with $_POST, which saves you having to draw out a form with hidden fields every time. but this is beyond the scope of your initial query


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
  •