I currently have a form with inputs and name attributes.
I’m able to get what I needed through jquery:
var inputValues= $('.myForm').serialize();
if I alert(inputValues), I get what I needed, (like form GET variables: categories=examplevalue&name=examplename&email=exampleemail)
Now, I’m trying to pass it to PHP with ajax, like so (ajax.js)
$.ajax({
url: "myfile.php",
type: "POST",
data: "inputs="+inputValues
}).done(function(data){
alert(data);
});
In my PHP i have this:
if(isset($_POST['inputs'])){
echo $_POST['inputs'];
}
I assume that it would alert out bunch of variables depending on my form, but it only echo’s out the first name variable which is categories
What am i doing wrong here?
Thanks
serialize()generates a query string (foo=bar&baz=yikes) format that cannot be assigned to a single parameter (inputs=...in your case).In your
$.ajaxcall, removeinputs=and just useinputValuesalone. This would allow you to get the individual variables in your form using$_POST['myvar'].