Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4

Thread: Form validation

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    Member #
    36762

    Form validation

    Can someone please help me to set up server side validation on all field in my form. I can't figure it out and I've searched all over the internet. Please, this is my last hope. URGENT!



    Html:


    <form class="form" id="contactus" action="" method="post" accept-charset="UTF-8">


    <label for="nametag">Namn<FONT COLOR="#FF0060">*</FONT></label>
    <input name="name" value="" type="text" id="name">


    <label for="emailtag">Email<FONT COLOR="#FF0060">*</FONT></label>
    <input name="email" value="" type="text" id="email">


    <label for="phonetag">Telefon</label>
    <input name="phone" type="text" id="phone" value="" />


    <label for="messagetag">Meddelande<FONT COLOR="#FF0060">*</FONT></label>
    <textarea name="message" id="message" value="" style="width: 87%; height: 200px;"></textarea>



    <label class="placeholder">&nbsp;</label>
    <button class="submit" name="submit">Skicka</button>



    </form>




    <script>

    $(function() {


    $('#contactus').submit(function (event) {
    event.preventDefault();
    event.returnValue = false;
    $.ajax({
    type: 'POST',
    url: 'php/mail.php',
    data: $('#contactus').serialize(),


    success: function(res) {
    if (res == 'successful') {
    $('#status').html('Det uppstod ett fel!').slideDown();
    }
    else {
    $('#status').html('Tack! Ditt meddelande har skickat.').slideDown();
    document.getElementById("contactus").reset();
    }
    },

    error: function(XMLHttpRequest, textStatus, errorThrown) {

    $('#status').html('Det uppstod ett fel!').slideDown();
    }
    });
    });
    });
    </script>






    Php:


    <?php



    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $message = $_POST['message'];
    $recipient = "info@mydomain.com";
    $subject = "Via Webbkontakt";
    $formcontent = "Namn: $name <br/> Email: $email <br/> Telefon: $phone <br/><br/> Meddelande:<br/><br/> $message";

    $headers = "From: " ."mydomain<info@mydomain.com>" . "\r\n";
    $headers .= "Reply-To: ". "$email" . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=utf-8\r\n";



    if(@mail($recipient, $subject, $formcontent, $headers))
    {
    echo "successful";
    }
    else
    {
    echo "error";
    }



    ?>
    Last edited by jilana2; Jul 13th, 2013 at 02:00 PM.

  2.  

  3. #2
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    How is it not working ? Any errors ?

  4. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    Member #
    36762
    Quote Originally Posted by Webzarus View Post
    How is it not working ? Any errors ?
    I think you misunderstood.
    I'm trying to validate the form server side.
    When submitting the form empty it should return
    "you have to fill in your name" You have to fill in a message" You have to fill in an email".
    And when you enter an invalid email "you must enter a valid email"

  5. #4
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    I didn't mis-understand as you didn't provide any details... If you want someone to just give you validation code.... Doubtful anyone here will do it... I write code, but I get paid very well to do it... You're better off learning how to do it yourself.https://www.google.com/search?q=php+...nt=safariThose will show you how to do it... Took 3 seconds to find the answer.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Tags for this Thread

All times are GMT -6. The time now is 02:56 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com