It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

PHP Validation Script

Moderator: Malcolm

Postby Malcolm on Tue Jan 04, 2005 12:08 am

I just got home from work, I'll work on it once I'm finnished my dinner :)
Image
User avatar
Malcolm
100+ Club
 
Posts: 198
Joined: Thu Oct 07, 2004 9:53 pm
Location: Ontario, Canada

Postby Malcolm on Tue Jan 04, 2005 1:14 am

Point #1: viewtopic.php?p=2952#2952

#2: I need to see where the forum data is going for it to be checked, unless you want to do a javascript solution. You could make your form action ($editFormAction) link to the current page. I need more information to be able to help with the validation part of the script.
Image
User avatar
Malcolm
100+ Club
 
Posts: 198
Joined: Thu Oct 07, 2004 9:53 pm
Location: Ontario, Canada

Postby tech_angel420 on Tue Jan 04, 2005 2:02 pm

This is where it's going to be checked:

Code: Select all
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "formInsertRecord")) {
  $insertSQL = sprintf("INSERT INTO payments (AccountNumber, FirstName, LastName, Phone, Email, PaymentAmount, Attention, CCType, CCNumber, CCExpMonth, CCExpYear, CCFullName, CHNumber, CHDate, CHBankName, CHRoutingNumber, CHAccountNumber, Address1, Address2, City, `State`, Zip, RecurrenceDate, Comments) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['textAccountNumber'], "text"),
                       GetSQLValueString($_POST['textFirstName'], "text"),
                       GetSQLValueString($_POST['textLastName'], "text"),
                       GetSQLValueString($_POST['textPhone'], "text"),
                       GetSQLValueString($_POST['textEmail'], "text"),
                       GetSQLValueString($_POST['textAmount'], "double"),
                       GetSQLValueString($_POST['textPayAttn'], "text"),
                       GetSQLValueString($_POST['selectCCType'], "text"),
                       GetSQLValueString($_POST['textCCNumber'], "text"),
                       GetSQLValueString($_POST['selectCCExpMonth'], "text"),
                       GetSQLValueString($_POST['selectCCExpYear'], "text"),
                       GetSQLValueString($_POST['textCCName'], "text"),
                       GetSQLValueString($_POST['textCHNumber'], "bigint"),
                       GetSQLValueString($_POST['textCHDate'], "date"),
                       GetSQLValueString($_POST['textCHBank'], "text"),
                       GetSQLValueString($_POST['textCHRouting'], "text"),
                       GetSQLValueString($_POST['textCHAccountNum'], "bigint"),
                       GetSQLValueString($_POST['textAddress1'], "text"),
                       GetSQLValueString($_POST['textAddress2'], "text"),
                       GetSQLValueString($_POST['textCity'], "text"),
                       GetSQLValueString($_POST['selectSt'], "text"),
                       GetSQLValueString($_POST['textZip'], "int"),
                       GetSQLValueString($_POST['textRecurringDate'], "date"),
                  GetSQLValueString($_POST['textComments'], "text"));


and here's some various fields:
Code: Select all
print ("<div class=\"row\"><span class=\"label\">Account Number:</span><span class=\"formw2\"><input name=\"textAccountNumber\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>First Name:</span><span class=\"formw2\"><input name=\"textFirstName\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Last Name:</span><span class=\"formw2\"><input name=\"textLastName\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Address:</span><span class=\"formw2\"><input name=\"textAddress1\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\">Address Line 2:</span><span class=\"formw2\"><input name=\"textAddress2\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>City:</span><span class=\"formw2\"><input name=\"textCity\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>State:</span><span class=\"formSelect\"><span class =\"formw3\"><select name=\"selectSt\">");
      foreach ($StateList_array as $ctype1)
      {
      print("<option>" . $ctype1 . "</option>");
      }
      print ("</select></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Zip code:</span><span class=\"formw2\"><input name=\"textZip\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Phone number:</span><span class=\"formw2\"><input name=\"textPhone\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\">E-mail address:</span><span class=\"formw2\"><input name=\"textEmail\" /></span></div><br>\n");


I have some payment fields too that need to be required... three radio buttons with three different types of payment choices. How do I make it so that it requires 1 of the 3 choices? (for reference to this code, see it where I posted it above in the 8th post down)
tech_angel420
 
Posts: 27
Joined: Thu Dec 16, 2004 4:02 pm

Postby tech_angel420 on Mon Jan 24, 2005 3:29 pm

Ended up using Javascript. Finally figured it out...
tech_angel420
 
Posts: 27
Joined: Thu Dec 16, 2004 4:02 pm

Re: PHP Validation Script

Postby phpfans on Thu Jun 09, 2011 3:16 am

Some free php validation scripts you can search and free download.
Glad to recommend a nice validation scripts, You can try it:
Code: Select all
class CompareValidator
03       {
04           private $data=array();
05   
06           public function CompareValidator($name)
07           {
08               $this->data['Name']=$name;
09               $this->data['BackColor']='#ffff00';
10               $this->data['BorderColor']='#ff0000';
11               $this->data['ControlToCompare']='';
12               $this->data['ControlToValidate']='';
13               $this->data['Font']='Tahoma';
14               $this->data['ForeColor']='#ff0000';
15               $this->data['Height']='25';
16               $this->data['Text']='اطلاعات وارد شده يكسان نيست';
17               $this->data['Width']='250';
18           }
19   
20           public function Draw()
21           {
22               echo '<DIV id="div'.$this->data['Name'].'" style="';
23               echo 'background-color: '.$this->data['BackColor'].'; ';
24               echo 'border-color: '.$this->data['BorderColor'].'; ';
25               echo 'border: solid; ';
26               echo 'font-family: '.$this->data['Font'].'; ';
27               echo 'color: '.$this->data['ForeColor'].'; ';
28               echo 'height: '.$this->data['Height'].'px; ';
29               echo 'width: '.$this->data['Width'].'px;"';
30               echo '></DIV>'."\n";
31               echo '<INPUT type="hidden" name="inp'.$this->data['Name'].'" id="inp'.$this->data['Name'].'" value="">'."\n";
32               echo '<SCRIPT language="javascript" type="text/javascript">'."\n";
33               echo '    function '.$this->data['Name'].'()'."\n";
34               echo '    {'."\n";
35               echo '        var cmp = document.getElementById(\''.$this->data['ControlToCompare'].'\');'."\n";
36               echo '        var vld = document.getElementById(\''.$this->data['ControlToValidate'].'\');'."\n";
37               echo '        var div = document.getElementById(\'div'.$this->data['Name'].'\');'."\n";
38               echo '        var inp = document.getElementById(\'inp'.$this->data['Name'].'\');'."\n";
39               echo '        div.innerHTML = (cmp.value!=vld.value?\''.$this->data['Text'].'\':\'\')'."\n";
40               echo '        inp.value = (div.innerHTML==\'\'?\'true\':\'false\')'."\n";
41               echo '    }'."\n";
42               echo '</SCRIPT>'."\n";
43           }
44   
45           public function __get($name)
46           {
47               if(array_key_exists($name,$this->data))
48               {
49                   return $this->data[$name];
50               }
51           }
52   
53           public function __set($name,$value)
54           {
55               if(array_key_exists($name,$this->data))
56               {
57                   $this->data[$name]=$value;
58               }
59           }
60       }
61   ?>
phpfans
 
Posts: 2
Joined: Thu Dec 02, 2010 3:33 am

Previous

Who is online

Users browsing this forum: No registered users and 0 guests