[jQuery] Re: Help Modifying the Action Page of an AJaX Form
Okay, I found a way to do what I want to do, but ran into something else. Using the jQuery Form plugin, I've managed to serialize the form inputs and, via ajax, post the values to a page which returns a JSON result: $('[EMAIL PROTECTED]/run.png]').click ( function ( e ) { var data = $('#filter').formSerialize(); var report = this.id.replace ( /\w+-(\w+)/, '$1' ); data += 'report=' + report; $.ajax ({ type: 'POST', url: '/reports/' + report + '.php', dataType: 'json', data: data, success: displayReport }); } ); The problem is that formSerialize() doesn't properly encode checkbox values. Given a set of checkbox options with the same name, normal form encoding passes the values as a comma-delimited list. The serialized value just applies them separately to the query string so that the only one that is read is the last one. Instead of myselections=value1,value2, value3, I get myselections=value1myselections=value2myselections=value3. Has anyone else seen this? Am I missing something? Thanks. On 4/27/07, Rob Wilkerson [EMAIL PROTECTED] wrote: I have a form on a page that doesn't have a submit button, per se. Instead, there are a number of elements which, when clicked, should submit the form to an action page that is specific to the element that was clicked. I see that I can ajax-ify a form, but I don't see how to modify the action attribute at the time the form is submitted. Currently, I have this working fine, but I need to implement a form for user input while maintaining the dynamic action page and the ajax nature. $('[EMAIL PROTECTED]/run.png]').click ( function ( e ) { var report = this.id.replace ( /\w+-(\w+)/, '$1' ); $.getJSON ( '/reports/' + report + '.php', function ( result ) { displayResult ( report, result ); } ); } ); Any help? Thanks. /rob
[jQuery] Re: Help Modifying the Action Page of an AJaX Form
The problem is that formSerialize() doesn't properly encode checkbox values. Given a set of checkbox options with the same name, normal form encoding passes the values as a comma-delimited list. N, that's not true at all. Normal, and proper, serialization would take the following markup: input type=checkbox name=cb value=1 / input type=checkbox name=cb value=2 / input type=checkbox name=cb value=3 / and generate this (assuming all three boxes are checked): cb=1cb=2cb=3 You can look at the spec here: http://www.w3.org/TR/html401/interact/forms.html Mike
[jQuery] Re: Help Modifying the Action Page of an AJaX Form
Correct. And although I haven't tried this on PHP servers, on a .NET server, the following form data passed: cb=1cb=2cb=3 Would be interpred on the server side: Request.Form[cb] == 1,2,3; JK -Original Message- From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Mike Alsup Sent: Friday, April 27, 2007 11:33 AM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Help Modifying the Action Page of an AJaX Form The problem is that formSerialize() doesn't properly encode checkbox values. Given a set of checkbox options with the same name, normal form encoding passes the values as a comma-delimited list. N, that's not true at all. Normal, and proper, serialization would take the following markup: input type=checkbox name=cb value=1 / input type=checkbox name=cb value=2 / input type=checkbox name=cb value=3 / and generate this (assuming all three boxes are checked): cb=1cb=2cb=3 You can look at the spec here: http://www.w3.org/TR/html401/interact/forms.html Mike
[jQuery] Re: Help Modifying the Action Page of an AJaX Form
You can look at the spec here: http://www.w3.org/TR/html401/interact/forms.html Hmmm. I hadn't read the spec. I'm used to dealing with these things on the server side and never really had to think about how they were handled. PHP doesn't seem to be handling it the same way ColdFusion and, as Jeff pointed out, .NET does. All the $_POST value is reporting is the last value. I'll do some more digging on the server side and take another look at my code to make sure I don't have some other bug. Thanks for setting me straight.
[jQuery] Re: Help Modifying the Action Page of an AJaX Form
http://www.php.net/manual/en/faq.html.php#faq.html.arrays This should point you in the right direction On 4/27/07, Rob Wilkerson [EMAIL PROTECTED] wrote: You can look at the spec here: http://www.w3.org/TR/html401/interact/forms.html Hmmm. I hadn't read the spec. I'm used to dealing with these things on the server side and never really had to think about how they were handled. PHP doesn't seem to be handling it the same way ColdFusion and, as Jeff pointed out, .NET does. All the $_POST value is reporting is the last value. I'll do some more digging on the server side and take another look at my code to make sure I don't have some other bug. Thanks for setting me straight. -- Aaron Heimlich Web Developer [EMAIL PROTECTED] http://aheimlich.freepgs.com
[jQuery] Re: Help Modifying the Action Page of an AJaX Form
Correct. And although I haven't tried this on PHP servers, on a .NET server, the following form data passed: cb=1cb=2cb=3 Would be interpred on the server side: Request.Form[cb] == 1,2,3; In PHP you'd need to name the inputs cb[] to achieve the same.
[jQuery] Re: Help Modifying the Action Page of an AJaX Form
Apologies for my ignorance. I've been away from PHP for a long time and guess I forgot that I had to name my checkbox fields with array notation (e.g. input type=checkbox ... name=mycheckbox[] /). Once I did that and used implode() on the server side I got what I needed. Thanks. On 4/27/07, Rob Wilkerson [EMAIL PROTECTED] wrote: You can look at the spec here: http://www.w3.org/TR/html401/interact/forms.html Hmmm. I hadn't read the spec. I'm used to dealing with these things on the server side and never really had to think about how they were handled. PHP doesn't seem to be handling it the same way ColdFusion and, as Jeff pointed out, .NET does. All the $_POST value is reporting is the last value. I'll do some more digging on the server side and take another look at my code to make sure I don't have some other bug. Thanks for setting me straight.