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!
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>
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>
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">
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".
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>
//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>
Related
I have a tiny issue where sending variables to another page yields undefined variables.
Page 1:
<form name= "updateProfiel" method="POST" action="index.php?page=updateProfiel">
<input required type="text" name="voornaam" value="<?php echo $result['voornaam']; ?>"/>
<input required type="text" name="achternaam" value="<?php echo $result['achternaam']; ?>"/>
<input required type="text" name="adres" value="<?php echo $result['adres']; ?>"/>
<input required type="text" name="postcode" value="<?php echo $result['postcode']; ?>"/>
<input required type="text" name="woonplaats" value="<?php echo $result['woonplaats']; ?>"/>
<input required type="email" name="email" value="<?php echo $result['email']; ?>"/>
<input required type="password" name="password" placeholder="password"/>
<input type="hidden" name="submit" value="true" />
<input type="submit" id="submit" value=" Update " />
Annuleren
</form>
Page 2:
(page name is updateProfiel.php)
$voornaam = htmlspecialchars($_POST["voornaam"]);
$achternaam = htmlspecialchars($_POST["achternaam"]);
$adres = htmlspecialchars($_POST["adres"]);
$postcode = htmlspecialchars($_POST["postcode"]);
$woonplaats = htmlspecialchars($_POST["woonplaats"]);
$email = htmlspecialchars($_POST["email"]);
$password = htmlspecialchars($_POST["password"]);
$password = password_hash($password, PASSWORD_BCRYPT);`
I used phpinfo(); to see if the variables got sent from page 1 to page 2, and they are there:
The phpinfo()
But if I try to set them as variables and use them they're undefined!..
Does anyone know what's happening here?
This is very embarassing.
The undefined variables are actually not undefined. The source-page just says so.
The issue was somewhere else :')... Thanks for everyone's help!
Ps: The issue was the fact that a piece of SQL-query for the database was missing two brackets.. Yay.
How to pass a form value to next page in other form?
I have this code in the :
<form action="confirm.php" method="post">
First name: <input type="text" name="firstname"><br>
Last name: <input type="text" name="lastname"><br>
Email: <input type="text" name="email">
</form>
Now I want that in confirm.php to put some hidden input fields with this values, I tried this code:
<form action="nextpage.php" method="post">
//some other input fields...
<input type="hidden" name="firstname" value="<?php $_POST['firstname']?>">
<input type="hidden" name="lastname" value="<?php $_POST['lastname']?>">
<input type="hidden" name="email" value="<?php $_POST['email']?>">
</form>
And so on in other 2 pages, and in the last page I want to email all this fields, I tried PHP _SESSION, but no luck with that, so I think that this can be more easier for me!
And something else I forgot to tell, on the second page (nextpage.php) action form variable I refer to a file that use this code:
<?php
header('Location: dear-'.$_POST['firstname'].'.php');
?>
<html>
<form>
<input type="hidden" name="firstname" value="<?php echo $_POST['firstname']?>">
<input type="hidden" name="lastname" value="<?php echo $_POST['lastname']?>">
<input type="hidden" name="email" value="<?php echo $_POST['email']?>">
</form>
</html>
In this case how to pass this values (firstname, lastname and email) on the next page ? I use that because I want to generate a page like this www.site.com/dear-name.php
Try this in confirm.php
<form action="nextpage.php" method="post">
//some other input fields...
<input type="hidden" name="firstname" value="<?php echo $_POST['firstname']?>">
<input type="hidden" name="lastname" value="<?php echo $_POST['lastname']?>">
<input type="hidden" name="email" value="<?php echo $_POST['email']?>">
</form>
You forgot to echo your variable.
<input type="hidden" name="firstname" value="<?php echo $_POST['firstname']; ?>">
Update:
You have two choices :
Store your data to session and retrieve to another page.
Pass your data using query string.
header('Location: dear-'.$_POST['firstname'].'.php?firstname='.$_POST['firstname'].'&lastname='.$_POST['lastname'].'&email='.$_POST['email']);
use echo:
<input type="hidden" name="firstname" value="<?php echo $_POST['firstname']; ?>">
<input type="hidden" name="lastname" value="<?php echo $_POST['lastname']; ?>">
<input type="hidden" name="email" value="<?php echo $_POST['email']; ?>">
and if this still not working, isset() your post variables:
if(isset($_POST['firstname'],$_POST['lastname'],$_POST['email'])) {
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
echo '<input type="hidden" name="firstname" value="$firstname">';
echo '<input type="hidden" name="lastname" value="$lastname">';
echo '<input type="hidden" name="email" value="$email">';
}
In your input text field, value is empty because of echo is missing. You need to add echo to print the value in your form. So that it can be sent into another page.
The second option is that you can use session_start() in top of each page.
and store the value of the variable in your session.
$_SESSION['name'] = "value_of_session"// in your case that is POST data
and this can be used in next page you need not to include hidden fields.
the most important thing is that You must write
<?php session_start() ?> // in each(you've three) page.
This is what my code, problem with all <input> tag, can any one tell me is this the correct way to integrate HTML and PHP
<div style="width:115px; padding-top:10px;float:left;" align="left">Email Address:</div>
<div style="width:300px;float:left;" align="left">
<input type="text" name="email" id="email" value="<?php echo strip_tags($_POST["email"]); ?>" class="vpb_textAreaBoxInputs"></div><br clear="all"><br clear="all">
you need to make sure that $_POST["email"] is set before use for that you can use isset() like
<?php if(isset($_POST["email"])) { echo strip_tags($_POST["email"]); }else{echo 'default' ;} ?>
use ternary operator to display default value for each input instead
<input type="text" name="email" id="email" value="<?php echo isset($_POST['email'])?strip_tags($_POST['email']):''; ?>" class="vpb_textAreaBoxInputs"></div><br clear="all"><br clear="all">
same for firstname
<input type="text" name="firstname" id="firstname" value="<?php echo isset($_POST['firstname'])?strip_tags($_POST['firstname']):''; ?>" >
if(isset($_POST['submit'])){
$domain=$_POST['domain'];
$fname=$_POST['fname'];
$sname=$_POST['sname'];
$tel=$_POST['tel'];
if($domain==""){
$error="<h4>Enter Domain </h4>";
}elseif($fname == ""){
$error="<h4>Enter Firstname </h4>";
}elseif($sname == "")
{
$error="<h4 >Enter Surname</h4>";
}elseif($tel=="")
{
$error="<h4 >Enter telephono no</h4>";
}
else {
$sql11=mysql_query("INSERT INTO domain VALUES('','$domain','$fname','$sname','$tel','$mobile','$email','$company','$address','$city','$country','$pcode','$tele',
'$fax','$qus','$ans')");
echo $sql;
$db->query($sql);
}
}
<div><?php echo $error; ?></div>
<form action="" method="post" name="classic_form" id="classic_form">
<div><h4>Personal details:</h4></div><div style="margin-left: 109px;">
<div>Domain</div>
<input type="text" name="domain" id="domain" value="" />
<div>First name: </div>
<input type="text" name="fname" id="fname" value="" />
<div>Surname:</div>
<input type="text" name="sname" id="sname" value="" />
<div>Telephone:</div>
<input type="text" name="tel" id="tel" value="" />
<div>Mobile:</div>
</form>
In my registration page, i used php validation. After the user submit the form if it shows validation errors it also resets all the fields. How can i resolve this problem? Without reset the fields i have to show the php validation errors. I also used in each input value. But it shows
"Notice: Undefined index: domain in D:\xampp\htdocs\deena\domainreg.php on line 82" . Please help me to resolve this problem
<input type="text" name="domain" id="domain" value="<?php echo isset($domain) ? $domain : ''; ?>" />
You have to pass all your values to php, and send back to html to feed your fields.
Its not 'resetting your fields' .. Your form is being submitted, hence the page is being reset and fields are therefore loading empty. Place the $_POST[] values in the field values upon page load:
<input type="text" name="domain" id="domain" value="<?php echo $domain ?>" />
<div>First name: </div>
<input type="text" name="fname" id="fname" value="<?php echo $fname?>" />
<div>Surname:</div>
<input type="text" name="sname" id="sname" value="<?php echo $sname?>" />
<div>Telephone:</div>
<input type="text" name="tel" id="tel" value="<?php echo $tel?>" />
Simple. Just add the variables to the input values:
<input type="text" name="domain" id="domain" value="<?php echo $domain; ?>" />
You should also protect the outputted value, against cross site scripting:
<input type="text" name="domain" id="domain" value="<?php echo htmlspecialchars($domain); ?>" />
In the value field:
<input type="text" name="domain" id="domain"
value="<?php if(isset($_POST['domain'])){echo $_POST['domain'];} ?>">
Didn't test it. But i think it should work.
In input tag add the php value as like value="" So that it will echo if the variable is posted or it will show the empty one
how to retain the values of data entry in a placeholder during postbacks
<input type="text" name="name" value="<?PHP $name;?>" placeholder="Enter Name"/>
when php found any error and post it back
The data entry are all gone, user have to re enter all the information again.
What does value="<?PHP $name;?>" do? Is this supposed to print the variable? You would need to do this instead:
<?= $name; ?>
or
<?php echo $name;?>
<?php if empty($name){
$name='Enter Name';
} else {}?>
<input type="text" name="name" <?php echo $name;?> placeholder="Enter Name"/>
Try this:
<input type="text" name="name" value="<?PHP echo empty($_POST['name'])?'Enter Name':$_POST['name'];?>" />
In your PHP use your $_POST / $_GET variables to restore your user data:
<input type="text" name="name" value="<?= $_POST['name'] ?>" placeholder="Enter Name"/>
Where $_POST['name'] contains the data sent via a POST request from the form and 'name' is the name of your input.
Try this;
<input type="text" name="name" value="<PHP if (isset($name)){ echo $name; }?>"placeholder="Enter Name"/>
The isset will handle any undefined variable errors, if $name has not been piror to the submission