Get Post Data from Jquery Multidatespicker

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
makamo66
Forum Newbie
Posts: 24
Joined: Wed May 12, 2010 6:13 pm

Get Post Data from Jquery Multidatespicker

Post by makamo66 »

This is a very basic question. I don't know how to get the post data from the jquery multidatespicker. When I submit the page I want to echo back the post variables but I don't see how they're sent with jquery.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Get Post Data from Jquery Multidatespicker

Post by requinix »

jQuery doesn't "send" them - it just helps the user to fill in the form value. The value should be in $_POST as if someone had just typed it into a textbox.
makamo66
Forum Newbie
Posts: 24
Joined: Wed May 12, 2010 6:13 pm

Re: Get Post Data from Jquery Multidatespicker

Post by makamo66 »

I am using print_r($_POST); but I don't see anything posted (except the token)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Get Post Data from Jquery Multidatespicker

Post by requinix »

Then it's not included in the form: maybe not inside the <form>, or not given a name, or not included in the hypothetical AJAX.

What's the HTML and Javascript?
makamo66
Forum Newbie
Posts: 24
Joined: Wed May 12, 2010 6:13 pm

Re: Get Post Data from Jquery Multidatespicker

Post by makamo66 »

Code: Select all

				var arr=[];
				$('#simpliest-usage').multiDatesPicker({onSelect: function(date,e) { 
				var found = jQuery.inArray(date, arr);
				if (found >= 0) {
					// Element was found, remove it.
					arr.splice(found, 1);
				} else {
					// Element was not found, add it.
					arr.push(date);
				}
                alert(arr);
                }});			
		
$( "#submit_mdp" ).submit(function( event ) {
  $.ajax({
    url: 'http://beta.opentemp.local/user/dashboard',
	//data: dates,
	data: $("form#submit_mdp").serialize(),
    type: 'POST',
    'beforeSend': function(xhr, settings) {
	console.log( $("form#submit_mdp").serialize() );
      console.log('ABOUT TO SEND');
    },
    'success': function(result, status_code, xhr) {
      console.log('SUCCESS!');
    },
    'complete': function(xhr, text_status) {
      console.log('Done.');
    },
    'error': function (XMLHttpRequest, textStatus, errorThrown) {

	alert("Error with ajax Function: "+ textStatus+" "+errorThrown); }
  });
});

Code: Select all

<div id="simpliest-usage" class="box"></div><br />
<form method="POST" action="http://beta.opentemp.local/user/dashboard" accept-charset="UTF-8" id="submit_mdp"><input name="_token" type="hidden" value="9jlMjOzit5sZBGPkYQfwXwSerdzSnZXYVnEyr9Yx"><input class="mdp_button" type="submit" value="Submit"></form>
makamo66
Forum Newbie
Posts: 24
Joined: Wed May 12, 2010 6:13 pm

Re: Get Post Data from Jquery Multidatespicker

Post by makamo66 »

The multidatespicker calendar is a modal.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Get Post Data from Jquery Multidatespicker

Post by requinix »

You aren't sending the dates in your AJAX - the "arr" needs to be included along with the serialized form data, like

Code: Select all

data: $("form#submit_mdp").serialize() + "&" + $.param({ dates: arr }, false)
resulting in

Code: Select all

_token=9jlMjOzit5sZBGPkYQfwXwSerdzSnZXYVnEyr9Yx&dates[]=2013-12-31&dates[]=2013-12-30&dates[]=2013-12-29
Post Reply