beanieboy Posted July 1, 2009 Share Posted July 1, 2009 Hi, How do i prevent a user from entering a value in a form which isnt in a mysql db. Is this possible with a onblur event in the form? thanks Quote Link to comment https://forums.phpfreaks.com/topic/164384-form-onblur/ Share on other sites More sharing options...
Adam Posted July 1, 2009 Share Posted July 1, 2009 Well technically you should never consider using JS to prevent anyone from doing anything, JS can be switched off and so is useless for security. What exactly do you mean by a value that isn't in a database? Do you have any examples? Quote Link to comment https://forums.phpfreaks.com/topic/164384-form-onblur/#findComment-867116 Share on other sites More sharing options...
beanieboy Posted July 1, 2009 Author Share Posted July 1, 2009 Hi, Okay this is what i want to do. I already validate form entries using javascript, this creates a inline div on the form if there is a problem. Only issue i have is that i dont know how to validate a entry against a mysql database in the javascript and display the inline div. Heres how the other validation works. Form <form action="search-tickets.php" class="form" onsubmit="return validate(this)" method="post" name="SearchTicket" id="SearchTicket" > <input id="username" type="text" name="username" /> <input type="submit" name="Submit" value="SEARCH" /> Validate function in JS function validate(form) { var user= form.username.value; if(user == "") { inlineMsg('username','Enter valid name',3); return false; } function inlineMsg(target,string,autohide) { // displays the error } Quote Link to comment https://forums.phpfreaks.com/topic/164384-form-onblur/#findComment-867132 Share on other sites More sharing options...
Adam Posted July 1, 2009 Share Posted July 1, 2009 You wouldn't use JS for this, you'd just validate with PHP. If you really, really wanted to, I guess you could use AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/164384-form-onblur/#findComment-867134 Share on other sites More sharing options...
beanieboy Posted July 1, 2009 Author Share Posted July 1, 2009 ok i wonder if i can do it another way... in the php can i do a onblur which checks the entry against the mysql db, if the record is found then set a hidden input value in the form to true. Then when i do a the complete validation via javascript, i check whether this hidden is set and if not do my normal inline message. is this possible? if so..how ??? Quote Link to comment https://forums.phpfreaks.com/topic/164384-form-onblur/#findComment-867147 Share on other sites More sharing options...
Bendude14 Posted July 1, 2009 Share Posted July 1, 2009 it sounds like you are trying to over complicate this... you should first implement a php script to validate against the database and once this works add your javascript in as a more user friendly option. OnBlur is an event that is triggered client side ie, javascript you could use Ajax to call a php script but i am thinking thats a bit complicated for now. Steps to take are.. Check if $_POST['Submit'] is set... if so then process your variables eg $_POST['username'] then query the database and act accordingly wether or not the user exists. When you have the PHP script working you can stop the form ever been submitted using Javascript but the form will still submit to the PHP file if they have JavaScript disabled. Have a go and post back with any problems Remember google's your best friend.. Quote Link to comment https://forums.phpfreaks.com/topic/164384-form-onblur/#findComment-867156 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.