thanks for sharing the code. Here's my take...

On Thursday, August 14, 2003, at 09:16 AM, Bill McCormick wrote:

..

Here are the key parts:

Some HTML template looks like this ...

<form id=new_data_form name=new_data_form method=post
action=myapp.cgi?rm=new_data>
<input type=hidden name="rm" value="add_record">
<input type=hidden name="param1">
<input type=hidden name="param2">
</form>

<form id=edit_data_form name=edit_data_form method=post
action=myapp.cgi?rm=edit_data>
<input type=hidden name="rm" value="edit_record">
<input type=hidden name="param1">
<input type=hidden name="param2">
</form>


in both instance above, you have a url variable (rm) on form action, and you also are passing the same variable as a hidden field. Why both? I see this commonly. Pass one or the other... in fact, in case of forms, don't use url variables at all... just use <input type="hidden" name="rm" value=whatever value> and make the action really simple such as <form ... action="myapp.cgi">. If, for some reason, you want to see the variables in the url, make method="get", but that is messy...



<form id=instant_update_form name=instant_update_form method=post
action=myapp.cgi>
<input type=hidden name="rm" value="display">
<input type=hidden name="param1">
<input type=hidden name="param2">
<input type=hidden name="param3">
</form>

<form id=main_form name=main_form method=post action=myapp.cgi>

SOME HTML::Template structure here

with ...

        <input type=text name="param3">
        onClick="javascript:add_record()"

....

and so on

</form>

And the Javascript ....

function add_record()
{
  var my_form;
  var somevar;

  my_form = this.document.forms['new_data_form'];
  somevar = this.document.forms['main'].param3.value;

  my_form.param1.value = "add";
  my_form.param3.value = somevar; /* this is where it happens */
  my_form.submit();
}

and so on for other main display form functions.

Then in the next form, on submit, pass all the cgi params back to
myapp.cgi?rm=display and finally process.

this is another common usage that puzzles me... form widgets were designed to submit forms... I often see folks using Javascript to submit forms. Unless there is something you are changing on the client side interactively, this is pointless... just overhead noise. My philosophy is to keep things as simple as possible and use them mostly for what they are designed -- less chance of breakage.


Here is a simple way of doing this...

in your template, for example, in the edit form...

<form name="myform" action="myapp.cgi" method="post">
        blah blah blah
        <input type="submit" name="action" value="Edit">
</form>

and then in your script...

my $action = param('action'); # assuming you are use-ing CGI.pm
if ($action eq 'Edit') {
        ... edit code ...
} elsif ($action eq 'Delete') {
        ... delete code ...
} elsif ($action eq 'Add') {
...
...
you get the idea

There can be many variations on the above... a simple way is to create separate templates for each of the actions, changing the value of <input type="submit" name="action" value=???> in each template appropriately.

Anyway... thanks for sharing your ideas.



-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to