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

PHP Validation Script

Postby tech_angel420 on Thu Dec 30, 2004 9:05 pm

Hi everyone... Can anyone give me a general idea of how to start writing a PHP Form Validation script?? Javascript just isn't working for me because first off, I am a super beginner in that department...
tech_angel420
 
Posts: 27
Joined: Thu Dec 16, 2004 4:02 pm

Postby webmaster on Thu Dec 30, 2004 9:33 pm

What exactly do you mean with Form Validation script?
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Postby tech_angel420 on Thu Dec 30, 2004 9:39 pm

I have a payment form, written in PHP... I have various fields that I want specific information validated... I have required fields, character-type fields, etc... Normally, from what I understand, a javascript is used to do this. I am having issues like you wouldn't believe with JS and I'm sick of it so I want to do the validation in PHP and then following that procedure, the results will post in a database.
tech_angel420
 
Posts: 27
Joined: Thu Dec 16, 2004 4:02 pm

Postby webmaster on Thu Dec 30, 2004 9:54 pm

Here is two things that could help you:

1. Set a special amoun to chars in a text input:
Code: Select all
<input type='text' name='description' size='70' maxlength='70'>


2. A field must contain information:
Code: Select all
<? if(empty($_POST['description'])) { echo "YOU MUST FILL-IN THE DESCRIPTION-INPUT"; }?>
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Postby tech_angel420 on Thu Dec 30, 2004 10:10 pm

I'll give that concept a whirl... what if I need to ensure that like a date is entered in a certain way? Or to specify the number of characters for say like a phone number or zip code?? And also the email?? LOL... I'm hopeless..
tech_angel420
 
Posts: 27
Joined: Thu Dec 16, 2004 4:02 pm

Postby webmaster on Fri Dec 31, 2004 12:53 am

I definately don't think this is the best way, but hopefully, it'll work. For example you want somebody to enter a zip-code like this: 123-45
Code: Select all
<?
$forth = substr($_POST['zip'], 3, 2);

if($forth != "-") {
   echo "ERROR";
}
?>


Read more about the substr function here: http://se.php.net/manual/en/function.substr.php
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Postby Malcolm on Fri Dec 31, 2004 12:56 am

You're going to need to use regular expressions (regex) if you need your data entered in a specific way; or better yet you can use regex to format non-proper input.

Show me what type of input you're grabbing for the user and how you'd like them to enter the data and I'll give you a few examples :)
Image
User avatar
Malcolm
100+ Club
 
Posts: 198
Joined: Thu Oct 07, 2004 9:53 pm
Location: Ontario, Canada

Postby tech_angel420 on Mon Jan 03, 2005 3:40 pm

Mkay, I appreciate the help... Here's some of my fields:

Code: Select all
   echo "<div id=\"form\" style=\"position:absolute; top:180px; left:156px; z-index:3; padding:0px; width:768px; height: 1207px;\">
      <form action='$editFormAction' method='post' name='formInsertRecord' onsubmit='return validateForm(this)'>\n";
         print ("<p><input type=\"hidden\" name=\"send\" value=\"true\" />\n");
      print ("</p><br>\n");
      //Customer Information//
      print ("<p class=\"pmtheads\">Customer Information</p><br>\n");
      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\"><span class=\"asterisk\">*</span>E-mail address:</span><span class=\"formw2\"><input name=\"textEmail\" /></span></div><br>\n");
      //Payment Data//
      print ("<p class=\"pmtheads\">Payment Information</p><br>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Payment Amount:</span><span class=\"formw2\"><input name=\"textAmount\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\">Payment Attention:</span><span class=\"formw2\"><input name=\"PayAttn\" /></span></div><br>\n");
      //Payment Types - Credit//
      print ("<div class=\"row3\"><p class=\"pmtheads2\">Please choose one:</span>&nbsp;
           <label for=\"Check\">Check</label><span class=\"formw3\"><input name=\"ToggleDivs\" type=\"radio\" value=\"Check\" onClick=\"Toggle('Div1')\" id=\"Div11\"></span>&nbsp;
           <label for=\"Credit\">Credit</label><span class=\"formw3\"><input  name=\"ToggleDivs\" type=\"radio\" value=\"Credit\" onClick=\"Toggle('Div2')\" id=\"Div22\" ></span>&nbsp;
           <label for=\"EasyPay\">EasyPay</label><span class=\"formw3\"><input  name=\"ToggleDivs\" type=\"radio\" value=\"EasyPay\" onClick=\"Toggle('Div3')\" id=\"Div33\"></span></div><br>\n");
      print ("<div id=\"Div1\" style=\"display:none;\"><br>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Credit Card Type:</span><span class =\"formw3\"><select name=\"selectCCType\">&nbsp;");
      foreach ($CCList_array as $ctype2)
      {
      print("<option>" . $ctype2 . "</option>");
      }
      print ("</select></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Name on Card:</span><span class=\"formw2\"><input name=\"textCCName\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Credit Card Number:</span><span class=\"formw2\"><input name=\"textCCNumber\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Expiration Month and Year:</span><span class =\"formw3\"><select name=\"selectCCExpMonth\">");
      foreach ($ExpMonth_array as $ctype3)
      {
      print("<option>" . $ctype3 . "</option>");
      }
      print ("</select></span>\&nbsp;");
         
      print ("<span class =\"formw3\"><select name=\"selectCCType\">");
      foreach ($ExpYear_array as $ctype4)
      {
      print ("<option>" . $ctype4 . "</option>");
      }
      print ("</select></span></div></div>\n");
       //Payment Types - Check//
       print ("<div id=\"Div2\" style=\"display:none;\"><br>\n");         
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Name on Check:</span><span class=\"formw2\"><input name=\"textCHName\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Check Number:</span><span class=\"formw2\"><input name=\"textCHNumber\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Account Number:</span><span class=\"formw2\"><input name=\"textCHAccountNum\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Routing Number:</span><span class=\"formw2\"><input name=\"textCHRouting\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Bank Name:</span><span class=\"formw2\"><input name=\"textCHBank\" /></span></div>\n");
      print ("<div class=\"row\"><span class=\"label\"><span class=\"asterisk\">*</span>Payment Date:</span><span class=\"formw2\"><input name=\"textCHDate\" /></span></div></div><br>\n");
tech_angel420
 
Posts: 27
Joined: Thu Dec 16, 2004 4:02 pm

Postby tech_angel420 on Mon Jan 03, 2005 3:41 pm

lol... holy cow.. I didn't realize I'd copied over so much.. lol sorry.
tech_angel420
 
Posts: 27
Joined: Thu Dec 16, 2004 4:02 pm

Postby webmaster on Mon Jan 03, 2005 10:11 pm

Press edit in that post and change the code.
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Next

Who is online

Users browsing this forum: No registered users and 0 guests