Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8322657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:27:53+00:00 2026-06-08T23:27:53+00:00

Hi – I’ve implemented a contact form on my site based on the tuto

  • 0

Hi – I’ve implemented a contact form on my site based on the tuto at this address http://designwoop.com/2012/07/tutorial-coding-a-jquery-popup-modal-contact-form/
It works fine, the only issue is that I want to add a field “name” in the form.

So I added this line of code in the html code of form:

<input id="name" class="txt" type="name" name="name" placeholder="name"/><br />

Code of the form after modification:

<form id="contact" action="#" method="post" name="contact">
<label for="name">Your Name</label>
<input id="name" class="txt" type="name" name="name" placeholder="name"/><br />
<label for="email">Your E-mail</label>
<input id="email" class="txt" type="email" name="email" placeholder="e-mail address"/>
<br />
<textarea id="msg" class="txtarea" name="msg" placeholder="Type your message here..."></textarea>
<button id="send">Send E-mail</button>
</form>

I also added this to the send mail php file:

$msg .= "<p><strong>From:</strong> ".$username."</p>\r\n";

Full code of the send mail php file:

?php
$sendto   = "myemail@gmail.com";
$usermail = $_POST['email'];
$content  = nl2br($_POST['msg']);

$subject  = "New Message frm";
$headers  = "From: " . strip_tags($usermail) . "\r\n";
$headers .= "Reply-To: ". strip_tags($usermail) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";

$msg  = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>New message</h2>\r\n";
$msg .= "<p><strong>From:</strong> ".$username."</p>\r\n";
$msg .= "<p><strong>E-mail:</strong> ".$usermail."</p>\r\n";
$msg .= "<p><strong>Message:</strong> ".$content."</p>\r\n";
$msg .= "</body></html>";


if(@mail($sendto, $subject, $msg, $headers)) {
        echo "true";
} else {
        echo "false";
}

?>

And last part: the javascript code of the contact form. This is where I guess I need to add a reference to the new field “name” that I added. But no idea where? (and also to make that field mandatory). Your help would be much appreciated. Many thanks

// JavaScript Document
function validateEmail(email) {
                var reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
                return reg.test(email);
        }

        $(document).ready(function() {
                $(".modalbox").fancybox();
                $("#contact").submit(function() { return false; });


                $("#send").on("click", function(){
                        var emailval  = $("#email").val();
                        var msgval    = $("#msg").val();
                        var msglen    = msgval.length;
                        var mailvalid = validateEmail(emailval);

                        if(mailvalid == false) {
                                $("#email").addClass("error");
                        }
                        else if(mailvalid == true){
                                $("#email").removeClass("error");
                        }

                        if(msglen < 4) {
                                $("#msg").addClass("error");
                        }
                        else if(msglen >= 4){
                                $("#msg").removeClass("error");
                        }

                        if(mailvalid == true && msglen >= 4) {
                                // if both validate we attempt to send the e-mail
                                // first we hide the submit btn so the user doesnt click twice
                                $("#send").replaceWith("<em>sending...</em>");

                                $.ajax({
                                        type: 'POST',
                                        url: 'sendmessage.php',
                                        data: $("#contact").serialize(),
                                        success: function(data) {
                                                if(data == "true") {
                                                        $("#contact").fadeOut("fast", function(){
                                                                $(this).before("<p><strong>Success! Your message has been sent, thank you.</strong></p>");
                                                                setTimeout("$.fancybox.close()", 1000);
                                                        });
                                                }
                                        }
                                });
                        }
                });
        });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:27:55+00:00Added an answer on June 8, 2026 at 11:27 pm

    Replace the following code with this:

    var emailval  = $("#email").val();
    var msgval    = $("#msg").val();
    var msglen    = msgval.length;
    var mailvalid = validateEmail(emailval);
    //Get our name
    var nameval = $("#name").val();
    //Get our name length
    var namelen = nameval.length;
    

    Then under

                    if(msglen < 4) {
                            $("#msg").addClass("error");
                    }
                    else if(msglen >= 4){
                            $("#msg").removeClass("error");
                    }
    

    add this

                if(namelen < 2) {
                //name must be at least 2 characters
                        $("#name").addClass("error");
                }
                else if(namelen >= 2){
                        $("#name").removeClass("error");
                }
    

    Thats the JavaScript done!

    For the PHP section search for :

    $usermail = $_POST['email'];
    

    add:

    $username = $_POST['name'];
    

    Try that my friend 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my website i develop http://alessandro.babonmultimedia.com/ when we clicked at contact (navigation at
I implemented a javascript menu onto my site http://www.ogormanconstruction.co.uk/work If you select 'Work' then
I found a site with a very nice Modal Contact Form that I think
I want to add a form to contact me via email on my site.
I'm working on a Wordpress theme that has a Jquery animated contact form in
In our Android application I implemented the contact selection by using Intent action *ACTION_PICK*
I have a requirement to implement contact database. This contact database is special in
Implemented a generic repository with several Methods. One of those is this: public IEnumerable<T>
I implemented the exception filter like here: http://www.asp.net/web-api/overview/web-api-routing-and-actions/exception-handling And registered it globally, like microsoft
I have implemented a scroll to on my test site and added a Specialities

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.