开发者

Is there a javascript (jquery) library for updating html form controls from cgi parameters?

Our site has some very complicated form controls that are submitted and then show up again on the results page in case users want to resubmit the form from the results page.

Currently, this requires a lot of if-then st开发者_C百科atements to preset the form controls to what was submitted.

I'm wondering if there is a library (preferably jquery) that can take the cgi parameters from the URL and then update the form to those values onready. Or if there is a slicker way that I'm not seeing even better. We use perl as our programming language.


Persisting form state isn't usually approached from the client (JS) side, but from the server side. There are a number of good modules on CPAN for dealing with web forms, including HTML::FormFu and Form::Sensible, although personally I prefer HTML::FormHandler. With it, you can declare your fields and all of their validation rules, and the module will validate the form for you, organize any errors on a per-field basis, and help you to render all of the form controls (including any error messages). You get your choice of control over rendering, from a totally automatic layout (nice for development), to manual layout with FormHandler's builtin widgets, to providing custom templates for the widgets, to doing all of the templating yourself and just using the form object as a repository of field values and messages.


You can use this

$('#myId').load('myCGI.py');

This

Load data from the server and place the returned HTML into the matched element.

See jquery load.


http://www.reach1to1.com/sandbox/jquery/testform.html

This plugin takes JSON data and updates the form as desired.

This plug creates JSON from the cgi parameter string http://benalman.com/code/projects/jquery-bbq/examples/deparam/

Put them together and add a class to any forms you want to apply this to and here you go in a one-liner to run on doc ready.

function form_presetFromQueryString(){
    $('form.deserialize').deserialize( $.deparam.querystring() );
}


This SO answer describes a little plugin that can either capture a form's state, or apply a serialized state to a form. Perhaps this could be part of the solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜