# Compulsory Fields

**URL:** <https://forum.kirupa.com/t/compulsory-fields/241880>\
**Category:** programming\
**Created:** [October 19, 2007, 2:54am UTC](https://forum.kirupa.com/t/compulsory-fields/241880 "2007-10-19T02:54:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![GGMcGee](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@GGMcGee](https://forum.kirupa.com/u/GGMcGee)\
**Post date:** [October 19, 2007, 2:54am UTC](https://forum.kirupa.com/t/compulsory-fields/241880/1 "2007-10-19T02:54:47Z")

</div>

Hey, I’ve created an email contact form on a web page for a client, using HTML and PHP.

Below is the code for the contact HTML page, and the mailer PHP page I’m using.

It works, but I need to make all the input fields compulsory. For instance if someone doesn’t put any details in any box, they receive some sort of error message and aren’t allowed to submit, or something similar.

Pages:

> [@"contact.html"](#):
>
> \<form method=“POST” action=“mailer.php”\>  
> \<table width=“450” border=“0” align=“center” cellpadding=“0” cellspacing=“5”\>  
> \<tr\>  
> \<td width=“39” align=“right” valign=“top”\>\<span class=“style1”\>Name\</span\>\</td\>  
> \<td width=“229” align=“left” valign=“top”\>\<input name=“name” type=“text” id=“name” size=“30” /\>\</td\>  
> \</tr\>  
> \<tr\>  
> \<td align=“right” valign=“top”\>\<span class=“style1”\>Phone\</span\>\</td\>  
> \<td align=“left” valign=“top”\>\<input name=“phone” type=“text” id=“phone” size=“30” /\>\</td\>  
> \</tr\>  
> \<tr\>  
> \<td align=“right” valign=“top”\>\<span class=“style1”\>Email\</span\>\</td\>  
> \<td align=“left” valign=“top”\>\<input name=“email” type=“text” id=“email” size=“30” /\>\</td\>  
> \</tr\>  
> \<tr\>  
> \<td align=“right” valign=“top”\>\<span class=“style1”\>Enquiry \</span\>\</td\>  
> \<td align=“left” valign=“top”\>\<span class=“style1”\>  
> \<textarea name=“enquiry” cols=“35” rows=“9” id=“enquiry”\>\</textarea\>  
> \</span\>\</td\>  
> \</tr\>  
> \<tr\>  
> \<td align=“right” valign=“top”\>\<span class=“style1”\>\</span\>\</td\>  
> \<td align=“left” valign=“top”\>\<span class=“style1”\>  
> \<input name=“submit” type=“submit” id=“submit” value=“Submit” /\>  
> \<input name=“reset” type=“reset” id=“reset” value=“Reset” /\>  
> \</span\>\</td\>  
> \</tr\>  
> \</table\>  
> \</form\>

> [@"mailer.php"](#):
>
> \<?php  
> if(isset($\_POST[‘submit’])) {
> 
> ```
> $to = "email@whatevertheiremailaddressis.com"; 
> $subject = "Website - Enquiry";
> $name = $_POST['name'];
> $phone = $_POST['phone'];
> $email = $_POST['email'];
> $enquiry = $_POST['enquiry'];
> 
> $body = "Name: $name
> 
> Phone: $phone
> 
> Email: $email
> 
> Enquiry: $enquiry
> 
> ";
> 
> echo "Your enquiry has been submitted!";
> mail($to, $subject, $body);
> 
> ```
> 
> } else {  
> echo “An error has occured. Please try again later.”;  
> }  
> ?\>

I have no idea what I have to do to make the fields compulsory, whether more coding on the existing pages is required, or if I have to create more pages.

Any help is appreciated! 🙂

\*\*EDIT: \*\*Also, I’ve just encountered another php related problem…  
Regarding another email contact form, with exactly the same format of coding as above, I’ve uploaded the html and php pages into two separate web spaces for testing. On one web space it works, emailing the query correctly to who it is supposed to. On another web space it doesn’t work, creating this error, **“Incorrect function.”** , when the Submit button is clicked.

Is it possible that one web space doesn’t allow PHP…?

I’ve uploaded exactly the same files in the correct directories. On one domain/web space it works, and on the other it doesn’t though.

…any ideas?
