Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to call perl subroutine from html form

Status
Not open for further replies.

michael12

Programmer
Sep 26, 2002
25
US
In html form, I can write <form method=post action=sample.pl>....</form>
How can I call a subroutine in &quot;sample.pl&quot; from this form?
It doesn't work if I write <form method=post action=sample.pl?subname>...</form>
 
You can add a hidden field to the form. When the form is submitted, use the value in an if...else statement. If the hidden field exists, go to the subroutine desired.

A method involving ?name=value is a query string and applies to method=&quot;get&quot;, not &quot;post.&quot; You could still apply the above suggestion to such, ?subroutine_trigger=call_sub_name. But better to make it a post, otherwise all form values will be carried in the query string in the browser window.

<form method=&quot;post&quot; action=&quot;sample.pl&quot;>
<input type=&quot;hidden&quot; name=&quot;subroutine_trigger&quot; value=&quot;call_sub_name&quot;>
</form>

if ($subroutine_trigger eq &quot;call_sub_name&quot;) {
&call_sub_one;
} else {
&call_sub_two;
}

Crystal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top