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

  • Home
  • SEARCH
  • 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 993029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:21:26+00:00 2026-05-16T06:21:26+00:00

I have a contact form, the values of which I’m passing to a php

  • 0

I have a contact form, the values of which I’m passing to a php page to save it to a text file. Somehow, it seems I cannot get the $_POSt values via ajax to save. What am I doing wrong? I am assuming something is wrong with my javascript code.

Here is the jQuery:

function checkForm(form) {
    var cssObj = {
        'background-color': '#F5C9C9',
        'border-color': '#F5A6A6',
        'border-style': 'solid',
        'border-size': '1px',
        'color': '#383838'
    }
    if ($("#name").val() == "" || $("#name").val() == "Your Name" || $("#name").val() == "Field cannot be blank") {
        $("#name").css(cssObj);
        $("#name").val('Field cannot be blank');
        return false;
    } else if ($("#email").val() == "" || $("#email").val() == "Your Email" || $("#email").val() == "Field cannot be blank" || $("#email").val() == "Please enter a valid Email Address") {
        $("#email").css(cssObj);
        $("#email").val('Field cannot be blank');
        return false;
    } else if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test($("#email").val())) {
        $("#email").css(cssObj);
        $("#email").val('Please enter a valid Email Address');
        return false;
    } else if ($("#msg").val() == "" || $("#msg").val() == "Your Message" || $("#msg").val() == "You forgot to enter your message!") {
        $("#msg").css(cssObj);
        $("#msg").val('You forgot to enter your message!');
        return false;
    } else {
        //create post data
        var postData = {
            "name": $("#name").val(),
            "email": $("#email").val(),
            "msg": $("#msg").val(),
            "origin": $("#origin").val()
        };

        //make the call
        $.ajax({
            type: "POST",
            url: "test.php",
            data: postData,
            success: function (response) {
                $('#label').show();

            }
        });
    }
}

$(function () {

    $('.msgload')
        .hide() // hide it initially
    .ajaxStart(function () {
        $(this).show();
    })
        .ajaxStop(function () {
        $(this).hide();
    });
}

HTML:

<form action="test.php" method="post" id="contactform" class="form">
        <div class="container">
            <div class="field">
                <input type="text" tabindex="1" value="Your Name" name="name" id="name" /><br />
            </div>
            <div class="field">
                <input type="text" tabindex="2" value="Your Email" name="email" id="email" /><br />
            </div>    
            <div class="field">
                <textarea tabindex="3" name="msg" id="msg">Your Message</textarea><br />
            </div> 
            <div class="field">
                <input type="text" tabindex="4" value="Type 'Yes, I am human'" name="captcha" id="captcha" /><br />
            </div> 
            <div class="field">
                <label id="label" style="display:none;">Your Message Has Been Sent</label>
            </div>
            <img src="image/ajax-loader.gif" alt="Sending" class="msgload">
            <input type="button" onclick="return checkForm('contactform');" id="sb" value="Submit" class="sbtn" />
            <input type="hidden" value="origin" name="origin" id="origin" style="display: none;"/>  
      </div>
</form>

PHP:

$data["name"]=$_POST["name"] 
$data["email"]=$_POST["email"] 
$data["msg"]=$_POST["msg"] 
$data["origin"]=$_POST["origin"] 


file_put_contents("test.txt", serialize($data));`enter code here`
  • 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-05-16T06:21:26+00:00Added an answer on May 16, 2026 at 6:21 am
          //create post data
                      var postData = { 
                        "name" : $("#name").val(),
                        "email" : $("#email").val(),
                        "msg" : $("#msg").val(),
                        "origin" : $("#origin").val()
                      };
    

    //change to..

    var email = encodeURIComponent($("#email").val());
    var name = encodeURIComponent($("#name").val());
    var msg = encodeURIComponent($("#msg").val());
    var origin = encodeURIComponent($("#origin").val());
    var postData = "name="+name+"&mail="+email+"&msg="+msg+"&origin="+origin;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a contact form in my flash file with name/email/message fields which a
I have this PHP contact form which disallows a submission from an existing IP.
I have a contact form made with php on my website. The problem is
I have a contact form which asks users for their name, email address and
I have a contact form which is suppose to go to a thank you
I have a textarea form which takes a large block of text. In this
I have a web page, and after the contact form is submitted, the contents
I have a contact form that has a dropdown to choose which department the
I have two files the one which hosts my actual contact form and then
I have a contact form which posts to mailchimp - but in certain cases,

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.