# Help to Validate Form DEADLINE

**URL:** <https://forum.kirupa.com/t/help-to-validate-form-deadline/261576>\
**Category:** programming\
**Created:** [May 28, 2008, 11:23pm UTC](https://forum.kirupa.com/t/help-to-validate-form-deadline/261576 "2008-05-28T23:23:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kwodlum](https://avatars.discourse-cdn.com/v4/letter/k/b782af/32.png) [@kwodlum](https://forum.kirupa.com/u/kwodlum)\
**Post date:** [May 28, 2008, 11:23pm UTC](https://forum.kirupa.com/t/help-to-validate-form-deadline/261576/1 "2008-05-28T23:23:33Z")

</div>

I’ve done a search and I can’t seem to find what I’m looking for, I have a deadline so I need help **ASAP**. Just help with **one** field to **validate** , than I can figure out the rest.

Here’s the form: [http://www.esl4work.com/form.html](http://www.esl4work.com/form.html)

_Thanks in advance._

Here’s the PHP code:

[COLOR=DarkRed]\<?php

if(isset($\_POST[‘submit’])) {

$firstName = $\_POST[‘txtFirstName’];  
$lastName = $\_POST[‘txtLastName’];  
$company = $\_POST[‘txtCompany’];  
$email = $\_POST[‘txtEmail’];  
$phone = $\_POST[‘txtPhone’];  
$hearAbout = $\_POST[‘selHearAbout’];  
$quest1 = $\_POST[‘txtQuest1’];  
$quest2 = $\_POST[‘txtQuest2’];  
$quest3 = $\_POST[‘selQuest3’];  
$quest4 = $\_POST[‘txtOther’];  
$quest5 = $\_POST[‘txtQuest5’];

foreach($\_POST[‘check’] as $value) {  
$check\_msg .= "Checked: $value  
";  
}

$body = "From: $firstName $lastName  
E-Mail: $email

1. What are the current positions of the participants?  
$quest1

2. Approximately how many participants would be interested in talking an ESL course?  
$quest2

3. What English Proficiency would you place the majority of the participants?  
$quest3

4. Which areas of English do the participants need improvement in?  
$check\_msg  
Other:  
$quest4

5. What are your organizations top three goals for running an on-site ESL program?  
$quest5  
";

header (‘location: [http://www.esl4work.com/thank-you.html](http://www.esl4work.com/thank-you.html)’);  
mail($to, $subject, $body);

}

else {

header (‘location: [http://www.esl4work.com/error.html](http://www.esl4work.com/error.html)’);

}

?\>[/COLOR]

---

<div class="post-metadata">

**Author:** ![djheru](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/djheru/32/3190_2.png) [@djheru](https://forum.kirupa.com/u/djheru)\
**Post date:** [May 29, 2008, 2:55am UTC](https://forum.kirupa.com/t/help-to-validate-form-deadline/261576/2 "2008-05-29T02:55:43Z")

</div>

Which field do you need to validate? Lets assume that it’s the first name… First, I would put the form itself into a function so that you can reuse it if the validation fails. Just pass the form function an array that represents the $\_POST array. Then echo the appropriate array key in the form field value attribute like so:

```php

echo "<input type=\"text\" name=\"txtFirstName\" value=\"$postValues['txtFirstName']\" />";

```

Then, after submission:

```php

if(isset($_POST['submit'])) 
{
     //you could use regular expression matching for phone, email
     if($_POST['txtFirstName'] != '')
     {
          $firstName = $_POST['txtFirstName'];
          $lastName = $_POST['txtLastName'];
          //etc...
     }
     else
     {
         echo "<h2>ERROR MESSAGE</h2>";
         $form = formFunction($_POST);
     }
}
else
{
     echo "<h2>FILL OUT FORM</h2>";
     $form = formFunction();
}

```

But I still like to use Javascript validation because it validates before the form is submitted to the server, so it is a little bit quicker
