Jump to content

Recommended Posts

Excuse my ignorance, I am brand new, and very much a novice when it comes to PHP...

 

I have looked throughout this forum, and could not find a simple answer to this:

 

I have a PHP script that is intended to validate an email address that one enters on a form that is dynamically generated.

 

The script i am trying to implement is:

 

function isValidEmail($email){return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email); }

 

And my form code is:

 

<form name="frm" action="dist.php" method="post" tmt:validate="true" onSubmit="validate()">

 

<input type="hidden" name="prod_id" value="<?php echo $_GET['find_id'];?>">

<input type="hidden" name="market" value="<?php echo $find['market']; ?>">

               

                 

<TABLE height=107 cellSpacing=0 cellPadding=0 width=322 align=left border=0>

      <TR>

                      <TH scope=row height=107>

  <DIV align=left>

                        <p>

                        <p class="header">Please fill out the following basic information so that we may send you to the appropriate distributor:</p>

                        <table width="100%" border="0">

                          <tr>

                            <td width="41%"><span class="littleheader">First Name</span><br>

                                <span class="specialheader">

                                <input name="fname" type="text" id="fname" size="20" tmt:required="false" tmt:message="Please Enter First Name">

                              </span></td>

                            <td width="59%"><span class="littleheader">Last Name</span><br>

                                <span class="specialheader">

                                <input name="lname" type="text" id="lname" size="28" tmt:required="false" tmt:message="Plese Enter Last Name">

                              </span></td>

                          </tr>

                          <tr>

                            <td colspan="2"><p class="littleheader">* Company Name<br>

                                    <input name="company" type="text" id="company" size="53" tmt:required="true" tmt:message="Please Enter Company Name">

                            </p></td>

                          </tr>

                          <tr>

                    <td colspan="2"><p class="littleheader">* Email<br>

                   

                    <input name="email" type="text" id="email" size="53" tmt:required="true" tmt:message="Please Enter Email">

                   

                    </p></td>

                          </tr>

                          <tr>

                            <td colspan="2"><span class="littleheader">* Zip Code<br>

                                  <input type="text" name="zipcode" tmt:required="true" tmt:message="Please Enter Zipcode">

                            </span></td>

                          </tr>

                          <tr>

                            <td colspan="2"><p class=body><span class=specialheader><br>

                                </span><span class="header">Please

                                  Select Your Market(s):</span><span class=specialheader><br>

                                        </span></p>

                                <p class=body>*note: you may select more than

                                  one<br>

                                          <br>

                                </p>

                              <?php $markets=$find['market'];

$query_market=executeQuery("select * from tbl_market");

while ($market=mysql_fetch_array($query_market)){?>

                                <input type="checkbox" name="market[]" value="<?php echo $market['id'];?>">

                                <label class=bodybold1 for=CATV><?php echo strtoupper($market['name']);?></label>

                                <br>

                                <?php } ?>

                                <p></p></td>

                          </tr>

                          <tr>

                            <td colspan="2"><span class="littleheader">Within <br>

                                  <select name="miles" class="body">

                                    <option value="5"> 5 miles</option>

                                    <option value="10"> 10 miles</option>

                                    <option value="15"> 15 miles</option>

                                    <option value="20"> 20 miles</option>

                                    <option value="25"> 25 miles</option>

                                  </select>

                            </span></td>

                          </tr>

                        </table>

                        <P class=littleheader> </P>

                       

                        <input type="hidden" name="product" tmt:required="false" value="<?php echo $_REQUEST['find_id'] ?>">

                       

                 

<input type="image" src="images/find_button.gif" height=20 alt=""  width=114  border=0>

  </div>   </TH></TR>

  </TABLE>

</form>

 

 

--------------------------

 

I am not sure where to put the script to make sure it validates the email.  i have tried it in several locations in the form code, and it has not worked yet.

 

I am not sure if the script is bad, or i am just not putting it in the right place.

 

It is supposed to disallow the user to proceed if the email is bad.  As of now, andyone can just put anything in there, and still proceed to the onSubmit page.

 

Any help is greatly appreciated.

 

Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/140554-simple-email-validator/
Share on other sites

Got it... sorry about that  :-[

 

The script i am trying to implement is:

 

function isValidEmail($email){return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email); }

 

And my form code is:

 

<form name="frm" action="dist.php" method="post" tmt:validate="true" onSubmit="validate()">

<input type="hidden" name="prod_id" value="<?php echo $_GET['find_id'];?>">
<input type="hidden" name="market" value="<?php echo $find['market']; ?>">
                 
                 
<TABLE height=107 cellSpacing=0 cellPadding=0 width=322 align=left border=0>
      <TR>
                      <TH scope=row height=107>
                 <DIV align=left>
                        <p>
                        <p class="header">Please fill out the following basic information so that we may send you to the appropriate distributor:</p>
                        <table width="100%" border="0">
                          <tr>
                            <td width="41%"><span class="littleheader">First Name</span><br>
                                <span class="specialheader">
                                <input name="fname" type="text" id="fname" size="20" tmt:required="false" tmt:message="Please Enter First Name">
                              </span></td>
                            <td width="59%"><span class="littleheader">Last Name</span><br>
                                <span class="specialheader">
                                <input name="lname" type="text" id="lname" size="28" tmt:required="false" tmt:message="Plese Enter Last Name">
                              </span></td>
                          </tr>
                          <tr>
                            <td colspan="2"><p class="littleheader">* Company Name<br>
                                    <input name="company" type="text" id="company" size="53" tmt:required="true" tmt:message="Please Enter Company Name">
                            </p></td>
                          </tr>
                          <tr>
                    <td colspan="2"><p class="littleheader">* Email<br>
                   
                    <input name="email" type="text" id="email" size="53" tmt:required="true" tmt:message="Please Enter Email">
                   
                    </p></td>
                          </tr>
                          <tr>
                            <td colspan="2"><span class="littleheader">* Zip Code<br>
                                  <input type="text" name="zipcode" tmt:required="true" tmt:message="Please Enter Zipcode">
                            </span></td>
                          </tr>
                          <tr>
                            <td colspan="2"><p class=body><span class=specialheader><br>
                                </span><span class="header">Please
                                  Select Your Market(s):</span><span class=specialheader><br>
                                        </span></p>
                                <p class=body>*note: you may select more than
                                  one<br>
                                          <br>
                                </p>
                              <?php $markets=$find['market'];
                   $query_market=executeQuery("select * from tbl_market");
                   while ($market=mysql_fetch_array($query_market)){?>
                                <input type="checkbox" name="market[]" value="<?php echo $market['id'];?>">
                                <label class=bodybold1 for=CATV><?php echo strtoupper($market['name']);?></label>
                                <br>
                                <?php } ?>
                                <p></p></td>
                          </tr>
                          <tr>
                            <td colspan="2"><span class="littleheader">Within <br>
                                  <select name="miles" class="body">
                                    <option value="5"> 5 miles</option>
                                    <option value="10"> 10 miles</option>
                                    <option value="15"> 15 miles</option>
                                    <option value="20"> 20 miles</option>
                                    <option value="25"> 25 miles</option>
                                  </select>
                            </span></td>
                          </tr>
                        </table>
                        <P class=littleheader> </P>
                       
                        <input type="hidden" name="product" tmt:required="false" value="<?php echo $_REQUEST['find_id'] ?>">
                       
                   
               <input type="image" src="images/find_button.gif" height=20 alt=""  width=114  border=0>
                 </div>                 </TH></TR>
                 </TABLE>
</form>

 

--------------------------

 

I am not sure where to put the script to make sure it validates the email.  i have tried it in several locations in the form code, and it has not worked yet.

 

I am not sure if the script is bad, or i am just not putting it in the right place.

 

It is supposed to disallow the user to proceed if the email is bad.  As of now, andyone can just put anything in there, and still proceed to the onSubmit page.

 

Any help is greatly appreciated.

 

Thanks.

Hmm, you have a lot of code and without any errors it is hard to know what is wrong.

 

Put at the top of the page

 

<?php

error_reporting(E_ALL);

ini_set("display_errors",true);

?>

 

And maybe have a look at this

http://www.plus2net.com/php_tutorial/php_email_validation.php

 

Edit: Where are you calling the function?

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.