CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Javascript using PHP/SQL (http://www.codingforums.com/showthread.php?t=284047)

ryan1234 12-12-2012 08:01 PM

Javascript using PHP/SQL
 
I've got a web page which has a form on it. When the Submit is clicked, it saves all the information to a database (SQL) using PHP.

I've got PHP validation for the email and currently when the email is incorrect it redirects to a different page with the same design but with the text 'Incorrect Email'.

However I want it to redirect to the same current page, but use javascript/jQuery to show 'Incorrect Email'.

Any ideas of how I would do this, if it is possible.

Thanks.

felgall 12-12-2012 09:34 PM

To redirect to the same page just needs a small change to the PHP. Either the validation of the form is done in the same page as the form with the form action pointing to the current page and a header location call redirects to the next page if the form is valid OR if the validation is done on a different page then it just needs a header location call to redirect back to the form if the validation falis - before outputting anything from the new page.

Once you get the page working correctly without JavaScript you can then make it easier for your visitors who have Javascript enabled by adding field validations to the form with JavaScript (eg. http://javascriptexample.net/domform15.php ) while still knowing that the form will function correctly without JavaScript.

jQuery is just a huge JavaScript library that provides lots of common JavaScript functionality. There is no great benefit in using it for form validation unless you are using a significant part of it for other purposes.

AndrewGSW 12-12-2012 09:39 PM

Well you could add a querystring to your url:

Code:

mailformpage.html?fail=1
and use JS/jQuery to extract this value and modify the content of the page or, more usefully, just change the class of an error-message paragraph from, say "error-no" to "error-yes" so that it displays on the page.

This is not a fully-robust solution as it is trivial to edit the address bar - but, of course, you won't be relying on this 'fail' value!!

Preferably you should add PHP to your main page which displays different content according to whether they're log-in (or email verification) was successful. It is possible to dynamically insert a JS/jQuery script to run when the page loads, but if you are doing this you might as well just use PHP to modify the page.

Personally, I use the same page to display and verify the form, only re-directing on a successful log-in, but I get the impression you don't want to re-write too much.


All times are GMT +1. The time now is 09:39 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.