Jump to content


Photo

$Php and multiple input type forms


  • Please log in to reply
5 replies to this topic

#1 dwees

dwees
  • Members
  • PipPipPip
  • Advanced Member
  • 47 posts
  • LocationUnited Kingdom

Posted 04 July 2006 - 09:25 PM

Hey there.

Suppose I have a form like this:

testing.html -
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<body>

<form name="input" action="test.php" method="GET">
Male: 
<input type="radio" name="Sex" value="Male" checked="checked">
<br>
<input type="text" name="firstname">
<br>
Female: 
<input type="radio" name="Sex" value="Female">
<br>
<input type="text" name="lastname">
<br>
<input type ="submit" value ="Submit">
</form> 

<p>
If you click the "Submit" button, you will send your input to a new page called html_form_action.asp.
</p>

</body>
</html>

I would like to be able to read the information from both input types.  It seems to me that using the POST and GET methods isn't working.  At least my very simple test function doesn't do anything (see below).

test.php -
<?php
$test = $_GET['input'];
echo $test;
?>
[CODE][/code]


#2 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 04 July 2006 - 09:36 PM

<form name="input" action="test.php" method="GET">
Male: 
<input type="radio" name="Sex" value="Male" checked="checked">
<br>
<input type="text" name="firstname">
<br>
Female: 
<input type="radio" name="Sex" value="Female">
<br>
<input type="text" name="lastname">
<br>
<input type ="submit" value ="Submit">
</form>

try using $_GET['sex'], $_GET['firstname'], and $_GET['lastname']
Why doesn't anyone ever say hi, hey, or whad up world?

#3 dwees

dwees
  • Members
  • PipPipPip
  • Advanced Member
  • 47 posts
  • LocationUnited Kingdom

Posted 04 July 2006 - 10:02 PM

Works super.  I'm going to assume it works with POST as well.

Dave

#4 Eugene

Eugene
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 04 July 2006 - 10:11 PM

use $_REQUEST, it's more safer than get.

#5 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 04 July 2006 - 10:59 PM

How is $_REQUEST safer than $_GET? 

I use $_POST though with my forms.

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 July 2006 - 04:04 AM

there are only 2 methods of passing variables with a form: GET and POST.

GET passes the variables through the url.
POST passes the variables through the body of the HTTP request

to access them, you would use $_GET['varname'] and $_POST['varname'] respectively. 

$_POST is safer than $_GET, because the information is not being sent through the url string.

$_REQUEST is an array that holds both $_POST and $_GET variables.  So I can access my form information with

$_REQUEST['blah'] same as $_POST['blah'] if my form method was POST, or same with the GET method, as well.

$_REQUEST is not any safer than the safety levels of $_POST or $_GET. You still need to sanitize it just the same, though as mentioned, $_POST is more safer than $_GET. You should still sanitize your $_POST vars though.


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users