Reputation: 1
I have a form in a file named signup.php like this,
<form action="includes/signup.inc.php" method="post">
<input type="text" name="uid" placeholder="Username..."><br><br>
<input type="text" name="mail" placeholder="Email..."><br><br>
<input type="password" name="pwd" placeholder="Password..."><br><br>
<input type="password" name="repeatPwd" placeholder="Repeat Password..."><br><br>
<input type="submit" name="btnSignup" value="Signup">
</form>
Then I have this if statement in the signup.inc.php file.
if (!preg_match("/^[a-zA-z0-9]*$/", $username)) {
header("Location: ../signup.php?error=invaliduid&mail=".$email);
exit();
}
That is if the user enter invalid username, then the user will be route back to the signup page, and I get an error message in the address bar, now I want to get the email from the address bar which the user entered, I make an if statement back in the signup.php file like this,
if ($_GET['error'] == "invaliduid") {
echo "Invalid username.";
$email = $_GET['mail'];
}
Now I want to fill the original form
<input type="text" name="mail" placeholder="Email...">
And put the email from $_GET['mail']
and put it in the value portion of the form, but I am stuck on how to do this.
The program should work like this, if the user entered proper mail and an invalid username then the user route back to the signup page with the message invalid username, and email field should be populated with the email which he already entered.
Upvotes: 0
Views: 630
Reputation: 1
This here is working as intended:
<input type="text" name="mail" placeholder="Email..." value="<?php echo(isset($email))?$email:'';?>">
Upvotes: 0
Reputation: 475
From what I understand, what you're looking for is simply this:
<input type="text" name="mail" placeholder="Email..." value="<?= htmlspecialchars($email) ?>">
(which is a less ugly way to write the following:)
<input type="text" name="mail" placeholder="Email..." value="<?php echo htmlspecialchars($email); ?>">
Upvotes: 3