#1 (permalink)  
Old 07-12-2006, 01:12 AM
Registered User
 
Join Date: Jun 2006
Posts: 10
A Function for a PHP Form Validating

I am trying to write a form validating script and have most of the functions figured out. I have a couple where I want the opportunity to leave it blank, but, if they choose to fill it in, I want it to meet certain requirements.

Example. The field can be left blank, but, if they put anything in the field, it must be in the form of a email address. (I know how the format for an email is

function checkEmail($email) { //Check Email Format
$pattern = "/^[A-z0-9\._-]+"
. "@"
. "[A-z0-9][A-z0-9-]*"
. "(\.[A-z0-9_-]+)*"
. "\.([A-z]{2,6})$/";
return preg_match ($pattern, $email);

but how do I add that it can be blank also.

The same thing except it would be in a dollar value, but could be blank.

Thanks,

Ken
Reply With Quote

  #2 (permalink)  
Old 07-12-2006, 09:04 AM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,437
Quote:
Originally Posted by kenwvs
but how do I add that it can be blank also.
Put that code within an IF statement that looks something like:

Code:
if($email != "" && isset($email)) {

}
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote
  #3 (permalink)  
Old 07-12-2006, 01:23 PM
Till's Avatar
Administrator
 
Join Date: Jan 2002
Location: Berlin, Germany
Posts: 1,453
Quote:
Originally Posted by curtiss
Put that code within an IF statement that looks something like:

PHP Code:
if($email != "" && isset($email)) {


Rather use empty() with strings.
Reply With Quote
  #4 (permalink)  
Old 07-12-2006, 01:33 PM
Registered User
 
Join Date: Jun 2006
Posts: 10
More functions...

Thank You, that makes sense.... I actaully hadn't tried to solve that one so the timing was perfect.

What about an if....... If a different field (drop box) is auction or dutch auction then must be filled with a dollar amount, but if it is a fixed price or classified it must be left empty

Thanks,

Ken
Reply With Quote
  #5 (permalink)  
Old 07-12-2006, 05:07 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,437
Quote:
Originally Posted by Till
Rather use empty() with strings.
The problem with that is that any time a form is submitted, if the form field is empty, it stores the value of that variable as "", rather than storing it as NULL, so it won't return as empty, unfortunately.

Unless there's some other way to submit forms without storing blank values in the form's variables.
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote
  #6 (permalink)  
Old 07-12-2006, 05:13 PM
Registered User
 
Join Date: Jun 2006
Posts: 10
So, right now with no validation, if I leave that field empty, it will store it as "". This works fine. So can I make a function that it can be either a dollar amount or "" and stipulate that if a different field is auction of dutch auction it is "" and if anything else a dollar amount is required> I have a function for a dollar amount, well, actually it is a field that will only allow numbers and period (I don't know how to make it a dollar amount.)

If easier for you to understand, I can copy and paste the code that I have.......although it isn't working properly yet, and I don't know why.

Ken
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending a form, not just the results by email kenwvs Programming and Scripting 1 06-29-2006 05:46 PM
Setting Values For Form Elements With Unconventional Names curtiss Programming and Scripting 2 06-04-2006 09:28 PM
Obtaining a Form Elements Index by Name curtiss Programming and Scripting 3 05-02-2006 11:25 AM
passing information from 1 form to another amanxman Programming and Scripting 3 04-12-2006 04:59 PM
Form and javascript function help - illiterate on this ruthann Programming and Scripting 1 09-11-2005 10:52 AM


All times are GMT -5. The time now is 06:37 AM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter