Jump to content

Capture An Array Of Post Data


bob_the _builder

Recommended Posts

Hey, im new to all the jquery stuff.. I cant get the function below to work proprely using serialize..

 

I guess I am way off track?

			$('#myForm').submit(function() {
	var data = $('#myForm').serialize();
	$("#shop").html('<center>

	<img src="./loading.gif"></center>');
	$.post("includes/cart-trans-process.php", data, function(response){
	$("#shop").html(response);
	},'text');
	});

			echo '<form name="myForm" id="myForm">';

	$sql = mysql_query("SELECT FROM trans ORDER BY firstname ASC");
	while($row = mysql_fetch_array($sql)) {
	foreach($row as $key=>$value){
	$$key = ValidateOutput($value);
	}

	echo '<tr>
	<p><a href="includes/cart-trans-delete.php?transid='.$transid.'" id="cart-trans-delete">x</a> | '.$firstname.' '.$lastname.' - <b>$'.$total.'</b></p>
	<p><input id="utotal" name="utotal[]" type="text" size="8"></p>
	<p><input type="hidden" id="method" name="method[]" value="'.$method.'"></p>
	<p><input type="hidden" id="firstname" name="firstname[]" value="'.$firstname.'"></p>
	<p><input type="hidden" id="lastname" name="lastname[]" value="'.$lastname.'"></p>
	<p><input type="hidden" id="email" name="email[]" value="'.$email.'"></p>
	<p><input type="hidden" id="total" name="total[]" value="'.$total.'"></p>
	<p><input type="hidden" id="transid" name="transid[]" value="'.$transid.'"></p>
	<input type="submit" id="myForm" value="Submit">';

	}

	echo '</form>';

 

With the code above the entire page reloads.. Appears it doesnt link to the jquery function..

 

Thanks

Link to comment
Share on other sites

To the script that you are posting to, what it is going to do is accept the $_POST data. I'm unclear on what you're trying to do and why, but I don't see any value in serializing a form and trying to send that to your serverside script. The serverside script should get the post values and then return back what you need to in terms of updating the client DOM with jquery.

Link to comment
Share on other sites

I am trying to capture the array of post variables on includes/cart-trans-process.php so process the request.. I used to use the following, but it only appearsd to work for single form variables apposed to an array of variables.. Im guesing that the use of id in the from locks it down to one variable not an array of variable.. ie

 

<input id="utotal" name="utotal" type="text" size="8">

 

vers.

 

<input id="utotal" name="utotal[]" type="text" size="8">

 

 

 

$("#cart-trans-process").live('click',function(){
var data = {utotal: $('#utotal').val(), total: $('#total').val(), method: $('#method').val(), firstname: $('#firstname').val(), lastname: $('#lastname').val(), email: $('#email').val(), transid: $('#transid').val(), };
$("#shop").html('<center><br /><br /><img src="./loading.gif"></center>');
$.post("includes/cart-trans-process.php", data, function(response){
$("#shop").html(response);
},'text');
});

Edited by bob_the _builder
Link to comment
Share on other sites

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.