Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How to modify forms validation error messages to show up next to label

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #34487
    Arde
    Participant

    Hi. I’m trying to modify this Nettust contact form so that it would show validating errors next to label and not in a list top of the form. My php skills are too poor to succeed in this task. Could someone advise how this could be made to work as desired?

    I would like to get the error message show up like this:

    Here is the html part:


    Get In Touch!


    Fill out our super swanky HTML5 contact form below to get in touch with us! Please provide as much information as possible for us to help you with your enquiry :)


    //init variables
    $cf = array();
    $sr = false;

    if(isset($_SESSION)){
    $cf = $_SESSION;
    $sr = true;
    }
    ?>

    • There were some problems with your form submission:

    • if(isset($cf) && count($cf) > 0) :
      foreach($cf as $error) :
      ?>

    • endforeach;
      endif;
      ?>

    Thanks for your message! We will get back to you ASAP!




















    * indicates a required field




    And here is the process.php

    
    if( isset($_POST) ){

    //form validation vars
    $formok = true;
    $errors = array();

    //sumbission data
    $ipaddress = $_SERVER;
    $date = date('d/m/Y');
    $time = date('H:i:s');

    //form data
    $name = $_POST;
    $email = $_POST;
    $telephone = $_POST;
    $enquiry = $_POST;
    $message = $_POST;

    //validate form data

    //validate name is not empty
    if(empty($name)){
    $formok = false;
    $errors[] = "You have not entered a name";
    }

    //validate email address is not empty
    if(empty($email)){
    $formok = false;
    $errors[] = "You have not entered an email address";
    //validate email address is valid
    }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
    $formok = false;
    $errors[] = "You have not entered a valid email address";
    }

    //validate message is not empty
    if(empty($message)){
    $formok = false;
    $errors[] = "You have not entered a message";
    }
    //validate message is greater than 20 charcters
    elseif(strlen($message) < 20){
    $formok = false;
    $errors[] = "Your message must be greater than 20 characters";
    }

    //send email if all is ok
    if($formok){
    $headers = "From: [email protected]" . "rn";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";

    $emailbody = "

    You have recieved a new message from the enquiries form on your website.


    Name: {$name}


    Email Address: {$email}


    Telephone: {$telephone}


    Enquiry: {$enquiry}


    Message: {$message}


    This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}

    ";

    mail("[email protected]","New Enquiry",$emailbody,$headers);

    }

    //what we need to return back to our form
    $returndata = array(
    'posted_form_data' => array(
    'name' => $name,
    'email' => $email,
    'telephone' => $telephone,
    'enquiry' => $enquiry,
    'message' => $message
    ),
    'form_ok' => $formok,
    'errors' => $errors
    );


    //if this is not an ajax request
    if(empty($_SERVER) && strtolower($_SERVER) !== 'xmlhttprequest'){
    //set session variables
    session_start();
    $_SESSION = $returndata;

    //redirect back to form
    header('location: ' . $_SERVER);
    }
    }
Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.