Developer Support »

Validate user input to check for letters in numbers  (See more user questions)

Hi

Here's some fiddling material!

if(!is_numeric($_REQUEST['age'])){$errors[] = "Age must be a numeric
value";}

if(!is_numeric($_REQUEST['phone'])){$errors[] = "Phone number must be a
numeric value";}

if(strlen($_REQUEST['phone']) != 10){$errors[] = "Phone number must be ten
digits long";}

You can put those lines in the script, pretty much anywhere (you can use
one, some or all of them) so long as it's before the code that prints the
errors. Replace 'age' and 'phone' with the exact name of the form field.
You can change the error messages (between the quotes) to suit.

Just thinking, one option for the age input could be to use a drop-down
<select> input with a list of numbers from 1??? to 100???!! That way, if
submitted from the form, the value will always be numeric.

Any questions, just let me know.

Best wishes.

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----
Sent: Tuesday, March 10, 2009 10:26 PM
Subject: Re: Fw: FormToEmail-Pro Script


Thanks, Charles. I understand completely about the custom
validation...can't do it for everyone. Would you possibly have an
example for me to fiddle with? I'm pretty good at figuring things out.
I used to do a lot of programming years ago, so most of the logic of
PHP make sense to me, I've just never studied PHP specifically.

Also, regarding my email address, I'm not sure why you're getting an
error. I haven't had anyone else experience a problem...however I have
confirmed that I'm not getting yours through my wenzelcomputer account
when you copy me at that address...so I'm not sure what's going on.
I'll remember to use my other address if I need to email you further.

Thanks again!

On Tue, Mar 10, 2009 at 3:14 PM, FormToEmail.com
wrote:
> Good stuff,
>
> Yes, the validation can be done, but it needs to be done on a case-by-case
> basis. I don't offer validation because with thousands of users/customers,
> requirements could vary hugely.
>
> Leave it with me for now, I'll see what I can do.
>
> (I am copying this to as I get an error on
> .com . I am remembering to do this from previous emails
> but if you contact me at a future time I will doubtlessley forget to do
> so!)
>
> Best wishes.
>
> Charles Sweeney
> https://formtoemail.com
> The world's easiest feedback script!
>
> ----- Original Message -----
> Sent: Tuesday, March 10, 2009 7:38 PM
> Subject: Re: Fw: FormToEmail-Pro Script
>
>
> Charles, your help is very appreciated, that code worked like a charm!
>
> One last (I hope) question...is there a way to validated a specific
> field's input to fit a particular requirement? For example, if I have
> a field named "age", can it validate that a number is typed in that
> field rather than a letter. Similarly if I have a "phone" field, can
> it be checked that the visitor entered exactly 10 digits and no
> letters or other characters?