Re: php Form Validation help

From: Date: Tue, 07 Sep 2004 13:08:20 +0000
Subject: Re: php Form Validation help
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-36089@lists.php.net to get a copy of this message
At 11:09 07/09/2004 +0000, you wrote:
From: "Vincent Jordan" <vjordan@extendedpop.com> To: <php-db@lists.php.net> Date: Mon, 6 Sep 2004 19:20:16 -0400 MIME-Version: 1.0 Content-Type: multipart/alternative;
        boundary="----=_NextPart_000_0004_01C49446.8C688C60"
Subject: php Form Validation help have a form that I would like to validate before it is submitted to the DB. I am having trouble with a couple of sections. I have a select box with a listing of all the states, the first option is "Choose One" with a value of "0". Would this be the correct way to "validate" this field?
if ($_POST["state"]==0) {
//      Display error message that no state is selected
        print '<p>Please select your State</p>';
}
Second, another part of the same form I have fields for phone numbers, once the field is submitted I would like to join the 3 sections of areacode, nxx and prefix. I have done this to join them, is this correct?
Almost there : Put quotes around parts of your output that aren't variables (ie quote literal text strings) $phone = $_POST['p-areacode'] . "-" . $_POST['p-prefix']. "-" .$_POST['p-suffix'];
The next question id for both phone number and area code. If I want to validate the zip code and ensure a minimum of X characters in the field, numbers only how would I do this?
if (strlen($zip_str) < 5) {
        print '<p>Please enter your Zip Code (EX. 77662)</p>';
} HTH Cheers - Neil

« previous php.db (#36089) next »