Hi frnds ....

I am trying to create a contact form in PHP , MySql .... In my form i have two 3 input fields n a Submit Button .....


1. Name
2. email
3. SecurityCode ( here user have to enter the captcha code )


m collecting all information frm user and if the captch code entered by the user is correct then the values will be entered into my database n emailed to some adress ....

Everything is working perfectly ....... But my problem is ...

I want to check these things before submitting the form ..

1. Name field is empty
2. User has entered a valid email
3. User has entered the correct Captcha code as shown in image

# If anything wrong i want to display the information n don't want submit or refresh the page....

# If everything is correct , then submit the form and do the actions ....


# I have searched in Google .... for some Ajax Validation ... But nothing is working perfectly n are too mess ....

# Can anyone tell me a simple solution or just an Idea for how to handle this ... please ...

Recommended Answers

All 6 Replies

You can handle these checks on the client-site by Javascript.
Or you make a AJAX call to your server (which is actually a post to your server), your server is checking the input and returns the result. When the result is OK, your form can post the data. While writing I thought: this will become a very weird solution: don't build it.

Why won't you post it and check the input on the server?

Member Avatar for diafol

There are loads of client-side validators out there. jQuery has a good few. Another simple one is YAV. Anyway, js hijacks the submit action and on validation either returns error messages or proceeds with the submit.

You MUST have server-side validation as js can be circumvented and forms can be spoofed.

Anyone have any ideas how to solve this issues using jQuery ... Please .....

I think that you can make it simpler by using the validation through Java Script.
You can assign a function to the submit button. Don't set the button type as a "submit" button. For example:
HTML:

<form name="Form1">
<input type="text" name="F1">
<input type="button" onclick="Validate();" value="Submit">
</form>

Java Script:

<script language="JavaScript">
if(!Form1.F1.value)
{
     return();
}
else
{
     Form1.submit();
}
</script>
commented: in high security mode internet explorer ignores javescript +0

Hi

you can solve the problem using javascript and ajax

<form name="Form1">
<input type="text" name="name">
<input type="text" name="email">
<input type="text" name="code">
<input type="button" onclick="Validate();" value="Submit">
</form>

function check(){
if(document.forms.form1.name.value.length<=0){
alert('Please enter a name');
return false;
}else if(document.forms.form1.email.value.length<=0){
alert('Please enter your email ID');
return false;

}else if(document.forms.form1.code.value.length<=0){
alert('Please enter the code');
return false;
}

}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.