TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-24-2007, 09:05 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default Form validation

Hey, I'm curious, how can I check an input value and match it in the database with javascript?

Like for instance, we have a simple login form.
Input username, input password.

When they write the username nothing happens, but when they DEselect the input field of username, it instantly checks if the username exists in the database.

Code:
<form action="" method="POST">
Username: <input type="text" name="username" onblur="check('username')"><span id="nameError"></span><br />
Password: <input type="password" name="pass" onblur="check('pass')"><span id="passError"></span></form>
And it just use innerHTML to change the value of the spans.
But how do I check the values in the database with javascript? :S
Tanax is offline  
Reply With Quote
Old 09-24-2007, 10:45 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

It looks like you're wanting to use an XMLHttpRequest in JavaScript to talk to a PHP script on your server. The PHP script will then check the database to see if the username exists and report back accordingly. Then the JavaScript will parse the response and change the innerHTML of the spans as appropriate. Or, in a more concise form, you're wanting to do an AJAX call.

I don't know your level of knowledge in this area but just let me say that if you're looking for a way for JavaScript (and only JS) to talk to the database, then you can't. But that doesn't mean the process is difficult.

Since it makes the process a whole lot easier, can I ask if you have any experience with JavaScript frameworks (jQuery, Prototype, Mootools...) and if so which one(s)? For the sake of simplicity, it would probably be easier to guide you through your problem using one of the frameworks (that's their purpose, to make things easier!).
Salathe is offline  
Reply With Quote
Old 09-25-2007, 07:56 AM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

I have no experience in jQuery, Prototype nor Mootools, however that's why I'm kinda asking, cause I want to learn :)
Tanax is offline  
Reply With Quote
Old 09-28-2007, 08:45 AM   #4 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Bump >.< ........
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:35 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design