Jump to content

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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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