Hi there!
I have a login form like this:
<form method="post" action="login.php">
Username:
<p><input type="text" name="id" /></p>
Password:
<p><input type="password" name="pass" /></p>
<input type="submit" value="Log In" name="login" />
<input type="reset" value="Reset" />
</form>
and the validation is in login.php aswell, a single file validation).
If the email or password doesn't match the error message appears below the form. If the input is valid, it redirects to homepage.php (header ("location: homepage.php");)
What I want to do is: if the password is wrong, or doesn't match with the username, it displays the form again with the original username input.
Is it by using cookie?
If anyone has any suggestion, please let me know.
Sankyu :)
Try saving the old value inside the session variable ($_SESSION) and displaying it on the value property of the element.
Related
-Checking if the username is entered.
-Basically I am trying to say if the user did not enter a username, echo "Please insert a username".
<form action="form_3.php" method="get">
Username: <input type="text" name="username" value="" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
$username=$_GET["username"];
if (!isset($username)) {echo "Please insert a USERNAME";}
else{echo "Hello: ".$username;}
?>
You can do this simply with HTML.
Username: <input type="text" name="username" value="" required>
You should add your php code on a different page to avoid any load errors.
You shouldn't use
isset();
but
empty();
The "empty" function is internally doing a "isset" on the value and checking that the variable is not an empty string.
http://php.net/manual/en/function.empty.php
The html5 validator can also be used to avoid your serveur to actually have to return the form saying "Please enter your username", but it can be easily disabled by a visitor.
<input type="text" name="username" value="" required>
When I load the page the first time it shows an error because the username is already empty. How can fix that error?
I have a form that when they submit it, it stores the info in the database. I need to be able to get the form data to come up on redirect page.
It does not need to fetch the database as I would love to do this PHP style. So lets say they enter there name and city. When they click submit it redirects them to a thank-you page with the results from the form on that page.
In a form, you have each element have a name, lets say name="username", in the php, yould get the value of this as either a get, or a post response, depending on the method of the form.
HTML Form
<form action="process.php" method="get">
<input name="username" type="text"></input>
<input type="submit" value="Submit"></input>
</form>
or
<form action="process.php" method="post">
<input name="username" type="text"></input>
<input type="submit" value="Submit"></input>
</form>
process.php
$someusername = $_GET['username'];
$someusername = $_POST['username'];
Form page:
<form action="thanks.php" method="post"><input type="text" name="myname" placeholder="Name" /><input type="text" name="mycity" placeholder="City" /><input type="submit" value="submit"></form>
PHP Page
print "Thanks, ".$_POST['myname']." who lives in ".$_POST['mycity']."!";
Have two login forms on one page and two database tables: admin(user, pass) and customer(fname, laname, email, user, pass).
One for customer, and one for admin.
Want to process both forms inside login.php
How to determine which form was Submit button clicked on and access user and pass fields from both forms inside login.php when trying to store $_POST username and password inside respective variables?
Something like this?(goes into login.php):
if(//submit button in customer form was clicked){
$user=$_POST['customer_login']['user'];
$pass=$_POST['customer_login']['pass'];
}else{
//admin submit button was clicked
$user=$_POST['admin_login']['user'];
$pass=$_POST['admin_login']['pass'];
}
Form(HTML):
<form name="customer_login" method="post" action="login.php">
<h3>Customer:</h3>
Username: <input type="text" id="user" name="user"><br>
Password: <input type="password" id="pass" name="pass"><br>
<input type="submit" name="Submit" value="Sign in">
</form>
<form name="admin_login" method="post" action="login.php">
<h3>Admin:</h3>
Username: <input type="text" id="user" name="user"><br>
Password: <input type="password" id="pass" name="pass"><br>
<input type="submit" name="Submit" value="Sign in">
</form>
Give the submit buttons unique names and/or identifiers and check which is set. From memory, that should work, but otherwise you could use a hidden field per form to indicate a predefined value you know, knowing this value you can process the appropriate data.
Change the name attrbute in one of your forms and then on php side check which $_POST values you get. For example:
<input type="submit" name="Submit2" value="Sign in">
if($_POST['Submit2']){
//form 2 has been sent
}
Create a post name with customer login only for the customer form.
if(isset($_POST['customer_login'])){
$user=$_POST['customer_login']['user'];
$pass=$_POST['customer_login']['pass'];
}else{
//admin submit button was clicked
$user=$_POST['admin_login']['user'];
$pass=$_POST['admin_login']['pass'];
}
Ok i am trying to find if this is possible, i have a single page that has two login forms. But uses the same username and password. Is it possible whereas once i log into one form my username is pulled from the from that already has my username and the password is pulled from the database?
<form action="home.php" method="post" id="LoginForm" style="color:#FFF">
<input type="hidden" name="SessionID" value="new"></input>
Username:
<input type="text" name="AccountNo" value="" class="input" size="28"></input>
<BR /><BR />
Password:
<input type="password" name="Password" value="" class="input" size="30"></input>
<BR />
<input type="image" src="images/input-img.gif" value="Log On" class="input-img"></input>
<BR /><br />
Register now! Forgotten your password?
</form>
If your question is whether it is possible, then answer is yes it is possible.
After you submit the form, you can use JavaScript to read the username from first form and populate it in the second form. To get password, you can AJAX.
I have a php signup form. I have a text field named username ie, <input type="text" name="username"> to enter username. I have a button next to it with value and name as check. I want to popup a small window when user click the check button. I just want the entered text (username) to get displayed in the popup window.
The key need is to transfer the data from this window to popup window.
How can I make this possible??
I'm not pretty sure what are your really wanted. I guess experimentX has a point. Anyway try this code. But first your calling page must be a php.
PHP:
<p>User Name is: <?php echo $_GET['userName']; ?> </p>
HTML
Forwarding value via URL
<form>
<p>
<input type="text" name="userName" />
<input type="button" value="check" onClick="window.open('popWindow.php?' + 'userName=' + this.form.userName.value, '_new')" />
</p>
</form>
Forwarding value via submit:
<form action="popWindow.php" target="_new" method="GET">
<p>
<input type="text" name="userName" />
<input type="submit" value="check" />
</p>
</form>
I hope this can help. If not please be more specific and provide more of your code.