Jump to content

Optional Email Field, validate if not empty.


ibda12u

Recommended Posts

Hello just as my title says, I have a form with an email field that is optional for the user to fill out.
What I've been trying to do is if a user fills out the optional email address field, it will check that field to make sure there is a . and an @ in the email.

My code here works, except it won't validate if the email field is empty.

Any idea's?
[code]
<?php
if($fathers_email != "" && !strstr($fathers_email,"@") || !strstr($fathers_email,".")) {
echo 'Sorry all required fields were not filled out, please <a href="javascript: history.go(-1)">go back</a> and correct Father\'s Email Address. ';
} else {
echo '  [/code]
I tried this, and it won't let me not enter an email at all.

[code] <?php
if(isset($fathers_email)){
if(!strstr($fathers_email,"@") || !strstr($fathers_email,".")) {
echo '<span class="style5">Sorry all required fields were not filled out, please <a href="javascript: history.go(-1)">go back</a> and correct Father\'s Email Address.</span> ';
}else {
echo ' [/code]
it just displays the pages html

[code]
<?php
if($fathers_email != "" && !strstr($fathers_email,"@") || !strstr($fathers_email,".")) {
echo 'Sorry all required fields were not filled out, please <a href="javascript: history.go(-1)">go back</a> and correct Father\'s Email Address. ';
} else {
echo 'Enrollment Application Step 5</font></b></font><p><font face="Verdana" size="1">Please

                  complete the form below to reserve your child\'s

                  spot. While it does not guarantee that an opening will be

                  immediately available, it does promise that the next available

                  spot will be held for your child. <font color="#CC3300">To

                  avoid delays </font></font>
  ';}
                    ?>
[/code]

[code]<?php
if(isset($fathers_email) {
  if(!strstr($fathers_email,"@") || !strstr($fathers_email,".")) {
echo "Incorrect email address formatting!";
} else {
    echo 'Enrollment Application Step 5</font></b></font><p><font face="Verdana" size="1">Please ';
    echo 'complete the form below to reserve your child\'s ';
    echo 'spot. While it does not guarantee that an opening will be ';
    echo 'immediately available, it does promise that the next available ';
    echo 'spot will be held for your child. <font color="#CC3300">To ';
    echo 'avoid delays </font></font>';
}
} else {
echo 'Sorry all required fields were not filled out, please <a href="javascript: history.go(-1)">go back</a> and correct Father\'s Email Address. ';
}
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.