Not signed in (Sign In)

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

Categories

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

    • CommentAuthormwanafunzi
    • CommentTimeJun 14th 2007
     permalink
    I was hoping to get some advice on why the code below is not working as expected.
    At the moment I am working on making sure that the name in the form is not empty, when the form is submitted.

    The particular snip bit I am talking about is -
    <code>
    elseif(($key === 'name'&& !empty($formatedValue))|| $key === 'other'){
    echo 'hi';
    if(!preg_match("/^[A-Za-z -]{3,30}\$/",$formatedValue)){
    $message = $key.' should only contain letters and should be no longer than 45 characters';
    }
    }
    </code>

    the code below in full -
    <code>
    <?php
    function sendEmail($email){
    $headers ="MIME-Versin: 1.0\r\n" .
    "Content-type: text/plain; charset=UTF-8; format=flowed\r\n" .
    "Content-Transfer-Encoding: 8bit\r\n" .
    "From:" .$email['email']. "\r\n" .
    "X-Mailer: PHP" . phpversion();

    foreach($email as $key =>$val){
    if(is_array($val)) $emails = implode("\n",$val);
    elseif($key === 'submited' || $val === '' || $key === 'email') ;
    elseif(!is_array($val)){
    $val = formatInput($val);
    $emails .= "$val \n";
    }
    ;//do nothing
    }

    mail("bfishdesign@gmail.com","Query",$emails,$headers);
    echo "Thank you for your enquiry. We will get back to you as soon as possible";
    }
    function checkEmail($email){
    if(!preg_match("/^[A-Za-z]+[1-9]*([.][A-Za-z]+)?[@][A-Za-z]+[.][A-Za-z]{2,3}([.][A-Za-z]{2,3})?\$/",$email)){
    return false;
    }else return true;
    }

    function formatInput($toFormat){
    if(get_magic_quotes_gpc()){
    $toFormat = stripslashes($toFormat);
    $toFormat = trim(strip_tags((string) $toFormat));
    }else{
    $toFormat = trim(strip_tags((string) $toFormat));
    }
    return $toFormat;
    }
    //do some error checking on user input
    function checkValues($key,$check){
    $message = '';
    $formatedValue = formatInput($check);
    if($key === 'submited' || $formatedValue === '' || is_array($formatedValue)) ;
    elseif(($key === 'name'&& !empty($formatedValue))|| $key === 'other'){
    echo 'hi';
    if(!preg_match("/^[A-Za-z -]{3,30}\$/",$formatedValue)){
    $message = $key.' should only contain letters and should be no longer than 45 characters';
    }
    }
    elseif($key === 'email'){
    $email = checkEmail($formatedValue);
    if($email == 0){
    $message = 'email error';
    }
    }
    elseif($key === 'post'){
    if(!is_numeric($formatedValue) || strlen($formatedValue) != 4) $message = $key .' error';
    }
    elseif($key === 'phone' || $key === 'mobile'){
    if(!is_numeric($formatedValue) || strlen($formatedValue) != 10) $message = $key .' error';
    }
    return $message;
    }
    //convert array into individual variables
    function separateArray($array){
    foreach($array as $key => $val){
    if(is_array($val)) ;//separateArray($array[$key]);
    else{
    $check = checkValues($key,$array[$key]);
    if (!empty($check)) $errors[$key] = $check;
    }

    }
    if(empty($errors)) sendEmail($_POST);
    else{
    echo '<pre>';
    var_dump($errors);
    echo '</pre>';
    }
    }

    separateArray($_POST);


    ?>
    </code>
Add your comments
    Username Password
  • Format comments as (Help)