Jump to content

Recommended Posts

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

}

 

Link to comment
https://forums.phpfreaks.com/topic/164384-form-onblur/#findComment-867132
Share on other sites

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  ???

Link to comment
https://forums.phpfreaks.com/topic/164384-form-onblur/#findComment-867147
Share on other sites

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..

Link to comment
https://forums.phpfreaks.com/topic/164384-form-onblur/#findComment-867156
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.