Click here to Skip to main content
14,739,178 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys... i would like to use the .serialize() function of jquery i am submitting my form now i want to use that values passed in my php file but how can i access them? heres my html file

<form id="priviledge" method="POST" action="update.php">
        
   <input type="submit"  class= "button_active_red" id="save_new_user" name="save_new_user"/>

   <input type="checkbox" id="can_open_admin" name="can_open_admin" value="test" /><label for ="can_open_admin">Allow access to Admin panel</label>
        
   <input type="checkbox" id="can_modify_useraccount" name="can_modify_useraccount" /><label for ="can_modify_useraccount">Allow user to modify other accounts</label>

</form>


and heres my js code



$.ajax({
  type	: "POST",
  url	: "update.php",
  data	: {		
    "formData" : $("#priviledge").serialize() 
	},
  datatype : 'html',
  success: function(data) {			
	alert(data);
  }
});


now in my php file im trying to access the value but it echos an empty string heres my php file

$postForm = $_POST["formData"];
print_r($_POST["formData"]);

echo $_POST["formData"]["can_open_admin"] ;
Posted

1 solution

You're posting your whole serialized form as a single piece of data called "formData".

Try this:
$.ajax({
  type	: "POST",
  url	: "update.php",
  data	: $("#priviledge").serialize(),
  datatype : 'html',
  success: function(data) {			
    alert(data);
  }
});


PHP:
$postForm = $_POST;
print_r($_POST);
echo $_POST["can_open_admin"];
   
Comments
Madzmar25 22-Feb-12 3:37am
   
yeah it works... thanks...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900