Jump to content

Archived

This topic is now archived and is closed to further replies.

dwees

$Php and multiple input type forms

Recommended Posts

Hey there.

Suppose I have a form like this:

testing.html -
[CODE]
<!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>
[/CODE]

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 -
[CODE]
<?php
$test = $_GET['input'];
echo $test;
?>
[CODE][/code][/code]

Share this post


Link to post
Share on other sites
[code]<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> [/code]

try using $_GET['sex'], $_GET['firstname'], and $_GET['lastname']

Share this post


Link to post
Share on other sites
Works super.  I'm going to assume it works with POST as well.

Dave

Share this post


Link to post
Share on other sites
How is $_REQUEST safer than $_GET? 

I use $_POST though with my forms.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.