Hi, two quick questions that you might be able to help me with:
1. I have a register form that checks to see if the user has input the password the same twice. (Password...Re-type password). I have put a link if the details are not correct, to go back to the html form. How do I have a link to go back to the original form that the user has filled out with there details on? It goes back to a blank page.
2. Is related to above. I want my users to updated there profiles. How do I input the users original data in an html form so that they can update only the information they want?
Thanks. Hope you can help.
Two quick questions about links
Moderator: General Moderators
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Check if the passwords match. If they don't, then create a variable like.. $theyDontMatch. Then, have a check somewhere where it says:
Code: Select all
if(isset($theyDontMatch)){ echo "The entered passwords do not match."; }- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
A general page setup for what you're trying to acheive. I generally use a $showForm control variable.
For this to work, the form must be submitted to the same page it is shown on.
Code: Select all
$showForm = true;
if ($formWasSubmitted) {
$showForm = false;
// process the form
if ($thereIsErrorInFormDetails) {
$showForm = true; //show the form again with values filled in
//show errors here or later on in the form
}
}
if ($showForm === true) {
//show form here
}- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Generally speaking, I do the same thing.
Code: Select all
<?php
// Set defaults
$show_form = true;
$error = '';
$username = '';
// Check if the form was posted
if (!empty($_POST['username']))
{
// assign the post value for checking
$username = $_POST['username'];
// Check if it meets our criteria
if (!ctype_alnum($username))
{
// Set the error var
$error = 'The username field must be alphanumeric only.';
}
else
{
$show_form = false;
}
}
if ($show_form): if (!empty($error)):
?>
<div style="background: #ccc; color: #c00; border: 1px solid #c00;"><?php echo $error; ?></div>
<?php endif; ?>
<form method="post" action="<?php echo basename(__FILE__); ?>">
<p>Please enter an alphanumeric user name:
<input type="text" name="username" value="<?php echo $username; ?>" /></p>
<p><input type="submit" name="submit" value="Submit Me" /></p>
</form>
<?php endif; ?>