Modal form Submission to PHP using Jquery .ajax

BEBO

I am trying to post a modal form to a table using php, jquery .ajax but it never works.. tried debugging using firebug and i don't see any errors. i tested the form by using form action="notes_functions.php" and it worked fine.

Profile.php

    <div class="modal-body">

        <form class="noteform" id="notesmodal" method="post">
           <fieldset>      
          <label>Title</label>
                <input type="text" class="form-control" name="note_title" placeholder="Enter a title for your note">
                <label>Note</label>
                <textarea rows="4" cols="50" class="form-control" name="note_content" placeholder="note"></textarea>
                <label>Note type</label>
                <div class="panel-body">
                    <input type="tagsinput" id="teetete" class="tagsinput" value="" />
                </div>                                                  
                <label for="exampleInputFile">Attach a document</label>
                <input type="file" id="exampleInputFile3">
                <p class="help-block">PDF, DOCX and image files are supported.</p>
            <div class="checkbox">
                <label>
                    <input type="checkbox"> Check me out
                    <input type="label" name="note_account" value="<?php echo $acctname ?>"/> 
                </label>
            </div>
            <input type="hidden" name="note_creator" value="<?php echo $_SESSION['username'];?>"/>
              </fieldset>
             <button class="btn btn-default" id="submitnote" >ADD</button>
        </form>
    </div>

this is my js code

$(function(){
  $("button#submitnote").click(function(){
    $.ajax ({
      type:"POST",
      url:"notes_functions.php",
      data: $('form.noteform').serialize(),
      success: function(msg){
        $("#thanks").html(msg)
        $("form.noteform").modal('hide');
      },
      error: function(){
        alert("failure");
      }
    });
  });
});

notes_functions.php

<?php

include_once 'dbconnect.php';

if (isset($_POST['note_title'])) {



        $notetitle = strip_tags($_POST['note_title']);
        $noteContent = strip_tags($_POST['note_content']);
        $noteAccount = strip_tags($_POST['note_account']);
        $noteCreator = strip_tags($_POST['note_creator']);

        mysql_query("INSERT INTO account_notes (note_title, note_contents, note_account, note_creator) 
            VALUES ('$notetitle','$noteContent', '$noteAccount', '$noteCreator') ");

        echo "Name = ".$notetitle;
        echo $noteCreator;




 }

?>
AlliterativeAlice

You should really be using .submit() rather than click (for submit-by-enter, etc.) and returning false to block conventional submits. You also need to make sure the code to bind the events runs after the form element is created. The easiest way to do this is to put it in the document ready handler.

jQuery(document).ready(function ($) {
    $("#notesmodal").submit(function () {
        $.ajax({
            type: "POST",
            url: "notes_functions.php",
            data: $('form.noteform').serialize(),
            success: function (msg) {
                $("#thanks").html(msg)
                $("form.noteform").modal('hide');
            },
            error: function () {
                alert("failure");
            }
        });
        return false;
    });
});

And change the ADD button to be:

<input type="submit" name="submit" class="btn btn-default" id="submitnote" value="ADD" />

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using jQuery AJAX to call a php page on form submission

From Dev

Ajax form submission on a form created using jquery

From Dev

Using PHP form validation on jQuery form submission

From Dev

multi submit buttons multi checkboxes no form jquery ajax php submission

From Dev

jQuery ajax form submission to php not working with response from server

From Dev

jquery ajax requests are not responding on the new tab after the php form submission

From Dev

multi submit buttons multi checkboxes no form jquery ajax php submission

From Dev

Prevent Form Submission if dynamic field is blank....Php / Jquery / Ajax

From Dev

How to confirm a form submission with Bootbox using jQuery AJAX and JSON

From Dev

jQuery - stop form submission from changing page using ajax

From Dev

Don't reload page after form submission using ajax and jquery

From Dev

Form Submission not working second time after submiting using Jquery and Ajax

From Dev

Form Submission through Ajax and PHP

From Dev

Form submission using AngularJS/AJAX

From Dev

Delayed form submission using JQuery

From Dev

Basic form submission with jquery/ajax not working

From Dev

jquery load vs ajax for form post submission

From Dev

CodeIgniter, Jquery Ajax, Form Submission and File Upload

From Dev

Ajax form submission with Jquery validation plugin is not working

From Dev

ajax form submission with jquery multiple forms

From Dev

trouble sending modal form contents to PHP file with AJAX and Jquery

From Dev

Bootstrap Form Submission and Modal

From Dev

Form submission using ajax and page view moderation after the submission

From Dev

php coding Form submission to server using php

From Dev

Form validation using JQuery, Ajax, PHP, Json

From Dev

Form validation using jQuery and Ajax in PHP

From Dev

form submission using jquery.confirm

From Dev

Prevent double submission of form using jQuery

From Dev

Form submission using Jquery: NULL is submitted

Related Related

  1. 1

    Using jQuery AJAX to call a php page on form submission

  2. 2

    Ajax form submission on a form created using jquery

  3. 3

    Using PHP form validation on jQuery form submission

  4. 4

    multi submit buttons multi checkboxes no form jquery ajax php submission

  5. 5

    jQuery ajax form submission to php not working with response from server

  6. 6

    jquery ajax requests are not responding on the new tab after the php form submission

  7. 7

    multi submit buttons multi checkboxes no form jquery ajax php submission

  8. 8

    Prevent Form Submission if dynamic field is blank....Php / Jquery / Ajax

  9. 9

    How to confirm a form submission with Bootbox using jQuery AJAX and JSON

  10. 10

    jQuery - stop form submission from changing page using ajax

  11. 11

    Don't reload page after form submission using ajax and jquery

  12. 12

    Form Submission not working second time after submiting using Jquery and Ajax

  13. 13

    Form Submission through Ajax and PHP

  14. 14

    Form submission using AngularJS/AJAX

  15. 15

    Delayed form submission using JQuery

  16. 16

    Basic form submission with jquery/ajax not working

  17. 17

    jquery load vs ajax for form post submission

  18. 18

    CodeIgniter, Jquery Ajax, Form Submission and File Upload

  19. 19

    Ajax form submission with Jquery validation plugin is not working

  20. 20

    ajax form submission with jquery multiple forms

  21. 21

    trouble sending modal form contents to PHP file with AJAX and Jquery

  22. 22

    Bootstrap Form Submission and Modal

  23. 23

    Form submission using ajax and page view moderation after the submission

  24. 24

    php coding Form submission to server using php

  25. 25

    Form validation using JQuery, Ajax, PHP, Json

  26. 26

    Form validation using jQuery and Ajax in PHP

  27. 27

    form submission using jquery.confirm

  28. 28

    Prevent double submission of form using jQuery

  29. 29

    Form submission using Jquery: NULL is submitted

HotTag

Archive