Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-12-2012, 08:01 PM   PM User | #1
ryan1234
New to the CF scene

 
Join Date: Oct 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
ryan1234 is an unknown quantity at this point
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.

Last edited by ryan1234; 12-12-2012 at 08:08 PM..
ryan1234 is offline   Reply With Quote
Old 12-12-2012, 09:34 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 12-12-2012, 09:39 PM   PM User | #3
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:32 PM.


Advertisement
Log in to turn off these ads.