Using PHP as browser 'Back' button


#1

I am developing some code that allows a website visitor to create a profile and define their username and password. I am having PHP do a check on the username before creating the new record in the database. If it finds the username already exists then I want to display a message indicating that the username is already taken and to please select a new one. Here’s the rub, I want to be able to send them back to the form entry page like their browser’s back button would do without instructing them to use their back button. (To preserve the POST information they already entered).

Is this possible with PHP or should I just make the username/password entry page separate from the rest of the form?

Thanks,

Lisa


#2

What I typically do is first to allow Javascript to check the obvious (Phone number right format, fields populated, zip code not too long, etc…) then when I submit the form, I submit it back to itself (PHPSELF) In the code, I check for the fact that it’s submitted and if it’s submitted, then I do processing else I will just move on to the part that displays the form.

//initialize error check variable
$errorCheck = 1;

if ($submit=='submit') {

    $errorCheck = 0; //assume it will check. If not, then change it back to 1 in the check step.
    
    //enter code to verify info such as USERID or password, or whatever
    // If there is an error or problem , change error flag to 1 else leave it 0
     
}

If ($error==0) {

    // process data then either redirect to new page or post a success
    // message and allow a user to navigate where they wish

} else {

   // re-display form if already submitted, then you can repopulate the
   // fields using the value tag. If it has not been submitted then 
   // all the values will be blank (or you can set some defautl)

}

#3

I already had everything you described in place (Javascript checking of input fields and submitting it back to itself) and had used the value field of the input statements before in edit programs developed for editing a database record BUT it didn’t click with me to just let the form reload itself if it needed to be resubmitted with only one or two field changes. Since I already populated the previous posted information into php variables then when I detect an error with one of the fields (ie. a record already existing in the database) I can just let the page reload itself and use the php variable to re-populate the value fields of the input statements. This would only occur after the submission because the first time the program is run those php variables would be blank. This will be a much better approach than having to spit out the two entry processes.

Thanks so much! :D

Lisa


#4

Glad I could help.