Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorWladislaw
    • CommentTimeAug 20th 2006
     permalink
    I'm coding myself a new portfolio website, and I was wondering if you guys know of any good tutorials to make a simple PHP contact form, with maybe some extra fields like "Time Frame" and "Budget". I'm not completely new to PHP, but I've dabbled with it before.
    • CommentAuthorPettyRider
    • CommentTimeAug 20th 2006
     permalink
    • CommentAuthorWladislaw
    • CommentTimeAug 20th 2006
     permalink
    Thanks. Now that I can code a contact form, how can I make it so that if the required fields are not completed, a message will appear that says, "All fields have not been completed," or something along those lines.
    • CommentAuthorPettyRider
    • CommentTimeAug 20th 2006 edited
     permalink
    Use IF statements in your PHP before the mail is sent.
    <?php
    ...

    if(!$_POST['time'])
    {
    $error['time'] = TRUE;
    }

    ...

    if(isarray($error))
    {
    ...
    }

    ...
    ?>
    • CommentAuthordhayes
    • CommentTimeAug 20th 2006
     permalink
    ..or:

    $required = array('name','email','message');

    $errors = array();
    foreach($_POST as $k=>$v){
    if(in_array($k,$required) and $v==''){
    $errors[] = 'Please fill in your '.$k.'.';
    }
    }

    if($error_count = count($errors)){
    $msg = '<ul><li>Please fill in the the following field'.($error_count>1?'s':'').' before proceeding:</li>';
    for($i=0; $i<$error_count; $i++){
    $msg .= '<li>'.$errors[$i].'</li>';
    }
    $msg .= '</ul>';

    echo $msg;
    exit;
    } else {
    // do email thing
    }


    • CommentAuthorPettyRider
    • CommentTimeAug 20th 2006
     permalink
    Yeah.. that's much more robust than my simplistic way.
Add your comments
    Username Password
  • Format comments as (Help)