Reputation: 1063
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
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
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
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
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
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
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