2

I have a form field:

<input type="text" value="" name="Email" id="Email">

and my form action confirmation url is this:

http://.../index.php?Email=<?php echo $_POST['Email']; ?>

However after submitting, the Email parameter is not coming through. Is this something that can be done in PHP, or does it only read the field on initial page load?

Thanks

6
  • 1
    Which HTTP method is used in your form? I suppose it is POST, while your email value will be passed via GET Commented Aug 6, 2013 at 13:14
  • Do you use action="get" or action="post"? Commented Aug 6, 2013 at 13:14
  • Use form method "GET" instead of POST, and in action param just type "http://.../index.php" Commented Aug 6, 2013 at 13:14
  • First things first: why do you want it? Commented Aug 6, 2013 at 13:16
  • Thanks for the replies. Unfortunately I'm limited to using the POST action as it is passing through a 3rd party program with the confirmation link being passed in as a form field later. GET in the URL works only if the parameter already exists in the url, so it looks like I'm SOL unless I use JS or something to populate the confirmation link. Commented Aug 6, 2013 at 13:25

4 Answers 4

5

Your issue is that you are mixing $_GET and $_POST.

See your code here, http://.../index.php?Email=<?php echo $_POST['Email']; ?>, when you post to that one, there will no longer be a $_POST['Email'], but a $_GET['Email']. So the first post will likely work (if you are using <form method="post" action="...">), but the second submit will fail, as $_POST['Email'] no longer exists.

So I recommend that you don't use parameters in the action. Instead, put them in a hidden field or switch to only $_GET parameters.

Option 1, use hidden field

Change the form on your second page to:

<form action="http://.../index.php" method="POST">
    <input type="hidden" name="Email" id="Email" value="<?php echo $_POST['Email'];?>" />
    ...
</form>

Option 2, use only $_GET

Change the form on your first page to <form ... method="GET">

And then change the form on the second page to use $_GET['Email'] and the method to GET.

<form action="http://.../index.php??Email=<?php echo $_GET['Email'];?>" method="GET">
    ...
</form>

Option 3, Use $_REQUEST instead of $_POST

Simply use http://.../index.php?Email=<?php echo $_REQUEST['Email']; ?> as your action url, as $_REQUEST is a merge of $_GET and $_POST. Be aware that this is a merge of $_GET, $_POST and $_COOKIE.

Sign up to request clarification or add additional context in comments.

1 Comment

Your option 2 is not working for me ... Are you sure it works currently also
4

It depends on the your FORM method

Your form should be

<form method='post' action='http://.../index.php'>
<input type="text" value="" name="Email" id="Email">
<input type='submit' value='Post data'>
</form>

and to access email in index.php you can write code as below

<?php
 $emailValue = $_POST["Email"];
//Use variable for further processing

?>

if your form is as below (please check that method is get

<form method='get' action='http://.../index.php'>
<input type="text" value="" name="Email" id="Email">
<input type='submit' value='Post data'>
</form>

and to access email in index.php you can write code as below

<?php
 $emailValue = $_GET["Email"];
//Use variable for further processing

?>

Comments

4

You don't need to define the structure of the GET request; that's what the form does.

For instance:

<form action="workerbee.php" method="GET">
    <input type="text" name="honey_type" value="sweet" />
</form>

...when submitted, would automatically append the field - honey_type - to the URL for you. It would end up like this:

http://example.com/workerbee.php?honey_type=sweet

You can then access the value via $_GET['honey_type'] in workerbee.php. To pre-fill the form with the existing submitted value - assuming that workerbee.php holds the form - just add a conditional value parameter:

<?php

$honey_type = !empty($_GET['honey_type']) ? $_GET['honey_type'] : null;

?>

<input type="text" name="honey_type" value="'<?php echo htmlspecialchars($honey_type); ?>'" />

Comments

0

If you're trying to use data from your current form, your form tag should read as follows:

<form action="http://.../index.php" method="GET">

If you're trying to pass data your server already has (such as from a previous form), then you should use a hidden field instead:

<input name="email" type="hidden" value="<?php echo $_POST['Email']; ?>">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.