Gossamer Forum
Home : Products : DBMan : Customization :

running a sub script with a button

Quote Reply
running a sub script with a button
Hi,

this time, I need to run a sub script, when a button is pressed. I've tried multiple versions of the code, but my perl skills are limited, and I can't find the solution. Please help!

The button should go in sub html_add_success and sub html_modify_success, just after the |; &html_record_long(&get_record($in{$db_key})); print qq| -line. If I put this: &html_save_server; the script (create_file_and_send_email_mod - without the mailsend) works just fine - BUT, I need to run it only when the (damn :) ) button is pressed.

Maybe the code is something like this:

<form action=" ???? " method="POST">
<INPUT class="input_1y" TYPE="SUBMIT" NAME="html_save_server" VALUE="Save">
</form>

maco
Quote Reply
Re: [maco] running a sub script with a button In reply to
I found this mod, but I still can't make it work...(even with a text link) Unsure

http://webmagic.hypermart.net/...n/db/text/link24.txt
Quote Reply
Re: [maco] running a sub script with a button In reply to
So you needed to do at least 3 things;

1. modify db.cgi near the top so that a variable passed to it in the URL causes execution of the right sub.

2. make a sub that works (I start with a working sub, rename it, then make sure I can execute it).

3. build a URL (or form button) that passes the variable as per number 1 above.

If you have done all these, then you need to provide more info.
Quote Reply
Re: [joematt] running a sub script with a button In reply to
OK.

I got this in db.cgi / sub main:
Code:
elsif ($in{'save_server'}) { if ($per_view) { &html_save_server; } else { &html_unauth; } }


This in html.pl:

Code:
sub html_save_server {
# --------------------------------------------------------

$newfile = "$in{'Userid'}-$in{'ID'}.html"; # Name of file to be created.


open(HTM, ">/***/***/***/HTML/arm/$in{'Userid'}/$newfile") or die "This is the error: $!\n";

select (HTM);

print HTM qq|
<html><head>

....


</body>
</html>
|;

close(HTM);
}


And this (at the moment) in html_add_success:

Code:
|; &html_record_long(&get_record($in{$db_key})); print qq|
</font></p>
<a href="$db_script_url?db=item&uid=$db_uid&save_server=1">save</a>
|; &html_footer; print qq|

Last edited by:

maco: Apr 2, 2003, 3:44 AM
Quote Reply
Re: [maco] running a sub script with a button In reply to
Thanks for the info.

I believe that because you are presenting the link to save after after the record is displayed, you would need to specify the search terms again in the URL that does the saving.

I read this link and find that they are saying to write the file as soon as it is displayed in html_add_success while it seems like you want to display the record in html_add_success then give the user the option to write the file.

I'm not sure you can make a post with your button without clearing the $in ???

SO, without better comments from the better programers, I would say ....

Let the file get written as part of html_add_success, then give the user a chance to delete the record using the button.

-or-

Include enough hidden search terms in the save button to find the right record and write it.

Hey, I think I learned something.
Quote Reply
Re: [joematt] running a sub script with a button In reply to
Hi joematt,

I'm not sure what you are suggesting, but the problem is not finding the right record - it's making the button to run the sub script.

I give an example: I added a checkbox in the html_record_form, which name is save_to_server and when checked, it returns text 'save'. Then I replaced this (in sub html_add_success) :

|; &html_record_long(&get_record($in{$db_key})); print qq|
</font></p>
<a href="$db_script_url?db=item&uid=$db_uid&save_server=1">save</a>
|; &html_footer; print qq|

To this:

|; &html_record_long(&get_record($in{$db_key})); print qq|
</font></p>
|; if ($rec{'save_to_server'} eq 'save') { &html_save_server; }
&html_footer; print qq|

And it works, the page is saved on the server when checkbox is checked. Only one little thing is missing from the 'Record Added' titled page, the html_footer ?? This happens also, if I put a direct link to the sub script, like this:

|; &html_record_long(&get_record($in{$db_key})); print qq|
</font></p>
|; &html_save_server; &html_footer; print qq|

And with the original text-link. Why? Is there something missing in the sub html_save_server, which gives the command to return to the sub html_add_success, and complete the script (=&html_footer) ?

But the original problem stays too, how do I run the script with a button?

Crazy
Quote Reply
Re: [maco] running a sub script with a button In reply to
Quote:
But the original problem stays too, how do I run the script with a button?

The button, or any link, will restart the db.cgi, thus resetting the $in variables, thus the button must send enough information for db.cgi to find the record and to know what to do with it.

To put it another way, once db.cgi has returned the output, the $in values are lost. It cannot hold them waiting for the user to pust the button. What would happen if a different user made a search while the first user was waiting to push the button? Who's $in would you get?

If I am wrong here, let me know, anybody.

So if you can build a button that finds the record, you can make that button save the record as well by adding to the button the save_server='save'.

Regarding returning from html_save_server to html_footer;

It should not need a return, it should go back to where it came from, unless the previous sub is missing a ending }

or something is misspelled ????

did you move html_footer into a format.pl file or some other file?

You are very close, keep at it.Smile
Quote Reply
Re: [joematt] running a sub script with a button In reply to
In Reply To:
The button, or any link, will restart the db.cgi, thus resetting the $in variables, thus the button must send enough information for db.cgi to find the record and to know what to do with it.

To put it another way, once db.cgi has returned the output, the $in values are lost. It cannot hold them waiting for the user to pust the button. What would happen if a different user made a search while the first user was waiting to push the button? Who's $in would you get?



It should not need a return, it should go back to where it came from, unless the previous sub is missing a ending }

or something is misspelled ????

did you move html_footer into a format.pl file or some other file?

You are very close, keep at it.Smile


Now I'm beginning to understand the problem, thanks for explaining. I'm gonna do this in other way, because I'm running out of time.

I was thinking, that the checkbox version of the save_server, is actually not bad at all. Let's say that the user is creating a new record. He/she fills part of the input fields (count is now 425 :) ), and stops for the day. He uses the button 'Add record' and log's off. Next day the user finish the filling (modify) and decides that the record is complete. Then he checks the save_server checkbox and uses the 'Modify Record' button. The record is updated in the database, and also stored in the server for the public to see. If user needs to modify the record once again, the checkbox is still checked, so he doesn't have to remember to change (or press a button) anything. Not bad, huh?

The html_footer is like it was in the original code - the only thing I have added is the Who's Online mod, and that is working fine. And I can't find any missing } from sub scripts ? Can the problem lie in the actual code of the html_save_server?? Well, I have to check the code once again...
Quote Reply
Re: [maco] running a sub script with a button In reply to
Hi!

I have triple checked everything, but still can't make the footer to work after running the html_save_server sub script - it stays hidden. Please help!

maco