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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing manually a subroutine 1

Status
Not open for further replies.

Perlwannabe

Technical User
Mar 7, 2006
57
IT
Hi,

Here is the problem:
Assuming that I have a subroutine called "send",Could I execute it manually,by means of a html button?

Code:
<input type="button" value="Send" onclick="send">

Or should I do something else?

Thanks for your help

Sincerely
 
isn't this a javascript question? using on click?

If you want to run a PERL script called 'send' you either post the form to it or call it with get variables.

onlcik="window.location='


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
whoops I missed out href in that post and a few typo's...
Code:
onclick="window.location.[b]href[/b]='[URL unfurl="true"]http://www.yourdomain.com/pathtoscripts/send.cgi?var1=val1&amp;var2=val2";[/URL]

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Thanks for your reply 1DMF.

Well,

I have a script that has in it a subroutine that allows an user to submit an url in a form and get automatically a confirmation mail:that subroutine is called "addurl";
What I would to do is to break it, separating the submission part from the mailing one,creating two separate subroutines:"addurl" and just "send";
Then I would execute "send" manually as explained;
Could I do it?

Here is the complete subroutine code:
Thanks for any helpful hint.

Code:
sub addurl {
	&heading;
	$noshow = 1;
	unless ($FORM{'url'} =~ /http:\/\//) {
		&submiterror;
	}

	if ($FORM{'url'} eq "" || $FORM{'title'} eq "" || $FORM{'email'} eq "" || $FORM{'description'} eq "" || $FORM{'keywords'} eq "") {
		&empty;
	}

	unless (open (DATA,"$base")) {die (&error);}
	if ($uselock eq '1') {
		flock DATA, 2;
		seek DATA, 0, 0;
	}
	@input = <DATA>;
	if ($uselock eq '1') {
		flock DATA, 8;
	}
	close (DATA);
	$entries = @input;

	$urlsearch = "$FORM{'url'}"."::";
	$urltemp = $FORM{'url'};
	chomp($urltemp);
	chop($urltemp);
	$urlsearchtwo = "$urltemp"."::";
	$urlsearchthree = "$FORM{'url'}"."/::";
	$currentline = 0;
	until ($currentline == $entries) {
		if ($input[$currentline] =~ /$urlsearch/i) {
			&exists;
		}
		if ($input[$currentline] =~ /$urlsearchtwo/i) {
			&exists;
		}
		if ($input[$currentline] =~ /$urlsearchthree/i) {
			&exists;
		}
		++$currentline;
	}  

	$testline = $input[$currentline-1];
	$testline2 = $input[$currentline-2];
	$testline3 = $input[$currentline-3];
	$testline4 = $input[$currentline-4];
	$testline5 = $input[$currentline-5];
	$testline6 = $input[$currentline-6];
	$testline7 = $input[$currentline-7];
	$testline8 = $input[$currentline-8];
	$testline9 = $input[$currentline-9];
	$testline10 = $input[$currentline-10];

	if ($testline =~ /$FORM{'description'}/) {
		&samestuff;
	}

	if ($testline =~ /$FORM{'title'}/) {
		&samestuff;
	}

	if ($testline =~ /$FORM{'keywords'}/) {
		&samestuff;
	}

	if ($testline =~ /$FORM{'email'}/i || $testline2 =~ /$FORM{'email'}/i || $testline3 =~ /$FORM{'email'}/i || $testline4 =~ /$FORM{'email'}/i || $testline5 =~ /$FORM{'email'}/i || $testline6 =~ /$FORM{'email'}/i || $testline7 =~ /$FORM{'email'}/i || $testline8 =~ /$FORM{'email'}/i || $testline9 =~ /$FORM{'email'}/i || $testline10 =~ /$FORM{'email'}/i) {
		&justsubmitted;
	}

	$newemail = $FORM{'email'};
	if ($FORM{'send'} ne "on") {
		$newemail = "X"."$newemail"."X";	
	}
	$newtitle = substr($FORM{'title'},0,$maxtitle);
	$newdesc = substr($FORM{'description'},0,$maxdescription);
	$newkeywords = substr($FORM{'keywords'},0,$maxkeywords);
	$line = join ("::","$FORM{'url'}","$newtitle","$newkeywords","$newemail","$newdesc");

	unless (open (DATA,">>$base")) {die (&error);}
		if ($uselock eq '1') {
			flock DATA, 2;
			seek DATA, 0, 2;
		}
		print DATA "$line\n";
		if ($uselock eq '1') {
			flock DATA, 8;
		}
	close (DATA);

	print "<center><HR WIDTH=400><FONT $font SIZE=3><b>Submission Received</b></font><p>\n";
	print "<FONT $font SIZE=2><B>The following submission has been received by $sitetitle :</B></font><br>\n";
	print "<table width=400><tr><td align=right><FONT $font SIZE=2><B>URL :</B></font></td>\n";
	print "<td><a href=\"$FORM{'url'}\"><FONT $font SIZE=2><b>$FORM{'url'}</b></font></a></td></tr>\n";
	print "<tr><td align=right><FONT $font SIZE=2><B>Title :</B></font></td><td><FONT $font SIZE=2> $FORM{'title'}</td></tr>\n";
	print "<tr><td align=right><FONT $font SIZE=2><B>Keywords :</B></font></td><td><FONT $font SIZE=2> $FORM{'keywords'}</td></tr>\n";
	print "<tr><td align=right><FONT $font SIZE=2><B>Description :</B></font></td><td><FONT $font SIZE=2> $FORM{'description'}</td></tr>\n";
	print "<tr><td align=right><FONT $font SIZE=2><B>E-mail :</B></font></td><td><FONT $font SIZE=2> $FORM{'email'}</font></td></tr></table></center><p>\n";
        print "<INPUT TYPE=button name=send></FORM></CENTER>\n";

	
}

#######HERE I WOULD BREAK IT CREATING "SEND":#########
# (sub send) 
        
if ($userespond eq '1') {
		unless (open (DATA,"$respondfile")) {die (&error);}
			if ($uselock eq '1') {
				flock DATA, 2;
				seek DATA, 0, 0;
			}
			@respondinfo = <DATA>;
			if ($uselock eq '1') {
				flock DATA, 8;
			}
		close (DATA);
		foreach $respondline (@respondinfo){
			$respondmessage = $respondmessage.$respondline;
		}

		open (MAIL, "|$mailprogram -t");
		print MAIL "To: $FORM{'email'}\n";
		print MAIL "From: $searchemail\n";
		print MAIL "Subject: Got it!\n\n";
		print MAIL "Welcome to $sitetitle!\n";
		print MAIL "We are located at $searchurl\n\n";
		print MAIL "YOUR SUBMISSION:\n";
		print MAIL "------------------------------------------------------------------\n";
		print MAIL "URL : $FORM{'url'}\n"; 
		print MAIL "Title : $FORM{'title'}\n";
		print MAIL "Description : $FORM{'description'}\n";
		print MAIL "Keywords : $FORM{'keywords'}\n";
		print MAIL "E-mail : $FORM{'email'}\n";
		print MAIL "------------------------------------------------------------------\n\n";
		print MAIL "$respondmessage";
		print MAIL "------------------------------------------------------------------\n\n";
		print MAIL "Thanks again,\n";
		print MAIL "---------------------------------------------\n";
		print MAIL "$sitetitle\n";
		print MAIL "$searchemail\n";
		print MAIL "$searchurl\n";
		print MAIL "---------------------------------------------\n";
		print MAIL "Powered by :\n";
		print MAIL "";
		print MAIL "http";
		print MAIL "---------------------------------------------\n";
		close (MAIL);
	}
	&footer;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top