Page 1 of 1

Get Post Data from Jquery Multidatespicker

Posted: Tue Dec 31, 2013 1:48 pm
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.

Re: Get Post Data from Jquery Multidatespicker

Posted: Tue Dec 31, 2013 2:08 pm
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.

Re: Get Post Data from Jquery Multidatespicker

Posted: Tue Dec 31, 2013 2:58 pm
by makamo66
I am using print_r($_POST); but I don't see anything posted (except the token)

Re: Get Post Data from Jquery Multidatespicker

Posted: Tue Dec 31, 2013 3:18 pm
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?

Re: Get Post Data from Jquery Multidatespicker

Posted: Tue Dec 31, 2013 4:28 pm
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>

Re: Get Post Data from Jquery Multidatespicker

Posted: Tue Dec 31, 2013 4:28 pm
by makamo66
The multidatespicker calendar is a modal.

Re: Get Post Data from Jquery Multidatespicker

Posted: Tue Dec 31, 2013 5:06 pm
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