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




Form Field *required* Validation


I have php form I'm trying to edit. Some of the fields on this form is required, and some aren't. I want to adjust it so none of the field is required.  But I am not able to find the place to set this value.

Following are 2 piece of the code for 2 fields, 1 is required and 2nd is optional. Please help me determin where I might be able to adjust the validation. Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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? 

Form Text Field Validation
I've got a form and I'm now trying to validate the text fields in it. The field I want to validate is for someones name, so there should only contain letters. Below is the function I've written to handle this. Code:

How To Update Form Input Field Background Colour On Validation Error
I have been searching for form validation scripts for ages and all th ones that I like are far too complicated and inflexible so I decided to stick with my own which is easier to understand.

The only thing I don't like which i have seen on better form validation scripts is that and fields with errors are highlighted.  i can only presume that they have used php to set the background color of the input field or textarea.

How would I add some code to change the background colour of form elements if an error is found? Here is my code which validates the form but doesn't change form elements colours. Code:

Required Field Script
Can someone please help me out with my script? I would like to make the 'email' and/or 'name' field required. If it is not filled in I would like it to display an error message but, if it is filled in correctly I would like it to redirect to "thankyou.html". Can anyone help me out? Below I have pasted my current script.

<?
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$message = $_POST['message'];
$quote = $_POST['quote'];
$question = $_POST['question'];
mail("myemail@mydomain.com", "Website Inquiry",
"Quote: $quoteQuestion: $question
$message
", "From: $name <$email>" );
header("Location: /thankyou.html" );
?>

How Can I Make A Field Not Required
I have a php form that links up to an Access database where all of the fields are required and one of the fields asks for a date for females only. I can't figure out how to not require a value for this date field (first_day) if the person entering the form is male. I also don't want to have to put in a real date for a value if the person filling out the form is male, because then that means we have inaccurate data in the database. Here is some of the code I'm working with. Code:

Building Required Field Sets.
I have been writing Perl for quite a long time, and am new to PHP, most of my questions are going to be about functionals while I transition between the languages. I am curious about building required field check routines, Naturally I can swing in the ereg_ functions of PHP.

Anyone have pointers on how they approach making sure the user actually fills in the blanks for fields that are "NOT NULL" in the mysql database? And lastly, what's the best approach of returning the user back to their form with the "un-submitted" data still in the fields?

How Do You Access An Array In An Included/required Field?
I have a large array that would be messy to include in the file "main.php"
itself and would prefer to include/require it. Say I have the following
line in "main.php":

require_once('/arr.php');

And the "arr.php" file looks something like this:

<?php
array(1)='ok1@Ok.com'
array(2)='ok2@Ok.com'
array(3)='ok3@Ok.com'
array(4)='ok4@Ok.com'
array(5)='ok5@Ok.com'
array(6)='ok6@Ok.com'
array(7)='ok7@Ok.com'
array(8)='ok8@Ok.com'
array(9)='ok9@Ok.com'
array(10)='ok10@Ok.com'
?>

Would I be able to reference the array AS IF I had declared the array in
"main.php"?

Checking For Required Form Fields
i have written the script to check for blank form fields (all fields are required)
on my registration form using :

if (ereg(".", $first) == 1){
$verify = "OK";}
else{
print ("<b>ERROR:</b> A first name is required.");
$verify = "bad";}

my question is, although this script works to verify a form field, it doesnt prevent the incomplete form from being sent to the database. can someone tell me how to stop the form from being sent if it is incomplete, and should this script be included on the form page(html page) or the php page that submits the data to mysql?

Decimal Field Validation
What is the best way to validate that the decimal field is filled with the properly data in a form? I have a field that ask the user to enter a price quote. I do not want letters or symbols allowed.

Drop Down Field Validation
i am working on a page where office staff enters info on scheduling a doctor for on-call duty. the page has info like  date, shift, Doctors name(Provider) and Location fields and a Add button.

staff selects the date from the calendar, selects a shift from the drop-down, selects a Provider and Location from the drop-down boxes.

When page loads, shift drop-down box defaults to the first value(Shift 1) and Provider and Location fields are defaulted to blank. These fields are to be made mandatory. i am trying what i did on othre screens and it doesnt seem to work here. if i hit the Add button without choosing values for these two fields(just leaving them blank) all validations are skipped. Code:

Check Form For Required Details Before Mysql Insert
I'm making a script that will let the users of my site enter information into a form and then submit it to a database. I've created the database and set up an sql user account that's only allowed to insert to a specific table so that's all ok. The thing i'm having trouble with, is checking the required forms have been filled in. I don't need to do any reqular expression matches on any of the inputs, i just need to let the user know when they've missed out a required field and to stop the script if they haven't.

I know this could have tons of different methods, i'm after something basic that will give me an idea how to do it as a beginner.

Are there any turtorials or guides on the net that will give me the information i need? Oh, i'm aware the sql part of the code isn't complete. Please remember i'm somewhat of a php noob so go easy. Code:

File Field Validation $_FILES??
I have the following code that validates my form fields. I have a file field called file that I cant figure out how to validate. Code:

Add Form Field Values Into Php Seesion Variable Before Submitting The Form
I have php page which is basically a simple html form containing some text fields.The user will type in values in it and submit it .Now what i want is that just at the time of submittion i want to assign the form field values in session variables.

I nwwd this b'coz the form is being submitted into a cgi script which has been given to me.Now the cgi script is an executable one and i am unable to view or change its content,Its functionability is to change a password for a linux user account .Now the cgi script after completing the job is redirected to another html page.What i have to do is that i need to trap the user input and update the values in a mysql database .Now if i can assign the values in a session variable then i can do the updatation from some later pages.

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 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:

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:


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