I need to create my own form with PHP in EZ-Pages. I've followed this thread and can make a simple echo statement work, but as soon as I try to add some functions nothing shows on my page. Here is what I have right now:
With this code, nothing is shown. If I take out the PHP before the form (just the functions) then the form is shown - so I know it's not the HTML. I need to add error-checking to this but don't know why I'm getting an error when I just add functions that aren't even being called yet. I've also used these functions on other sites and they work - so I don't believe the PHP code is wrong either.PHP Code:
<?php
function validPhone($phone)
{
if(ereg('^[2-9]{1}[0-9]{2}-[0-9]{3}-[0-9]{4}$', $phone))
return true;
else
return false;
}
/*
EmailAddressValidator Class
http://code.google.com/p/php-email-address-validation/
Released under New BSD license
http://www.opensource.org/licenses/bsd-license.php
Sample Code
----------------
$validator = new EmailAddressValidator;
if ($validator->check_email_address('[email protected]')) {
// Email address is technically valid
}
*/
class EmailAddressValidator {
/**
* Check email address validity
* @param strEmailAddress Email address to be checked
* @return True if email is valid, false if not
*/
public function check_email_address($strEmailAddress) {
// If magic quotes is "on", email addresses with quote marks will
// fail validation because of added escape characters. Uncommenting
// the next three lines will allow for this issue.
//if (get_magic_quotes_gpc()) {
// $strEmailAddress = stripslashes($strEmailAddress);
//}
// Control characters are not allowed
if (preg_match('/[x00-x1Fx7F-xFF]/', $strEmailAddress)) {
return false;
}
// Check email length - min 3 (a@a), max 256
if (!$this->check_text_length($strEmailAddress, 3, 256)) {
return false;
}
// Split it into sections using last instance of "@"
$intAtSymbol = strrpos($strEmailAddress, '@');
if ($intAtSymbol === false) {
// No "@" symbol in email.
return false;
}
$arrEmailAddress[0] = substr($strEmailAddress, 0, $intAtSymbol);
$arrEmailAddress[1] = substr($strEmailAddress, $intAtSymbol + 1);
// Count the "@" symbols. Only one is allowed, except where
// contained in quote marks in the local part. Quickest way to
// check this is to remove anything in quotes. We also remove
// characters escaped with backslash, and the backslash
// character.
$arrTempAddress[0] = preg_replace('/./'
,''
,$arrEmailAddress[0]);
$arrTempAddress[0] = preg_replace('/"[^"]+"/'
,''
,$arrTempAddress[0]);
$arrTempAddress[1] = $arrEmailAddress[1];
$strTempAddress = $arrTempAddress[0] . $arrTempAddress[1];
// Then check - should be no "@" symbols.
if (strrpos($strTempAddress, '@') !== false) {
// "@" symbol found
return false;
}
// Check local portion
if (!$this->check_local_portion($arrEmailAddress[0])) {
return false;
}
// Check domain portion
if (!$this->check_domain_portion($arrEmailAddress[1])) {
return false;
}
// If we're still here, all checks above passed. Email is valid.
return true;
}
/**
* Checks email section before "@" symbol for validity
* @param strLocalPortion Text to be checked
* @return True if local portion is valid, false if not
*/
protected function check_local_portion($strLocalPortion) {
// Local portion can only be from 1 to 64 characters, inclusive.
// Please note that servers are encouraged to accept longer local
// parts than 64 characters.
if (!$this->check_text_length($strLocalPortion, 1, 64)) {
return false;
}
// Local portion must be:
// 1) a dot-atom (strings separated by periods)
// 2) a quoted string
// 3) an obsolete format string (combination of the above)
$arrLocalPortion = explode('.', $strLocalPortion);
for ($i = 0, $max = sizeof($arrLocalPortion); $i < $max; $i++) {
if (!preg_match('.^('
. "([A-Za-z0-9!#$%&'*+/=?^_`{|}~-]"
. "[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]{0,63})"
.'|'
. '("[^"]{0,62}")'
.')$.'
,$arrLocalPortion[$i])) {
return false;
}
}
return true;
}
/**
* Checks email section after "@" symbol for validity
* @param strDomainPortion Text to be checked
* @return True if domain portion is valid, false if not
*/
protected function check_domain_portion($strDomainPortion) {
// Total domain can only be from 1 to 255 characters, inclusive
if (!$this->check_text_length($strDomainPortion, 1, 255)) {
return false;
}
// Check if domain is IP, possibly enclosed in square brackets.
if (preg_match('/^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])'
.'(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}$/'
,$strDomainPortion) ||
preg_match('/^[(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])'
.'(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}]$/'
,$strDomainPortion)) {
return true;
} else {
$arrDomainPortion = explode('.', $strDomainPortion);
if (sizeof($arrDomainPortion) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0, $max = sizeof($arrDomainPortion); $i < $max; $i++) {
// Each portion must be between 1 and 63 characters, inclusive
if (!$this->check_text_length($arrDomainPortion[$i], 1, 63)) {
return false;
}
if (!preg_match('/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|'
.'([A-Za-z0-9]+))$/', $arrDomainPortion[$i])) {
return false;
}
if ($i == $max - 1) { // TLD cannot be only numbers
if (strlen(preg_replace('/[0-9]/', '', $arrDomainPortion[$i])) <= 0) {
return false;
}
}
}
}
return true;
}
/**
* Check given text length is between defined bounds
* @param strText Text to be checked
* @param intMinimum Minimum acceptable length
* @param intMaximum Maximum acceptable length
* @return True if string is within bounds (inclusive), false if not
*/
protected function check_text_length($strText, $intMinimum, $intMaximum) {
// Minimum and maximum are both inclusive
$intTextLength = strlen($strText);
if (($intTextLength < $intMinimum) || ($intTextLength > $intMaximum)) {
return false;
} else {
return true;
}
}
}
?>
<html>
<img src="http://lemarceldogbakery.com/good dog club/good-dog-club.gif" />
<br />
<div style="text-align:center">
<form id="club_form" name="club_form" method="post" action="good_dog_club.php">
<label for="name"><img src="http://lemarceldogbakery.com/forms/name.gif" width="176"/></label>
<input type="text" name="name" id="name" />
<span style="color : #FF0000"><?php if(!empty($namemsg)) echo $namemsg; ?></span>
<br />
<label for="address"><img src="http://lemarceldogbakery.com/forms/address.gif" width="176"/></label>
<input type="text" name="address" id="address" />
<span style="color : #FF0000"><?php if(!empty($addressmsg)) echo $addressmsg; ?></span>
<br />
<label for="city"><img src="http://lemarceldogbakery.com/forms/city.gif" width="176"/></label>
<input type="text" name="city" id="city" />
<span style="color : #FF0000"><?php if(!empty($citymsg)) echo $citymsg; ?></span>
<br />
<label for="state" style="margin-left:40px"><img src="http://lemarceldogbakery.com/forms/state.gif" width="176"/></label>
<select name="state" size="1" id="state" style="margin-right:71px">
<option value="" selected="selected">Choose</option>
<option value="AK">AK</option>
<option value="AL">AL</option>
<option value="AR">AR</option>
<option value="AZ">AZ</option>
<option value="CA">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DC">DC</option>
<option value="DE">DE</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="HI">HI</option>
<option value="IA">IA</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="MA">MA</option>
<option value="MD">MD</option>
<option value="ME">ME</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MO">MO</option>
<option value="MS">MS</option>
<option value="MT">MT</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="NE">NE</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NV">NV</option>
<option value="NY">NY</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="VA">VA</option>
<option value="VT">VT</option>
<option value="WA">WA</option>
<option value="WI">WI</option>
<option value="WV">WV</option>
<option value="WY">WY</option>
</select>
<span style="color : #FF0000"><?php if(!empty($statemsg)) echo $statemsg; ?></span>
<br />
<label for="zip"><img src="http://lemarceldogbakery.com/forms/zip.gif" width="176"/></label>
<input type="text" name="zip" id="zip" />
<span style="color : #FF0000"><?php if(!empty($zipmsg)) echo $zipmsg; ?></span>
<br />
<label for="phone"><img src="http://lemarceldogbakery.com/forms/phone.gif" width="176" /></label>
<input type="text" name="phone" id="phone" />
<span style="color : #FF0000"><?php if(!empty($phonemsg)) echo $phonemsg; ?></span>
<br />
<label for="email"><img src="http://lemarceldogbakery.com/forms/email.gif" width="176" /></label>
<input type="text" name="email" id="email" />
<span style="color : #FF0000"><?php if(!empty($emailmsg)) echo $emailmsg; ?></span>
<br />
<label for="dogs_names"><img src="http://lemarceldogbakery.com/forms/dogs-names.gif" width="176" /></label>
<input type="text" name="dogs_names" id="dogs_names" />
<span style="color : #FF0000"><?php if(!empty($dnamesmsg)) echo $dnamesmsg; ?></span>
<br />
<input type="image" src="http://lemarceldogbakery.com/forms/register.gif" value="Submit" name="subbutton" id="subbutton" class="button" style="margin-left:170px"/>
</form>
</div>
</html>
Thanks.
Bookmarks