Matt
Matt

Reputation: 1063

pass value from $_GET to $_POST

So, I have a disabled email form field whose placeholder and value are retrieved from $_GET['email']:

<input name="email" type="text" placeholder="<?php if(isset($_GET['email'])) echo $_GET['email']; ?>" value="<?php if(isset($_GET['email'])) echo $_GET['email']; ?>" disabled>

When the user fills out the form, I was hoping that $_POST['email'] would have the email value, but it doesn't (it's empty). What am I missing/forgetting? Is there a clever way to pass this value along? Thanks!

Upvotes: 1

Views: 358

Answers (6)

programmerKev
programmerKev

Reputation: 399

As Cuchu stated, you could use readonly instead of disabled. Or you could duplicate the field and change the type to hidden.

<form method="post" action="register.php">
    <input type="text" value="<?php if(isset($_GET['email'])) echo $_GET['email']; ?>" disabled>
    <input name="email" type="hidden" value="<?php if(isset($_GET['email'])) echo $_GET['email']; ?>">
</form>

Upvotes: 3

Tosif
Tosif

Reputation: 36

  //try this
<form method="post">
<input type="text" name="email"><input type="submit" value="click" name="btnClick" id="btnClick">
<input type="text" name="email1" placeholder="inserted value" value="<?php echo (isset($_POST['email']))? $_POST['email'] : "" ?> ">      
</form>

Upvotes: 0

Aron
Aron

Reputation: 139

I think it is better to use the readonly attribute instead of disabling the input.

<input name="email" type="text" placeholder="<?php if(isset($_GET['email'])) echo $_GET['email']; ?>" value="<?php if(isset($_GET['email'])) echo $_GET['email']; ?>" readonly="readonly">

Upvotes: 1

pritesh
pritesh

Reputation: 2192

You should enclose in a form tag and set the method to post as

<form action="" method="post">
<input name="email" type="text" placeholder="<?php if(isset($_GET['email'])) echo $_GET['email']; ?>" value="<?php if(isset($_GET['email'])) echo $_GET['email']; ?>" disabled>
</form>

Upvotes: 0

Maxi Schvindt
Maxi Schvindt

Reputation: 1462

change attribute disabled to readonly because disabled not submit values..

<input name="email" type="text" placeholder="<?php if(isset($_GET['email'])) echo $_GET['email']; ?>" value="<?php if(isset($_GET['email'])) echo $_GET['email']; ?>" readonly>

Upvotes: 3

Ethan Brown
Ethan Brown

Reputation: 703

Placeholder is a prompt, not a value. If you want the textfield to have a value of the email, use the "value" attribute, not the "placeholder".

Upvotes: 0

Related Questions