Problem with form

3 posts by 2 authors in: Forums > CMS Builder
Last Post: October 18, 2010   (RSS)

By paulmac - October 18, 2010

Hi

I'm getting some error messages on a form I'm using.

The header information is:

// process form
if (@$_REQUEST['submitForm']) {

// error checking
$errorsAndAlerts = "";
if ([url "mailto:!@$_REQUEST['fullname'"]!@$_REQUEST['fullname'[/url]]) { $errorsAndAlerts .= "You must enter your full name!<br/>\n"; }
if ([url "mailto:!@$_REQUEST['email'"]!@$_REQUEST['email'[/url]]) { $errorsAndAlerts .= "You must enter your email!<br/>\n"; }
else if(!isValidEmail(@$_REQUEST['email'])) { $errorsAndAlerts .= "Please enter a valid email (example:

user@example.com)<br/>\n"; }
if ([url "mailto:!@$_REQUEST['message'"]!@$_REQUEST['message'[/url]]) { $errorsAndAlerts .= "You must enter a message!<br/>\n"; }

// send email user
if (!$errorsAndAlerts) {
$from = $_REQUEST['email'];
$to = "name@emailaddress.com";
$subject = "Email form submitted";
$message = <<<__TEXT__
You've received an email enquiry from the website


Full name: {$_REQUEST['fullname']}
Company name: {$_REQUEST['companyname']}
Company type: {$_REQUEST['companytype']}
Phone: {$_REQUEST['telephone']}
Email: {$_REQUEST['email']}
Area of Interest1: {$_REQUEST['area_interest1']}
Area of Interest2: {$_REQUEST['area_interest2']}
Area of Interest3: {$_REQUEST['area_interest3']}
Area of Interest4: {$_REQUEST['area_interest4']}
Area of Interest5: {$_REQUEST['area_interest5']}
Area of Interest6: {$_REQUEST['area_interest6']}
Message: {$_REQUEST['message']}

The user who sent this message had the IP address {$_SERVER['REMOTE_ADDR']}.
__TEXT__;
// Note: The above line must be flush left or you'll get an error
// This is a PHP heredoc. See:

http://ca2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

// send message
$mailResult = @mail($to, $subject, $message, "From: $from");
if (!$mailResult) { die("Mail Error: $php_errormsg"); }

//
$errorsAndAlerts = "Thanks for your enquiry. ";
$_REQUEST = array(); // clear form values
}

}

?>





and the actual form is:



<form method="post" action="?">
<input type="hidden" name="submitForm" value="1" />
<h1>Enquiry Form </h1>
<?php if (@$errorsAndAlerts): ?>
<div style="color: black; font-weight: bold; font-size: 14px; font-family: arial;"><br/>
<?php echo $errorsAndAlerts; ?><br/>
<br/>
</div>
<?php endif ?>
<table width="403" border="0" cellpadding="2" cellspacing="0">
<tr>
<td colspan="2" class="breadcrumb">* indicate required field </td>
</tr>
<tr>
<td width="150">Full Name*</td>
<td><input class="text-input medium-input" type="text" name="fullname" value="<?php echo

htmlspecialchars(@$_REQUEST['fullname']); ?>" size="20" /></td>
</tr>
<tr>
<td width="150">Company Name</td>
<td><input class="text-input medium-input" type="text" name="companyname" value="<?php echo

htmlspecialchars(@$_REQUEST['companyname']); ?>" size="20" /></td>
</tr>
<tr>
<td>Company Type </td>
<td><label>
<select name="companytype" size="1" id="companytype">
<option>Select From Below</option>
<option value="Trader">Trader</option>
<option value="Contractor">Contractor</option>
<option value="End User">End User</option>
<option value="Supplier">Supplier</option>
</select>
</label></td>
</tr>
<tr>
<td width="150">Telephone</td>
<td><input class="text-input medium-input" type="text" name="telephone" value="<?php echo

htmlspecialchars(@$_REQUEST['telephone']); ?>" size="20" /></td>
</tr>
<tr>
<td width="150">Email*</td>
<td><input class="text-input medium-input" type="text" name="email" value="<?php echo

htmlspecialchars(@$_REQUEST['email']); ?>" size="20" /></td>
</tr>
<tr>
<td colspan="2">Please select your specific areas of interest: </td>
</tr>
<tr>
<td colspan="2">
<input name="area_interest1" type="checkbox" id="area_interest1" value="area1" />
Standard Generator Sets
<input name="area_interest2" type="checkbox" id="area_interest2" value="area2" />
UPS Sy-stems
<input name="area_interest3" type="checkbox" id="area_interest3" value="area3" />
Power Plants<br />

<input name="area_interest4" type="checkbox" id="area_interest4" value="area4" />
Gas &amp; Co-Generation Systems
<input name="area_interest5" type="checkbox" id="area_interest5" value="area5" />
Oil &amp; Gas
<input name="area_interest6" type="checkbox" id="area_interest6" value="area6l" />
Rental </td>
</tr>
<tr>
<td width="150" valign="top">Your Enquiry
*</td>
<td valign="top"><textarea name="message" rows="5" cols="35"><?php echo htmlspecialchars(@$_REQUEST

['message']); ?></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><br/>
<input class="button" type="submit" name="submit" value="Send Message &gt;&gt;" />

</td>
</tr>
</table>
</form>





I can fill in the form ok and it will get sent, the problem is with the checkbox area of interest. If they are not checked and left blank, I get an error at the top of the page:

Notice: Undefined index: area_interest1 in /home/public_html/contact.php on line 34

How can I get rid of this error.

Thanks

Re: [chris] Problem with form

By paulmac - October 18, 2010

Worked perfect. Thanks Chris!