Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Form Validation


I wrote the following form so that if a user leaves a field blank the page will not process and instead be re-loaded with a red error message asking the user to enter the missing information: Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Form Validation...
you would need to use Javascript for form validation, since the form is client side, PHP doesn't have the capabilities for validating forms to the extremes you'd need.

it isn't all that difficult really, how well do you know Javascript?. if not well enough, contact me and i'll see what i can do.

Form Validation
Rather than individually access all the $_POST vars individually, I want to try and create a smart script, thats loops through all the fields and performs the neccesary checks. The problems being, depending on what var is being checked there will be different procedures, for example

email
username
password etc etc

Also, not all fields may be required, but some will be. How would you do this with a loop?
Would you use a reg exp on the name of the var to determine what check to perform?

So if it contained 'email' perform email check.
If it contained 'pass' do the password check.
If it contained 'numbers and letters' do the relevant check.

Form Validation - A Better Way?
I have a form to process in PHP, and I want to validate all the fields. only way that I can think of is use a if statement for each field, is there a better way than this? at the moment my code is just swamped with if statements...

Form Validation - How Can I Do This?
Can someone suggest a method or point me in the right direction for validating a simple form using php.

I have a form which only has two significant fields - a drop down with three choices, and a dropdown with five choices - and I want the user to have chosen the correct value from the first dropdown before allowing the form to be submitted : ideally, on choosing the incorrect value, the page will display "incorrect please try again" or something along those lines.

the form is like this :

Form Validation
Slowly I'm getting this figured out. Now I have the error messages going where i want them to but I cant figure out how to combine validation for different fields. The form due to how I now have it set up as error_msg, error_msg1 and error_msg2 will only reject the form if one field is not filled in. I tried to use the pipe to combine them but had no luck. Will i have to set a different complete validation for each field. Or can i use an array (error_msg = 'error messager here' error_msg1 = 'error message one here') somthing like that
Can you use multiple words in an array? Everything i see on line and in my books show one word one=two sort of This is the code I now have ...

Form Validation
Many people often ask the question related to form validation. Here is
my style. It just gives the idea; but not exactly what I do in
development.

<?php
//usually header...
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Form Validation</TITLE>
<META http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<STYLE type="text/css">
<!--
p, input,select, table {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
}
-->
</STYLE>
</HEAD>
<BODY>
<?php
$tst_form = new TestForm();
if ($_POST) //form posted?
{
$tst_form->validateFormInputs($_POST); //extract inputs
if ($tst_form->isValidInputs()).......

Form Validation
I am sure this subject has been done to death, but I would like to make
sure that a form post is an interger or a float.

I have used

if (!ctype_digit($current_value)

but this is true if the number contains a decimal point.

I probably need a good tutorial/guide on form validation.

[php] Form Validation
I have a page now wich contains a form below that form are a couple of tables wich contain some data from the db. With the form you can add new stuff to that db. What I wanna do is make the form do self submit (no prob here)

But now Im stuck with the way the script is going to work I want to validate the form and report back in text (on the same page) which fields were missing. If eerything is ok insert into db and just show the page.

Form Validation
I have been using JS for my form validation needs upto now but I have been noticing more and more problems with relying on this. Therefore I am now in the process of changing all this over to PHP, unfortunately I am stuck on how to check that the username field contains no spaces and that it is no longer than ten characters.

Form Validation
I need to validate the
following fields using php.

1. email (needs to be just one e-mail address, and take out stuff like
bcc or anything that would be used for e-mail injection vulnerability)
2. Phone number (has to be in the format 555-5555)
3. Phone number area code (has to be limited to 3 characters)
4. Address has to be stripped of all illegal characters like slashes,
special characters etc

Another thing is I don't want people to be able to leave any of the
fields blank.

Where does the validation code go?

After this statement?

if($REQUEST_METHOD=="POST") or before?

I have tried a few things, but I am not sure what most people use,

Form Validation
I am having a break down in the "how to turn the page process. If a html form has the action attribute set to itself when the form is sumitted it validates (or not) then how does one get to the next page.

I have a hidden variable - $validated but am a loss where to go with it. My code so far is based on a really sorry book "Professional PHP Programming" and it glosses over or simply dismisses big fundamentals.

Form Validation
I am a newbie to PHP and finding even the simple stuff quite hard.

I am trying to validate an email address using a recursive page.

The validation is done using a regular expression which works fine , and the
valid/invalid messages shows as expected.

My input tag is as follows:
<input type="text" name="emailAddress" value="<?php
$HTTP_POST_VARS['emailAddress'] ?>">

When the page refreshes the input field is blank!

How do retain the value typed?

Form Validation
I am looking into form validation for my HTML form. I don't want to use
javascript and was looking into using PHP. A crazy thought crossed my
mind and I just wanted to get some input.

What if I basically made the form one long if/then statement? I could
ask for the first piece of information, test it against some
conditions, then if it is okay I allow the user to fill in the next
piece of information. I could go do down the page validation each box
as we go. I could use hidden on all the text boxes until the previous
condition had been validated. Some pseudocode:

<?php
<form action=POST method=registered.php>
<input name"Fname" type="text">
if ($Fname meets some condition)
{
<input name="Lname" type="text">
if ($Lname meets some condition)
{
<input name="Number" type="text>
if ($Number meets some condition)
{
}
}
}
else;
echo "Please enter a phone number";
else;
echo "Please enter a valid last name";
else;
echo "Please enter a valid first name";
?>

I know the code isn't exact, I am just theorizing here. Could such a
thing be done? Even remotely similar? I don't really plan on doing this
anytime soon, but I was just curious.

Form Validation
Ever get annoyed spending 90% of your time validating user input before processing/inserting into a database? I know I do. I was thinking of trying to write some framework that makes this process more generic and reusable. I'd also like to be able to share the same validation rules with javascript so that I don't have to write the logic twice. I was thinking define some sort of XML document with my validation rules and share that between PHP & Javascript but I see some limitations there as well.

So my questions to you, fellow PHPers, do you see merit in this idea? Is it reinventing the wheel... what might be some existing solutions or frameworks that would be worth looking into?

Form Validation
I have a login form (though this persists with all forms). On my login.php page, if I use this code:

if(isset($_POST['username'])){
'do whatever here';}

Once the form is submitted this always evaluates to true even if the field was left empty. I have used this:

if($_POST['username'] !==''){
'do whatever here'}

A single space in the field will make this evaluate to true thus username field is no longer blank, but nothing was entered. empty() gives the same results as !==''.

The only other way I can think of to ensure that something was entered is to use strlen() and make sure the fields are above a certain length. Does this sound plausible to anyone else, or is there a better way?

PHP Form Validation
I have an HTML for that I'm using to post data to a PHP validation script. I was then wondering if there is a way to pass the data from the post to another script without have the user to click submit on a form?

Form Validation
my httpd error_log keeps saying undefined index for each of the vars passed every time i try to submit. I can't find a syntax error in the code tho. Code:

Form Validation.
I am trying to validate a string for just numbers and letters... I can't seem to get it working. Not much of a fan of regex.. 0-9, A-Z, a-z

<?php

//This doesn't work....

if (eregi("/^[a-z0-9]+$/i", "test")) {
echo "Valid";}
else {
echo "Invalid";}?>

Form Validation
I have a registration form (the bulk of it anyway) and all validation passes and throws up errors if anything doesn't pass.

The last field is a text fiels so the user has to enter the captcha image and throws an error if they don't match.

What I would like to know is, is there a way i can store the passwords if they match along with everything else when the validation has failed on the captcha text.

It would be a pain for the user having to re-enter their password if they entered the wrong captcha text or is it common practice to leave them blank. Code:

Form Validation
I am having problems figuring out how to do a form validation using HTML and PHP. I create 2 radio buttons, 4 text boxes for name, email, password, and validation string. I then create some other stuff that isn't mandatory to fill out followed by a push button of type="submit".

When the user presses the Submit button, I want to notify them if they forget to fill out the name, email, or password, or if they forget to choose one of the radio buttons or if they type in an incorrect validation string. I do not know how to go about doing this if it is part of PHP or HTML. Code:

Form Validation With JS
I read somewhere that it's a not faster to validate forms by with the client side (JS) and that PHP form validation should be used as backup. So I found some JS code to validate the form. Now, how would I proceed to validate the form with PHP in the case that a user turns off JS?

Form Validation
I have a script that validates blank fields, and improper entrys. I want to validate a couple of the fields (middle_initial,fax_number)for improper data, however it would be ok for them to leave it blank.

Form Validation....
Im in the midst of creating a secure signin script which brings me to two questions I have.

1. I want to filter out blank spaces from the login and password fields. Im very unfamiliar with regular expressions, so I went out and found the below script on the web:

function no_specialchars($field1)
{
   if (!eregi("[a-zA-Z0-9]+",$field1))
   {
      $_SESSION['error'] = "The password or username fields should only contain alphanumerical characters or hyphens and underscores.";
      header('Location: reg_signin.html');
      exit();
    }
}

This function seems to do the trick when I try to signin with most special characters (although not all of them?!) and only spaces, however it still lets me pass when I put spaces before, in between or after the text string. What I want is to filter out any spaces and any special characters except for hyphens and underscores.

2. My second question would bring me to the handling of an error caught by the filter. Im using sessions where the session key 'error' is created once the filter finds a problem. This session data is then kept and displayed at the original signin form page. Is this the ideal way to do it or should I maybe put url variables to the redirect link such as header('Location: reg_signin.html?error=1'); and then read the user the error according to the error GET value?

Form Validation
Does anyone know anyway to put in additional php coding to validate list/menu in forms? I am currently using Dreamweaver, so I am using their Validation check in their Tags/Behaviour sections. I read in alot of places that this default function does not allow a validation check for list/menu. But I am wondering if anyone know of anyway to put in some additional coding so that it will allow it to validate the list/menu as well?

Form Validation
Does anyone know if it is possible to validate form fields (i.e. make sure certain sections ae filled in) with php?

If it is can anyone tell me how or where I can find out how?

Form Validation
I've writen the script and it all works now I want to do some validation to make sure the user enters a 'correct value', simple enough you might think, anyway what I have is 40 fields in my form which are sent to 5 different arrays for processing, so:

$q1 = $_POST['q1'];
$q2 = $_POST['q2'];
$q3 = $_POST['q3'];
//.......
//then
$typea = array( '1' => $q1 , '10' => $q10 , '11' => $q11 , ........ '40' => $q40);
//so now I want to validate...
$check = 0;
foreach ($typea as $key => $value)
{
if ($value != 0 || $value != 2 || $value != 3)
$check = 1;
echo $value . " , " . $check . "<br />
";  //to make sure values are what i think
}
if ($check == 1)
   //go back to form
else
   //do the processing

$check always returns as 1 though, even when the values are 0 , 2 or 3

Form Validation
I have a form that inserts data into a db via mysql. I want to validate the form to check people aren't inputting code to destroy my database and website. How can i go about this? Any good tutorials?

Form (Array) Validation
Okay i know i have been going on and on about this but its driving me nuts and i have confused a lot of people so i am going to paste code and comments. Hopefully ill get some help

I have been working on these couple of scripts for a while. The first one you enter the number of textfields to create to insert images to the table. That actual field is validated (this works!) then it passes that number to second script which creates and array according to that number it got (this works as well !).

Now before being able to submit the data finally (in page 2) i want to make sure that first there are no duplicates the fields are not empty (both dont work !). Some how with both or seperatley validations when i choose to submit i get the "Java Script Prompt" and when i click the OK button on the "prompt window" the page disappears !. Obviously when u (press back button) the fields disappear too since the arrays gone.

Form Validation With HTTP_GET_VAR [ ]
Hello, I am pretty new to PHP. I have set up this submit form which passes on many (around 30) variables, I want to make sure that all the forms are filled out and none of them are empty. Is there any way that I can use HTTP_GET_VARS [] so if any of the variables passed on are empty then the user will have to fill out the form again.

Form Validation- One Of Three Fields
I've been looking for a PHP script to accept a search form for either the name or town or postcode fields to search a MySQL db. I would like the user to put in any one search field but not none.

Also I am trying to figure out a select statment to select one item on a drop down form list or any item on the list eg the list would be dog, cat, horse, fish or all, the column would be pets. The search would pull out any single pet or all pets.

Form Validation Problem
I am using form validations for different fields.
One of them for City as -

if(($_GET['app_city']) == ''){
$cityError = "Invalid or missing city";
$error++; }
else
{
$app_city = trim(stripcslashes($_GET['app_city'])) ;

If I typed City as - "My City",

If the validation fails, it shows City as - "My" instead.
Does not consider both the words.

Validation After Form Submitting..
Basically, im redesigning a form page on our website.

Currently the user submits the form, it does a few javascript checks
and either submits to the "processstuff.php" page, or gives the user a
JS error message.. where they have to go back and fill the details in.

Im trying to optimise and make this form/page as best as it can be.

Do you think it would be a better idea to continue using JS or use JS
then submit to the php page(where it checks some other details(postcode
validation) and submits, or just solely use php validation?

Form Validation And Setcookie
Is there a statement that allows for redirection to an entirely different page?

What Im trying to do is have my script load a new page with SetCookie("UnderAge", "", Time()+3600); if a person enters an age under 13 years. On the main form page it would check for cookie(Underage) to deny them acces for an hour if set. Right now it simply echos "You must be at least 13 years of age to participate, you are not eligible." PHP Code:

Asking For Help With Captcha And Form Validation
I'd like to use a captcha form validation on my web form, but I'm not sure if I'll be able to with my current set up.

I have a form, which when submitted, 'posts' the data to a cgi script (formmail) and then redirects the user to a thank-you page.

However, a php captcha seems to do everything within one php file - you hit submit and it reloads the php file while validating the captcha. Is there a way to get a script to validate the captcha and if valid, send the data to the cgi script and then redirect the user to the thank you page?

PHP Form To Email With Validation
I have form that once you have pressed the submit button will validate 3 * fields to check if they have been entered in correctly. If the have errors it will not process the form to email and instead display the errors and tell the user to amend the error fields before it can be processed.

My problem is that i have tested the validation and works to a certain standard my only PROBLEM is that if there is an error in the form it wipes the whole form clear so ultimately the user will lose everything they have entered.

I do not want this happening, much like other forms on websites i have used it still displays the form as you entered it and so you can ammend the error fields and start again making sure everything is correct and processed properly. PHP Code:

Form Validation With PHP/Javascript
I have a form for uploading documents and inserting the data into a mysql
db. I would like to validate the form. I have tried a couple of Javascript
form validation functions, but it appears that the data goes straight to the
processing page, rather than the javascript seeing if data is missing and
popping up an alert. I thought it may be because much of the form is
populated with data from the db (lists, etc.), but when I leave out data in
a simple textbox, it still doesn't see it. I've tried a couple of different
things, that didn't work, so I simplified and tried to address one form
element at the simplest level at a time - still no luck. Is there something
special I need to do to make the Javascript work before the PHP? Is there a
good way to do client side validation with PHP?

Here's most of the code:

function ValidateForm(upload)
{
if(IsEmpty(upload.title))
{
alert('You have not entered a title!')
form.title.focus();
return false;
}

return true;

}
</script>
<?php
NOTE: queries are here - they fill some of the list boxes

<form enctype="multipart/form-data" action="upload.php" name="upload"
id="upload" method="post" onsubmit="javascript:return ValidateForm(upload)">
<input name="uploadfile" type="hidden" value="uploadfile" />
<!--//Create the file and description inputs. -->

<table width="100%" border="0" cellspacing="5" cellpadding="0">
<snip - took out a different category listing>
<tr>
<td <fieldset>
<legend><a name="Standard" id="Standard"></a>Standard Document</legend>
<br />Complete this section <strong>only</strongif document/link is NOT
a Tool.<br /><br />
<snip - took out the generated category/subcategory lists>
</td>
</tr>
<tr>
<td><fieldset>
<legend>Document Information</legend>
<strong>Document Title</strong>:
<input name="title" id="title" type="text" size="40"
maxlength="50" />
<br />
(Required - no more than 50 characters)<br />
<br />
<strong>Description:</strong>(Required -150 characters) <br />
<textarea name="description" cols="30" rows="5"></textarea>
<br />

</fieldset></td>
<td><fieldset>
<legend>Project Data</legend>
</p>
<strong>Primary Project:</strong>
<select name="project" id="project">
<option value="value">Select a project...</option>
<?php
do {
?>
<option value="<?php echo $row_projects['projID']?>"><?php echo
$row_projects['projCode']?></option>
<?php
} while ($row_projects = mysql_fetch_assoc($projects));
$rows = mysql_num_rows($projects);
if($rows 0) {
mysql_data_seek($projects, 0);
$row_projects = mysql_fetch_assoc($projects);
}
?>
</select>
</p>
<snip- took out another listbox>
</fieldset></td>
</tr>
<tr>
<td><fieldset>
<legend>Document to Upload</legend>Upload a document from your computer.
<p><strong>File:</strong>
<input type="file" name="fileupload" id="fileupload"/>
</p></fieldset></td>
<td></td>
</tr>
</table>
<p</p>
<div align="center">
<input type="submit" name="submit" value="Submit" />
</div>
</form>
<snip>
?>

Serverside Form Validation
I want to validate a form serverside. And I have no idea how to check the variables for different things...

-Check how many characters are in a variable.
-Check if the variable containes a spesific character.
-Check if the variable containes any alphabetic character. This variable is puposed to only contain numbers...

Form Validation Query
I have a form on my website
(http://www.nprie.info/content.php?pn=12&frm=3~4). When the user
submits the form various validation checks are completed by another PHP
script. If any of these fail, the user is redirected back to the form.
The content that they submitted is retained and sent back in the URL
and picked up by another script and inserted into the fields.

My problem is with memo fields as this method of returning the data
seems to chop off anything after the first newline or carriage return.

I presume it would be better to POST this information back but how do I
do this from PHP without a SUBMIT button?

Hope all that makes sense - see the website which should clarify the
process.

p.s. the &frm=3~4 in the link simply ensures that my name appears in
the
"TO" box so if you test the script spurious messages don't go to my
colleagues.

Form Validation With JavaScript
I'm looking for an example of form validation by JavaScript before it's
processed by a PHP script.

Form Validation & Redirection
i'm making a form validation script that once it checks all the info is correct passes the visitor onto the next page. But i seem to be getting 'header already sent' problem. Here is teh general script i am using. PHP Code:

Form Validation (revisited)
I am 99% of the way there but now cannot get the "Reset" button to work.

I have included the whole of my code and would appreciate it if someone
could explain where I am going wrong.

<?php
$message="";
if (isset($HTTP_POST_VARS['submit']))
{

$re =
"^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.([a-z]){2,3})$" ;

if (eregi($re,$HTTP_POST_VARS['emailAddress'])){
$a = true;
$message = "<font color="green"><b>Hooray - The email address you entered
was valid!</b></font>";
}else{
$a = false;
$message = "<font color="red"><b>It Sucks! - The email address you entered
was NOT valid. Please try again!</b></font>";
}

}else{
$HTTP_POST_VARS['emailAddress']="Enter Here";
$HTTP_POST_VARS['submit']= false;
}
?>

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- Creation date: 05/02/2004 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="Institute of Criminology" />
<meta name="generator" content="AceHTML 5 Pro" />
</head>
<body>

Form Validation Script
i'm just writing a small script about how you can validate a form using php.This question i use to get daily in my inbox.so i thought ,i should post this script in Devshed.this may
be helpful for new comers. My html page consisting of a form.and i want to validate all the fields of that form.i have three input field in that form(name,email,address). Code:

Automated Form Validation?
after coding for days on stupid form validations -
Like:
strings (min / max length), numbers(min / max value), money(min / max
value), postcodes(min / max value), telefon numbers,
email adresses and so on.

I thought it might be a better way to programm an automated, dynamic
form validation that works for all kinds of fields, shows the
necessary error messages and highlights the coresponding form fields.

Before I start to reinvent the wheel I thought I should ask you guys
if someone has done this before, or if there are some good examples of
how to do this on the web?

Some Form Validation Directions
I m trying to create a server side form validation with php. The idea is to send the user's  input to an errors.php that checks the integrity of input and then store it to a database, if i m not wrong. There are  many errors here so if someone can look at the code and point  some basic instructions  on what i m doing wrong with my functions?

My Form [hr]<form action="errors.php" method="post" name="Errors" onreset="return confirm('Do you want to reset the form?')" >



   

<h2>&nbsp;Create a User Account:<br></h2>
&nbsp;

<fieldset>
<legend>Personal Info</legend>
<table border="0">
<tr >
<th><label for="Username">*Username</label></th>

<td><input type="text" name="username" id="Username" value="" maxlength="15" class="Username" ></td>
<tr >
<th><label for="Name">*Name</label></th>

<td><input type="text" name="name" id="Name" value="" maxlength="15" class="First Name" ></td>
</tr>
<tr >
<th><label for="Surname">*Surname</label></th>

<td><input type="text" name="surname" id="Surname" value="" maxlength="20" class="Surname" ></td>
</tr>
<tr>
<th><label for="password">*Password</label></th>

<td><input type="password" name="password" id="password"   maxlength="15" class="password" ></td>
</tr>
<tr>
<th><label for="password2">*Confirm Pass.</label></th>

<td><input type="password" name="Password2" id="password2"  maxlength="15" class="password" ></td>
</tr>
</table>
</fieldset>

    <fieldset>
<legend>Contact Details</legend>
<table  border="0">
<tr>
<th><label for="email">*Email&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label></th>

<td><input type="text" name="email" id="email"  maxlength="25" class="email" ></td>
</tr>
<tr>
<th><label for="Phone">Phone&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label></th>

<td><input type="text" name="phone" id="Phone"  maxlength="10" class="phone" ></td>
</tr>
</table>
    </fieldset>


                <fieldset>
<legend>Postal Address</legend>

<table border="0">
<tr>
<th><label for="Town">*Town</label></th>

<td><input type="text" name="town" id="Town" value="" maxlength="20" class="town" ></td>
</tr>

<tr>
<th><label for="Address">*Address</label></th>

<td><input type="text" name="address" id="Address" value="" maxlength="30" class="address" ></td>
</tr>

<tr>
<th><label for="PostCode">*PostCode</label></th>

<td><input type="text" name="postCode" id="PostCode" value="" maxlength="8" class="Post Code" ></td>
</tr>


</table>

<input  id="submit" type="submit" value="Sign Up">
<input  id="reset"  type="reset"  value="Reset">

</fieldset>

</form>

And my errors.php[hr]<?php
extract($_POST);
/* Validation */
/*USername*/
function checkUsername($username)
{
  if(!preg_match("/[^a-zA-Z0-9.-ÄäÖöÜü
   ]+$/s",$username))
    return TRUE;
  else
    return FALSE;
}
/*Name*/
function checkName($name)
{
  if(!preg_match("/[^a-zA-ZÄäÖöÜü
   ]+$/s",$name))
    return TRUE;
  else
    return FALSE;
}
/*Surname*/
function checkSurname($surname)
{
  if(!preg_match("/[^a-zA-ZÄäÖöÜü
   ]+$/s",$surname))
    return TRUE;
  else
    return FALSE;
}
/*Password*/
function checkPassword($password) {
  $length = strlen ($password);
  if ($length &lt; 8) {
    return FALSE;
  }
  $unique = strlen (count_chars ($password, 3));
  $difference = $unique / $length;
  echo $difference;
  if ($difference &lt; .60) {
    return FALSE;
  }
  return preg_match ("/[A-z]+[0-9]+[A-z]+/", $password);
}
/*Email*/
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);
}
/*Phone*/
function checkPhone($phone)
{
  if(!preg_match("/[^0-9 ]+$/",$phone))
    return TRUE;
  else
    return FALSE;
}
/*Town*/
function checkTown($town)
{
  if(!preg_match("/[^a-zA-ZÄäÖöÜü
   ]+$/s",$town))
    return TRUE;
  else
    return FALSE;
}
/*Address*/
function checkAddress($address)
{
  if(!preg_match("/[^a-zA-Z0-9.-ÄäÖöÜü
   ]+$/s",$address))
    return TRUE;
  else
    return FALSE;
}
/*PostCode*/
function checkPostCode($postCode)
{
  if(!preg_match("/[^0-9]+$/ ",$postcode))
    return TRUE;
  else
    return FALSE;
}
/* Validation */

$error=0; // check up variable

/* get it checking */

if(!checkUsername($username))
{
  echo "Illegal input $username in 'Username'";
  $error++; // $error=$error+1;
}
if(!checkName($name))
{
  echo "Illegal input $name in 'Name'";
  $error++;
}
if(!checkSurname($surname))
{
  echo "Illegal input $surname in 'Surname'";
  $error++;
}
if(!checkPassword($password))
{
  echo "Illegal input $password in 'Password'";
  $error++;
}
if(!checkEmail($email))
{
  echo "Illegal input $email in 'Email'";
  $error++;
}
if(!checkPhone($phone))
{
  echo "Illegal input $phone in 'phone'";
  $error++;
}
if(!checkTown($town))
{
  echo "Illegal input $town in 'Town'";
  $error++;
}
if(!checkAddress($address))
{
  echo "Illegal input $address in 'Address'";
  $error++;
}
if(!checkPostCode($postcode))
{
  echo "Illegal input $postcode in 'PostCode'";
  $error++;
}

if($error == 0)
{
  echo
  "
  The data you entred was correct, thank you!<p>
  Your data:<br>
  Your Username: $username<br>
  Your Name: $name<br>
  Your Surname: $surname<br>
  Your Email: $email<br>
  Your Town: $town<br>
  Your Address: $address<br>
  Your phone: $phone<br>
  Your Post $postcode<br>
  ";
}else{
  echo "Number of errors: $error";
}

?>

Form, Checkbox Validation.
I have a list of products generated from mysql.In front of every item is a checkbox.I want only the selected items to be listed on the next page.How can I do this ? Code:

Form Validation Tips For All
I have read these forums a lot looking at posts and gaining a lot of information about PHP. I just want to give something back. When I begin writing code I always wonder if it's the most efficient way to write it, and if it is using proper semantics. So I purchased the PHP Cookbook http://www.oreilly.com/catalog/phpckbk/ and I wanted to share some of the code with you. All these code snippets have to do with form validation and processing because that is one of the most popular subjects of PHP. I don't want to rip off the book so I will post the code but try and write my own descriptions. Code:

Edit Form Validation
i have an edit form which as a validation code to check if the new parent category/subcategory is not yet existing in the database. apparently only my parent validation code is working, but my validation code for the subcategory is not working. Code:

Form Field Validation
When validating user input I check it's not empty and then run 'mysql_real_escape_string($s)', I was then going to make sure that it is only alphanumeric, but I wanted to allow certain other characters as well. Realising this must be done before the mysql escape check, what characters should be blocked because they are dangerous, I can only really think of quotes and $. The real escape check should handle the quotes issue, so is the $ an issue or not? 

Problem With Form Validation Before Inserting
I would like to validate this simple form, just to make sure the person fills out everything prior to inserting it into mysql. Problem is, the data is inserted but it prints the error indicating that the information wasn't filled in.

Ok, here is my form:

<html>
<body>
<table width=100><tr><td>
<form action=insert_submit.php method=GET>
Project Name<BR>
<input type=text name=project_name size=50 maxlength=50><BR><BR>
Project Description:<BR>
<textarea name=project_desc cols="75" rows="10"></textarea><BR><BR>
<input type=submit>
</td></tr>
</table>
</body>
</html>

It is submitted to this:

<html>
<body>
<?php
(project_name,project_desc) VALUES ('$project_name','$project_desc')");
if (ereg(".", $project__name) == 1)
{
mysql_connect (neon, root, glider);
mysql_select_db (projects);
mysql_query ("INSERT INTO projects (project_name,project_desc) VALUES ('$project_name','$project_desc')");
print ("The project has been submitted.")
}
else
{
print ("Error: A project name is required.");
}
?>
</body>
</html>

Any suggestions are appreciated!


Copyright © 2005-08 www.BigResource.com, All rights reserved