Jump to content

[SOLVED] Serializing my form using jquery only returns a single result


lonewolf217

Recommended Posts

This is what I am working with right now.  I have a large form with multiple text, select and select multiple elements

 

	<script type="text/javascript">
		$(document).ready(function() {
			var jInput = $(":input");
			$("#submit").click(function() {
				var str = $("#resFilters").serialize();
				alert(str);
				$.post("test.php",$("#resFilters").serialize(),function(data) {
					if(data.length > 0) {
						$('#resources').fadeIn('slow');
						$('#resources').html(data);
					}
				});
				return false;	
			});
		});	

	</script>

 

on my backend page, i do

<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";

 

and for one of my select multiple fields on which I had selected multiple elements, it is only displaying one result, the last result

 

I have tried doing some research on how serialize works, but all I can find is that it is supposed to handle multiple selects without a problem, but I do not know how much simpler I can make it.  if I output an alert from my main page with the contents of the serialized form, I can see that it is formatted like "OS=windows&OS=unix", but how do I retrieve it?

I tried

<?php
foreach($_POST['OS'] as $os) {
	echo "OS=".$os."<br>";
}

but it outputs nothing, so now I am a little more confused why print_r($_POST) returns something, but not this

 

any help, or shove in the right direction is appreciated

Link to comment
Share on other sites

  • 2 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.