Jump to content

how can I validate this simple contact us form?


co.ador

Recommended Posts

<div id="tresuno"> 
<p>Contac us we want to assist you better.....</p>
<div id="tresdos">
<form action="step2.php" method="post">
Name<br/><input name="username" type="text" id="username" />
<br/> 
Email<br/><input name="email" type="text" id="email"/>
<br/>
Message<br/><textarea  name="message"  cols="60" rows="8" id="message"></textarea>
<br/>
<input type="submit" value="Send your message" /><br/>
</form>
</div>
</div>

Link to comment
Share on other sites

As pbs said above, best to do this validation in javascript (using a library such as jQuery may help).

 

The only thing you'd really want to check server-side (in the php) in a simple contact form such as that, is whether the required fields are filled in.

 

ie. if you wanted to make sure they entered a name in:

if ($_POST['username'] == '') {
    echo 'Please make sure you enter a username before submitting the form.';
}
else {
   // process results
}

 

You could get more specific on which values they can enter in what field but that would require regex which is far more complex if you are new to validation.

Link to comment
Share on other sites

The above script will check weather username is equal to empty then, echo enter and input in the username input, let say.

 

Is there another way of checking a different posibility? Let say if the type of form being validated is retrieving information from a database instead of sending information Then I would say there is a possibility of checking weather a input is NULL meaning it doesn't match any of the record in the database. so the testing would be weather the index username is NULL instead of empty right?

Link to comment
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.