This is a discussion on Variable in <FORM> action within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, In script below I try to validate the email address and when it's not correct it should NOT ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
In script below I try to validate the email address and when it's not correct it should NOT send the form containing the email address. Therefor the 'form' varable ( in <Form action="<?php echo $_SERVER['PHP_SELF'] ?>?form=yes" method="POST"> ) must not be 'yes'. Now the variable is always set to 'yes' but I want it to be 'no' when the email address is not correct. I tried to adjust this line (on the bottom of the script): <Form action="<?php echo $_SERVER['PHP_SELF'] ?>?form=yes" method="POST"> Into something like this <Form action="<?php echo $_SERVER['PHP_SELF'] ?>?form="<?php echo "$eml"; ?>" method="POST"> Where $eml is defiend in the validate_email() function in eighter yes or no. It's head breaking and I can't get it working. Does someone has the solution??? Cheers, Robert p.s. please reply in this newsgroup ----begin script------ <html> <head><title>Nieuwsbrief</title> <?PHP /* Scripting by IPOS (c) 2006 */ /* Function alert double entry email address */ function reenter_email($Email) { $twee_x_email = 0; ?> <form name="contact" action="<?php echo $_SERVER['PHP_SELF'] ?>?form=yes" method="POST"> <table> <tr> <td align="left" valign="top"> <?php print ("<b>Op e-mail adres: <i>".$Email."</i> ontvang je al een nieuwsbrief, voer opnieuw je email adres in:</B><BR><BR>"); ?> E-mail: <input type="text" name="Email" size="50" maxlength="30" onBlur='checkEmailAddress()'><BR></b> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value="Verzend"> <input type="reset" value="Wissen"> </td> </tr> </table> </form> <?PHP return($twee_x_email); return (Email); exit(); } ?> <?php function validate_email($Email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $Email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. $eml="no"; return false; } // Split it into sections to make life easier $email_array = explode("@", $Email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { $eml="no"; return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { $eml="no"; return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { $eml="no"; return false; } } } $eml="yes"; return true; } ?> </head> <body> <?php $host="localhost"; $user="root"; $password="nopass"; $database="db"; /* Section that executes query */ if(@$_GET['form'] == "yes") { /* Openen verbinding met database */ mysql_connect($host,$user,$password); mysql_select_db($database); /* Insert Values */ $query = "INSERT INTO Nieuwsbrief (VoorNaam, AchterNaam, Adres, Adres2, Pc, Wpl, Provincie, Land, Email, Nieuwsbrief, Wijzigingen, Aanbiedingen, Enquete) Values ('$VoorNaam', '$AchterNaam', '$Adres', '$Adres2', '$Pc', '$Wpl', '$Provincie', '$Land', '$Email', '$Nieuwsbrief', '$Wijzigingen', '$Aanbiedingen', 'NULL')"; $result = mysql_query($query); if($result == 0) $twee_x_email = mysql_errno(); if($twee_x_email == 1062) reenter_email($Email); elseif($result == 0) print ("<b>ER GING WAT MIS<BR>Error ".mysql_errno().": ".mysql_error(). "</b>"); elseif (@mysql_num_rows($result) == 0) print ("<b>Bedankt!<br><br>De eerstvolgende nieuwsbrief ontvang jij ook! </b><br>"); else print ("xx"); unset($form); exit(); } // endif form=yes ?> <form name="contact" action="<?php echo $_SERVER['PHP_SELF'] ?>?form=yes" method="POST"> <table> <tr> <td align="right" valign="top"> <b>E-mail: <input type="text" name="Email" size="50" maxlength="30"><BR> </b> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value="Verzend" onClick="validate_email()"> <input type="reset" value="Wissen"> </td> </tr> </table> </form> </body></html> |
|
|||
|
I think you are looking for something like this:
http://www.google.com/search?hl=en&h...+email&spell=1 YOU CANNOT RUN PHP IN CLIENT SIDE! onClick="validate_email()" will execute JavaScript not PHP... |
|
|||
|
Thanks.
I originally wanted to do this in PHP but i cannot get it to work, I have a javascript now, thanks! "Drakazz" <tikras@hakeris.co.uk> schreef in bericht news:1141201597.702009.12890@i40g2000cwc.googlegro ups.com... >I think you are looking for something like this: > http://www.google.com/search?hl=en&h...+email&spell=1 > > YOU CANNOT RUN PHP IN CLIENT SIDE! > onClick="validate_email()" will execute JavaScript not PHP... > |