Looks like a great solution! Thanks!!

// mika

On Friday, May 10, 2013 9:42:46 PM UTC+8, Anthony wrote:
>
> It's not quite clear what your HTML looks like -- are you saying you have 
> multiple forms (i.e., <form></form>) with the same web2py formname (i.e., 
> same value in the hidden _formname field)? Or do you just have multiple 
> <input> elements with the same names (perhaps in separate forms, or outside 
> of forms altogether)?
>
> Anyway, I don't think it's documented, but instead of passing an array of 
> input names as the second argument to ajax(), you can instead pass any 
> jQuery selector that identifies either an entire form or any set of form 
> input elements (within a single form or across multiple forms). For 
> example, if you have:
>
> <div id='mydiv'>
>   <form id='myform'>
>     <input name='myinput1' type='text' />
>     <input name='myinput1' type='text' />
>   </form>
> </div>
>
> you can do:
>
> ajax('/my/url', '#myform', ...)  // all input elements in #myform
> ajax('/my/url', '#mydiv form', ...)   // all input elements in all forms 
> within #mydiv
> ajax('/my/url', '#mydiv input', ...)  // all input elements within #mydiv 
> (whether or not in a form)
> ajax('/my/url', '#mydiv [name=myinput1]', ...)  // just the myinput1 
> input within #mydiv
> ajax('/my/url', '#mydiv [name=myinput1], [name=myinput2]', ...)  // 
> multiple specific inputs
> ajax('/my/url', '[name=myinput1]', ...)  // all inputs on the page with 
> name 'myinput1'
>
> That last one is equivalent to the usual behavior when you specify just an 
> array of input names (i.e., ajax(..., ['myinput1'], ...)).
>
> Anthony
>
> On Friday, May 10, 2013 6:27:11 AM UTC-4, Mika Sjöman wrote:
>>
>> Hi
>>
>> I am having a problem because my forms are getting sent with multiple 
>> values. The issue is that on my page there are multiple places where the 
>> same formnames are used. So the post vars becomes like this:
>>
>> Parametersapplication/x-www-form-urlencoded
>> answer280lesson75lesson75lesson75player_answer
>> quiz96quiz96streak7streak7streak7
>> Source
>>
>> player_answer=&answer=280&streak=7&streak=7&streak=7&quiz=96&quiz=96&lesson=75&lesson=75&lesson=75
>> The above is created by>
>>
>> jQuery('#add_quiz_option').submit(function() {
>>                   ajax('{{=URL(c='quiz',f='add_inline_answer')}}',
>>                        ['description', 'is_correct', 'quiz', 'streak', 
>> 'lesson'], 'quiz_answers');
>>                   return false;
>>                 });
>>
>> On the server I could do a check if they are lists and then chop them 
>> down, but that is REALLY messy. Is this a design flaw from my perspective 
>> or is there a way to solve this better than renaming the vars and them 
>> renaming them to the matching corresponding database field names when the 
>> function receives the request.vars?
>>
>> Starting to get really messy in my code now because I use ajax/jquery 
>> calls allot. I could rename the form names, but that forces me to rename 
>> them again after I receive them at the server. Is there a simple way to 
>> tell jQuery to only use the values from a specific FORM-name so it will not 
>> send the same value 5 times?
>>
>> Cheers
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to