1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

some small help with PHP contact form

Discussion in 'PHP & Perl' started by XoRaK, Feb 2, 2015.

  1. XoRaK

    XoRaK Regular Member

    Joined:
    Oct 28, 2009
    Messages:
    313
    Likes Received:
    251
    Occupation:
    social worker
    Location:
    Belgium
    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
     
  2. XoRaK

    XoRaK Regular Member

    Joined:
    Oct 28, 2009
    Messages:
    313
    Likes Received:
    251
    Occupation:
    social worker
    Location:
    Belgium
    noone? I'm paying 5$ for this simple thing... maybe that helps getting help ;-)
     
  3. lightning37

    lightning37 Newbie

    Joined:
    Dec 12, 2014
    Messages:
    21
    Likes Received:
    4
    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($subjectFILTER_VALIDATE_URL,FILTER_FLAG_HOST_REQUIRED)) {
        
    $error_message .= 'The url you entered does not appear to be valid.<br />';

    Try that.
     
  4. kaptain1

    kaptain1 Junior Member

    Joined:
    Jan 30, 2015
    Messages:
    102
    Likes Received:
    16
    Occupation:
    Freelance
    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!!
     
  5. Tobbe co

    Tobbe co Junior Member

    Joined:
    Sep 29, 2014
    Messages:
    171
    Likes Received:
    139
    NEVER put the validation on the clients side..
     
  6. stevie

    stevie Newbie

    Joined:
    Jul 31, 2010
    Messages:
    49
    Likes Received:
    10
    Location:
    UK
    Home Page:
    Hope this helps.
     
  7. lightning37

    lightning37 Newbie

    Joined:
    Dec 12, 2014
    Messages:
    21
    Likes Received:
    4
    Did anyone ever end up getting get paid the $5 promised by XoRaK?
     
  8. laowai

    laowai Power Member

    Joined:
    Feb 27, 2011
    Messages:
    522
    Likes Received:
    185
    Always put the validation on BOTH sides :p
     
    • Thanks Thanks x 1
  9. iamian

    iamian Newbie

    Joined:
    Jun 5, 2015
    Messages:
    4
    Likes Received:
    0
    try to user javascript to make it validation.

    or you can example script from lightning37 or stevie. :)
     
  10. WebmasterHacks

    WebmasterHacks Newbie

    Joined:
    Sep 6, 2015
    Messages:
    10
    Likes Received:
    14
    You can use build-in filter_var function.

    PHP:
    <?php

    if (!filter_var($subjectFILTER_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.