This is the jQuery code that I use to submit form details to a php function:
jQuery(document).ready(function($) { jQuery('.submit').click(function(){ var str = $("#ajaxForms").serialize(); var data = { action: 'myajax-submit', serialize: str, beforeSend: function(){ alert('Sending...'); } }; jQuery.post(MyAjax.ajaxurl, data, function(response) { alert('Got this from the server: ' + response); }); return false; }); });
and this is the php function:
function myajax_submit() { $whatever = $_POST['serialize']; echo $whatever; die(); }
Everything works, but when a warning window appears, the text displays a string of values from my html form #ajaxForms . I believe this is because the php function echos $_POST['serialize'] .
In my form, I have an input field, for example:
<input id="postID" name="postID" value="First Name" type="text" />
but when I try to execute the echo variable $_POST['postID'] in php, it does not display anything in the warning field.
I thought, by sending form data serialized to a php function, could I use the $ _POST variable associated with the form inputs?
Help evaluate. :)
jquery php serialization
Shoebox
source share