Jump to content

Force a link?


Obi1-Cannabis

Recommended Posts

Is it possible to force a link on php.my idea is: i have a form that takes me to another page but i want it to stay in the same if the fields are not complete, if they are wrong or if i already have that same data on my DB.how am i suposed to do such a thing?

Link to comment
Share on other sites

Is it possible to force a link on php.my idea is: i have a form that takes me to another page but i want it to stay in the same if the fields are not complete, if they are wrong or if i already have that same data on my DB.how am i suposed to do such a thing?
You can check the content with the handler, for example:
if ($message == "" | $user == "") {   echo "sorry, not all required fields are entered. Please try again.<meta http-equiv=\"refresh\" content=\"3; url=form.html\">";}else if (info is double or wrong, I don't know how to check that yet) {   echo "sorry, the information you entered is invalid or already in use. Please try again.<meta http-equiv=\"refresh\" content=\"3; url=form.html\">";else {   echo "Thank you. You will now be taken to another page.<meta http-equiv=\"refresh\" content=\"3; url=form.html\">";

This is the syntax as I recall it from the top of my head, it may be wrong. Please verify/test and adapt to your needs before using it. You may also wish to save the information already filled to a session, and have it echoed in the fields when the user is taken back (input type=text name=field value=<?$_SESSION['value']?>, again from the top of my head)If you want to check immediately upon leaving each field, that would require Javascript.Meta tags are usually only stored in the head of a document. Only use these tags in documents that you do not wish to validate as (x)html. The meta-refresh is the only way I know to redirect someone to a page and give a proper notification at the same time. But again, I may be wrong.Good luck.

Link to comment
Share on other sites

The easiest way to do this is to have your form submit to the same page (submit to itself). So a form on login.php will submit to login.php. On that page, before you send any HTML, you can check if the form was submitted, and if it was, validate the information. If everything is ok, then you set some session variables or whatever you need to do, and do a meta refresh to redirect the user somewhere else. If there are problems, then you just show the form again (it's easy since it's on the same page), but fill in the values they already entered and show whatever error messages you need.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...