some small help with PHP contact form

XoRaK

Regular Member
Joined
Oct 28, 2009
Messages
326
Reaction score
274
Hi guys

What should I change to the following code, to make the second part (= subject part) expect a url in the following form: http://www.XXX.com

I guess I should add a $string_exp = like in the first part (the name part) but I don't know how to do it exactly...
Can someone please help me, consider it your good deed for the day ;-)

PHP:
$string_exp = "/^[A-Za-z .'-]+$/";  
if(!preg_match($string_exp,$name)) {    
$error_message .= 'The First Name you entered does not appear to be valid.<br />';  
}   
if(!preg_match($string_exp,$subject)) {   
$error_message .= 'The url you entered does not appear to be valid.<br />';  
}

Thx!

XoRaK
 
noone? I'm paying 5$ for this simple thing... maybe that helps getting help ;-)
 
PHP:
$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($string_exp,$name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!filter_var($subject, FILTER_VALIDATE_URL,FILTER_FLAG_HOST_REQUIRED)) {
    $error_message .= 'The url you entered does not appear to be valid.<br />';
}

Try that.
 
do this type of processing on the client side, just to reduce load on server + the user may not frustate.. its a minimal thing but when things like this get together, they mean alot!!
 
do this type of processing on the client side, just to reduce load on server + the user may not frustate.. its a minimal thing but when things like this get together, they mean alot!!

NEVER put the validation on the clients side..
 
$url = "http://www.blackhatworld.com";
if (preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $url)) {
echo "URL is valid";
}
else {
echo "URL is invalid";
}

Hope this helps.
 
Hi guys

What should I change to the following code, to make the second part (= subject part) expect a url in the following form:
I guess I should add a $string_exp = like in the first part (the name part) but I don't know how to do it exactly...
Can someone please help me, consider it your good deed for the day ;-)

PHP:
$string_exp = "/^[A-Za-z .'-]+$/";  
if(!preg_match($string_exp,$name)) {    
$error_message .= 'The First Name you entered does not appear to be valid.<br />';  
}   
if(!preg_match($string_exp,$subject)) {   
$error_message .= 'The url you entered does not appear to be valid.<br />';  
}

Thx!

XoRaK

try to user javascript to make it validation.

or you can example script from lightning37 or stevie. :)
 
You can use build-in filter_var function.

PHP:
<?php

if (!filter_var($subject, FILTER_VALIDATE_URL)) {   
    $error_message .= 'The url you entered does not appear to be valid.<br />';  
}

P.S. JavaScript validation is not used for security, it just helps user to see what's wrong immediately without submitting form. So you can add it, but after you checked that's everything valid on server side.
 
Back
Top