Jump to content

$Php and multiple input type forms


dwees

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]
Link to comment
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']
Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.