Jump to content

Recommended Posts

Ok, I just did a bunch of looking around and found some ways to validate a form. I am trying to just validate the form, no sending to the database yet. I am using 2 different files, one for the functions, and one for the form and actual validation. When I hit submit, I get no feedback, and everything in the boxes dissappear. Here is the link to it running:

[a href=\"http://anylance.blogmyway.com/registration.php\" target=\"_blank\"]http://anylance.blogmyway.com/registration.php[/a]

These are the files:

functions.php
[code]
<?php

function isLetters($element) {
  return !preg_match ("/[^A-z]/", $element);
}
function checkLength($string, $min, $max) {
  $length = strlen ($string);
  if (($length < $min) || ($length > $max)) {
    return FALSE;
  } else {
    return TRUE;
  }
}
function checkEmail($email) {
  $pattern = "/^[A-z0-9\._-]+"
         . "@"
         . "[A-z0-9][A-z0-9-]*"
         . "(\.[A-z0-9_-]+)*"
         . "\.([A-z]{2,6})$/";
  return preg_match ($pattern, $email);
}
function isSame($string1, $string2) {
  if ($string1 != $string2) {
    return FALSE;
  } else {
    return TRUE;
  }
}
function checkPhone($phonenumber,$useareacode=true)  
{  
if ( preg_match("/^[ ]*[(]{0,1}[ ]*[0-9]{3,3}[ ]*[)]{0,1}[-]{0,1}[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/",$phonenumber) || (preg_match("/^[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/",$phonenumber) && !$useareacode)) return eregi_replace("[^0-9]", "", $phonenumber);  
return FALSE;
}
?>
[/code]

registration.php
[code]
<html>
<head>
<!--QrV3s1-->
<title>AnyLance - Anything You Need At Any Price You Want</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<STYLE TYPE="text/css">
<!--
BODY
   {
   font-family:Arial;
   font-size:12px;
   }
td
   {
   font-family:Arial;
   font-size:12px;
   color:003333;
   }
-->
</STYLE>

</head>

<?php
require_once ('functions.php');

$valid = TRUE;

if (isset ($_POST['submit'])) {
    foreach($_POST as $key=>$value) {
      $$key = $value;
    }
    
    $valid = $fn = checkLength($fname, 1, 30);
    $us = checkLength($username, 5, 30);
    $valid = $valid && $us;
    $fn2 = isLetters($username);
    $valid = $valid && $fn2;
    $em = checkEmail($email);
    $valid = $valid && $em;
    $ps2 = $password == $passwordc;
    $valid = $valid && $ps2;
    $em2 = $email == $emailc;
    $valid = $valid && $em2;
    $ph = checkPhone($number);
    $valid = $valid && $ph;
    if ($valid) {
        echo "Form filled successfully!";
        exit;
    }
} else {
    $fn = $ln = $us = $ph = $fn2 = $em = $ps = $ps2 = $em2 = TRUE;

}
?>

<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<BR>
<table width="750" border="0" cellpadding="0" cellspacing="0">
<TR><TD width=750>

<font style="font-family:arial;font-size:20px;color:000000;">
<h4>
Client Registration:
</h4>
</font><BR>
<center>
<table width="80%" border="1" bgcolor="whitesmoke" bordercolor="006666" cellpadding="8" cellspacing="0">
<TR><TD width="80%">

<form name="registerc" action="registration.php" method="post">


<table width="100%" border="0" cellpadding="0" cellspacing="0">
<TR><TD width="100%" colspan="2">
<B>Registering at AnyLance is easy.  Just fill in all of the blanks, and you're ready to go!</B><BR>
<font color="red">

<?php if(!$us) echo 'Username must be between 5 - 30 characters long<br />'; ?>
<?php if(!$ps2) echo 'Passwords do not match<br />'; ?>
<?php if(!$em2) echo 'Emails do not match<br />'; ?>
<?php if(!$em) echo 'Emails not valid<br />'; ?>
<?php if(!$fn) echo 'Please enter your first name<br />'; ?>
<?php if(!$fn2) echo 'Only letters in first name<br />'; ?>
<?php if(!$ph) echo 'Please enter a valid phone number, use xxx-xxx-xxxx format<br />'; ?>

</font>
<BR>
</td></tr>

<TR>
<TD width=50%>
&nbsp&nbspUsername:
</TD>
<td width="50%">
&nbsp
</td>
</TR>
<TR>
<TD width=50%>
<input type="text" name="username">
</TD>
<td width="50%">
&nbsp&nbspAlready registered with AnyLance?  Click Here!
</td>
</TR>

<TR><TD width="100%" colspan="2" height="10">&nbsp</TD></TR>
<TR>
<TD width=50%>
&nbsp&nbspPassword:
</TD>
<td width="50%">
&nbsp&nbspRe-Enter Password:
</td>
</TR>
<TR>
<TD width=50%>
<input type="password" name="password">
</TD>
<TD width=50%>
<input type="password" name="passwordc">
</TD>
</tr>

<TR><TD width="100%" colspan="2" height="10">&nbsp</TD></TR>
<TR>
<TD width=50%>
&nbsp&nbspEmail:*
</TD>
<td width="50%">
&nbsp&nbspRe-Enter Email:*
</td>
</TR>
<TR>
<TD width=50%>
<input type="text" name="email" size="30">
</TD>
<TD width=50%>
<input type="text" name="emailc" size="30">
</TD>
</tr>

<TR><TD width="100%" colspan="2" height="10">&nbsp</TD></TR>
<TR>
<TD width=50%>
&nbsp&nbspFirst Name:*
</TD>
<td width="50%">
&nbsp&nbspPhone Number:*
</td>
</TR>
<TR>
<TD width=50%>
<input type="text" name="fname" size="30">
</TD>
<TD width=50%>
<input type="text" name="number" size="30">
</TD>
</tr>
<TR><TD width="100%" colspan="2" height="10"><font style="font-family:arial;font-size:10px;color:003333;">
&nbsp&nbspYour Email, First Name, and Phone Number will only be visible to bidders whose services you accept.  Your

email will also be used to send you updates about your project.
</TD></TR>
</TABLE>
<BR><CENTER><input type="submit" value="Register"></CENTER>
</FORM>


</TD>
</TR></TABLE>

</center>
</TD>
</TR></TABLE>


</body>
</html>
[/code]

Any help is appreciated.

Thanks,
e39m5
Link to comment
https://forums.phpfreaks.com/topic/4173-validating-my-form-not-working/
Share on other sites

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.