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




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:




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

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:

Increment A Text Field In A Form
I am creating an intranet which shows active projects and allows people to add new projects. If users want to add a new project, they fill in a form but what I want the form to display in the ProjectNumber field (which is a var char field & not the primarykey) is the last Job Number incremented by 1.

For example if the last ProjectNumber was TS0014, then the default value in the ProjectNumber field should be TS0015 - this way users know what the next job number is.
At present, the last job number in my table is TS0014. Below is the code i'm using but for some reason in the Job Number field in the form Im getting TS001? WHY? Code:

Form Field Text Output
How can I get html code in an editable form field to display properly? Specifically: I have text that is echoed to a form field via <? echo $text ?>

The user can then edit that text and submit. However <BR> is showing up as a literal <BR> and should be a linefeed. Is there a way to have this display properly?

Example: LINE ONE<BR>LINE TWO
should display as
LINE ONE
LINE TWO

Note that this is only a problem in the form field. It displays properly when echoed outside of the form.

How To Get Un-escaped Text From A Form Field
I have a php script that gets the text from a form field:

<?php

include("global.inc.php");

pt_register( 'POST', 'test1');
echo $test1;

?>

The text comes back fine, just some characters (', " and ) are now escaped
(', " and ). The problem is that I need the he text to be exactly as it
was entered by the user. I could process the text myself, and replace the
escaped characters, but I'd like first to understand why this is happening
and if there is a way to disable this behavior and get the unmodified text
directly.

Formatting The Contents Of A Text Area Form Field
On my site I get users to enter a load of information in a textarea
box, however when i save this data to my mysql DB and then retrieve it,
it comes out without all the formatting, like new paragraphs and new
lines.

Can anyone tell me how you can capture the data entered into such a
field with all the formatting the user has entered like new paragraphs
etc?

Clearing The Input Text Field After Submiting The Form To A New Page
I have a page with a form with an input text field ... and when a user types his/hers ID ... and submits the form - his/hers page opens in a NEW window .... but the value (ID) that was written in the original window remains.

I want to make sure that the form input field on the original page becomes "invisible" - by refreshing/reloading the original page or just by clearing the input form after submission.

For now I have put in a meta refresh tag in the head of the html file ... but that is not the solution ... becouse I only need a one time refresh/reload of the page ... and this is to happen right after the input text value is being submitted.

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:

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:

Quickly Adding Text To A Mysql Text Field That Is NOT Empty
Is there a way to insert text into a mysql text field that already has
text into it; without having first to extract the existing data and
append the new text to that string variable and then insert the new
string.

Basically i'm looking for a way to do it with a single query not 2 (one
being a select to gather existing data).

Text Returned From DB Gets Cutoff When Placed In A Text Field
I have a string that contains an apostrophe or a quotation mark, stored in a DB. I can retrieve the data, and display it properly (for editing) in a textarea, but when I try to put the string in a text field, it get's cut off right before the questionable character.

For example:
$string_in_database = "John's car."

 -displays correctly here <textarea><?php print $string_in_database ?></textarea> and displays this - John's car.

 -gets cutoff here <input type='text' value=''<?php print $string_in_database ?>' /> and displays this -  John

I've tried adding slashes and stripping slashes and I just can't figure out what I need to do.

Text Validation
We want to allow users enter text, numbers, HTML, and quotes (basically any input) and the system should handle the input gracefully. A few questions:
1) Magic quotes is ON - is that all we need ?

2) or do we need to create a regular expression (eregi)

3) If we use eregi - Is it better to replace double quotes in narrative text with (") or (&quot;)

4) Does anyone know of a good article relating to validating text input using php - or a code snippet that could validate this type of text?

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.

Validate Text Field
This is very simple in javascript but I can't seem to find the exact solution in php. I have searched the forum but couldn't find my exact example.

I have "page1.php" with a <form> that includes one text field and a submit button. Once submitted the data in the text field would be entered into the DB. I want to make sure that before the <form> is submitted that there has been some data entered into the text field. I have seen the function --- empty() and I have also seen if (!$textfieldName)
all coupled with <? PHP_SELF ?> in the action field of the <form> but it just doesn't seem to work for me.

I think that it doesn't work because the page that I am entering data in the text field is also inserting data to the DB from a previous page and the <? PHP_SELF ?> is conflicting with this----(Just speculating).....I don't know I am kinda stumped.

Text Field Variable
I'm new trying to use php forms.  Trying to write what is typed into the text field to a file.  But its not working.  It makes the file, but the text field data is not written. Code:

Mysql Text Field
I have a DB with a column that is set as Text format. The data stored in the field will be stored in many lines. When I get the data from the DB I want it to display where the line breaks are I'm not sure how to write the script to do this. I have worked withe explode before but there is nothing come at the end of each line to do this with.

How To Query In A Text Field
can i query in a text field, i have the normal fulltext search but i want to or substr search it or something, but i dont know how.

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?

Validating TEXT Field Entires
Because I have several TEXT fields in my MySQL database, I need to know how to validate that only alphanumeric characters have been entered -- as this data will be echoed back to the user upon completion of the form.

Therefore, I need to prevent any malicious text from being entered into the form (SSIs, HTML formatting, etc.)

Is there any way to do this?

So far, I've only been referred to addslashes(). I've managed to use the following function:

function validate_text($text) {
$text = addslashes($text);
return ($text); }
$input_text = validate_text($input text);

But this only escapes single and double quotes with the slash. URLs, SSI statements, etc. remain untouched.

TEXT Or BLOB Field Problems
When I use a form and php to input long articles (in a TEXT field) into a mysql table, the code runs smoothly (i get a thank you message). However, the record isnt always put into the table.

If I input only the varchar fields into the form, then it works. But if I also try to append the TEXT field then it doesn't work from a web form. It works sometimes but not all fo the time.

Why does this only work sometimes, do i have to do something witht he code? change the database?


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