Use of HFH within javascript

20 views
Skip to first unread message

Sungsam Gong

unread,
Sep 10, 2012, 8:13:54 AM9/10/12
to formh...@googlegroups.com
Hi,

Is there any way to use HFH within a javascript call?
I just want the form displayed within a pop-up window and doing some ajax stuff.
In specific, I'm using a jquery plugin (boxy) to build a dialog box
and wondering HFH can be fitted into this.

Regards,
Sung

Rippl, Steve

unread,
Sep 10, 2012, 12:27:46 PM9/10/12
to formh...@googlegroups.com
Your ajax call can hit a url in your app that returns your HFH form and it puts that html in the pop-up box.  If it's still the native window (as I think you'd get with the JQuery plugin) you'd use more javascript for the submit, if it's a separate window popup then it can be handled by the browser, some JS to close the window on successful submissions etc.  I've used this kind of thing a couple of times and it works OK I think.




--
You received this message because you are subscribed to the Google Groups "formhandler" group.
To post to this group, send email to formh...@googlegroups.com.
To unsubscribe from this group, send email to formhandler...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/formhandler?hl=en.




--
Steve Rippl
Technology Director
Woodland Public Schools
360 841 2730

Sungsam Gong

unread,
Sep 11, 2012, 4:59:49 AM9/11/12
to formh...@googlegroups.com
Thanks for this - helped me alot

Sungsam Gong

unread,
Sep 11, 2012, 7:15:01 AM9/11/12
to formh...@googlegroups.com
Hi,

One thing I just noticed is that whenever the ajax hits the url, a
hidden parameter, named '_', is passed together, which invokes a form
validation on appearance.
I think the hidden parameter is to point the DOM constructor to
prepare the jquery call.
Nothing to do with HFH, but can you think of any workaround this?

Regards,
Sung

Rippl, Steve

unread,
Sep 11, 2012, 11:18:17 AM9/11/12
to formh...@googlegroups.com
I believe $form->process is triggered whenever there's something in $c->req->params, so perhaps something like 

$form->process(...) if  !$c->req->params->{_}

or however you need to shape it...

Sungsam Gong

unread,
Sep 11, 2012, 11:22:01 AM9/11/12
to formh...@googlegroups.com
Well, managed to delete a hidden parameter on an ajax call:
delete $c->req->params->{'_'};
$form->process(params=>$c->req->params);

Next challenge is how to process the ajax form on submission - the
'posted' request designates the native URL rather than the URL where
the ajax pops up.

Rippl, Steve

unread,
Sep 11, 2012, 11:31:19 AM9/11/12
to formh...@googlegroups.com
On Tue, Sep 11, 2012 at 8:22 AM, Sungsam Gong <gong.s...@gmail.com> wrote:
Well, managed to delete a hidden parameter on an ajax call:
delete $c->req->params->{'_'};
$form->process(params=>$c->req->params);

Next challenge is how to process the ajax form on submission - the
'posted' request designates the native URL rather than the URL where
the ajax pops up.

 

Sungsam Gong

unread,
Sep 11, 2012, 12:04:48 PM9/11/12
to formh...@googlegroups.com
Worked very well:
MyApp::MyForm->new(action=>$c->uri_for('/some_url'));

Many thanks to you.

Sungsam Gong

unread,
Sep 11, 2012, 12:25:15 PM9/11/12
to formh...@googlegroups.com
Just realised one caveat for this - no form validation within this action

Rippl, Steve

unread,
Sep 11, 2012, 12:31:14 PM9/11/12
to formh...@googlegroups.com
On Tue, Sep 11, 2012 at 9:25 AM, Sungsam Gong <gong.s...@gmail.com> wrote:
Just realised one caveat for this - no form validation within this action


I don't understand, isn't validation triggered by $form->process, or rather the pattern is normally if( $form->process(...)) {...} , it returning some true value if validation occurred successfully...


 

Sungsam Gong

unread,
Sep 11, 2012, 12:53:04 PM9/11/12
to formh...@googlegroups.com
What I meant is that after an initial loading of the form by an ajax
call, the parameters are forcefully dealt by non-default action. So no
parameter validation within the catalyst action where the form is
defined.

Rippl, Steve

unread,
Sep 11, 2012, 12:58:19 PM9/11/12
to formh...@googlegroups.com
On Tue, Sep 11, 2012 at 9:53 AM, Sungsam Gong <gong.s...@gmail.com> wrote:
What I meant is that after an initial loading of the form by an ajax
call, the parameters are forcefully dealt by non-default action. So no
parameter validation within the catalyst action where the form is
defined.

Why aren't you pointing the action back to the URL where the form was defined?  If for some reason you have to process it elsewhere you can still pull in the form and run process there can't you?

 

Sungsam Gong

unread,
Sep 12, 2012, 5:32:49 AM9/12/12
to formh...@googlegroups.com
That's true; $form->process can be pulled and called where the action
is defined.
Reply all
Reply to author
Forward
0 new messages