Eliminate the need for hidden input fields

I have some hidden input fields used to store coordinates calculated by javascript. The purpose of these fields is to transmit the coordinates when submitting the form. I am using an AJAX request through MooTools. Is there an easy way to eliminate hidden input fields and add them to the $ _POST data submitted via the form?

+4
source share
2 answers

Yes. if a lot depends on how your form data is defined / how it is sent. eg:

new Request({ data: $("formid") }).send(); will serialize the form and submit all form fields. what you can do is move the hidden fields to the form before submitting, so that they also include them (via $("formid").adopt(el1, el2, ... eln); where els are your hiden) or a collection that you did as $$("input[type=hidden]") .

if you compose the data object manually, and then just add them to it using the key, its just a hash table of the key-> value pairs.

+1
source

I do not use MooTools, but my experience with Prototype, jQuery, and raw Javascript templates is that Javascript-based POST files are executed using the <form> element created on the fly. Adding POST data is done by adding hidden input fields to this form element, and then the form is submitted.

What is the reason you don't want to use hidden input fields? Does it work for me ...

0
source

All Articles