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 8891791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:49:52+00:00 2026-06-14T22:49:52+00:00

I’m using jquery/ajax to submit a form without refreshing the page. Here is my

  • 0

I’m using jquery/ajax to submit a form without refreshing the page.

Here is my form code:

<div id="event_form">
    <form name="event_submit" method="post" action="">
        <label for="what" id="what_label">What is the event?</label>
        <input type="text" name="what" id="what" class="entry_field" />
        <br />
        <label class="error" for="what" id="what_error">This field is required.</label>
        <br />
        <label for="where" id="where_label">Where is the event?</label>
        <input type="text" name="where" id="where" class="entry_field" />
        <br />
        <label class="error" for="where" id="where_error">This field is required.</label>
        <br />
        <label for="when" id="when_label">When is the event?</label>
        <input type="text" name="when" id="when" class="entry_field" />
        <br />
        <label class="error" for="when" id="when_error">This field is required.</label>
        <br />
        <label for="details" id="details_label">Additional details</label>
        <textarea rows="8" cols="30" name="details"></textarea>            
        <br />
        <input type="submit" value="Post Event" name="submit" class="submitButton" title="Click to post event" />
    </form>
</div>

Here’s my jquery/ajax:

  $(function() {
    $('.error').hide();

    $(".submitButton").click(function() {
      // validate and process form
      // first hide any error messages
      $('.error').hide();

      var what = $("input#what").val();
      if (what == "") {
        $("label#what_error").show();
        $("input#what").focus();
        return false;
      }
      var where = $("input#where").val();
      if (where == "") {
        $("label#where_error").show();
        $("input#where").focus();
        return false;
      }
      var when = $("input#when").val();
      if (when == "") {
        $("label#when_error").show();
        $("input#when").focus();
        return false;
      }

      var dataString = 'what='+ what + '&where=' + where + '&when=' + when;
      //alert (dataString);return false;

      $.ajax({
        type: "POST",
        url: "event_submit.php",
        data: dataString,
        success: function() {
          $('#event_form').html("<div id='message'></div>");
          $('#message').html("<h2>Event Submitted!</h2>");
        }
       });
      return false;
    });
  });

And here’s the php:

<?php

include "conf.php";

if ((isset($_POST['what'])) && (strlen(trim($_POST['what'])) > 0)) {
    $what = stripslashes(strip_tags($_POST['what']));
} else {$what = 'No description of the event entered.';}
if ((isset($_POST['where'])) && (strlen(trim($_POST['where'])) > 0)) {
    $where = stripslashes(strip_tags($_POST['where']));
} else {$where = 'No location entered for the event.';}
if ((isset($_POST['when'])) && (strlen(trim($_POST['when'])) > 0)) {
    $when = stripslashes(strip_tags($_POST['when']));
} else {$when = 'No time entered for the event.';}
if ((isset($_POST['details'])) && (strlen(trim($_POST['details'])) > 0)) {
    $details = stripslashes(strip_tags($_POST['details']));
}

if(isset($details)){
    mysql_query("INSERT INTO `events` (`school_id`, `what`, `where`, `when`, `details`) VALUES ('$school_id', '$what', '$where', '$when', '$details')") or die(mysql_error());
}
else {
    mysql_query("INSERT INTO `events` (`school_id`, `what`, `where`, `when`) VALUES ('$school_id', '$what', '$where', '$when')") or die(mysql_error());
}

exit;
?>

On the page that the form is on, there is a “$school_id” given in the url as ?school=1687 or whatever. I can retrieve that on the form page with $_GET, but how can I pass this variable to the ajax/php? I need to insert it in the table as a variable.

  • 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-14T22:49:53+00:00Added an answer on June 14, 2026 at 10:49 pm

    You could just use a hidden input. Something like:

    <input type="hidden" id="school_id" value="<?php echo $school_id" />
    

    then tack it onto your data variable:

    var dataString = 'school_id='+$('#school_id').val()+'&what='+ what + '&where=' + where + '&when=' + when;
    

    then retrieve it on your php page:

    $school_id = $_POST['school_id'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.