5 Replies - 1421 Views - Last Post: 22 March 2008 - 03:13 PM

#1 b_real   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 29-December 06

Form values

Posted 21 March 2008 - 10:17 AM

OK, this must be really simple, but im having a brain fug and I can't find anything on the internet to point me in the right direction:

HTML form Posting to a perl CGI script. CGI script does some validation. When form data fails, CGI script prints an html message saying why, and offers the user a link to go back to the form.

This is where the problem is - when the user clicks on the link to go back, all form data that has been entered is lost. If the user clicks the browsers 'back' button, form data is retained. But when the link is clicked to go back to the HTML form, all form data is lost.

Cheers
B_Real

Is This A Good Question/Topic? 0
  • +

Replies To: Form values

#2 KevinADC   User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: Form values

Posted 21 March 2008 - 12:03 PM

Thats not a problem, thats the normal behavior one would expect. You can code a "back" link that does the same thing as the back button.

<a href="java script: history.go(-1)">Back</a>


Or just adivse the users to click the back button to return to the form.

NOTE: remove the space this forum injects between "java" and "script" in the above code.

This post has been edited by KevinADC: 21 March 2008 - 12:05 PM

Was This Post Helpful? 0
  • +
  • -

#3 b_real   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 29-December 06

Re: Form values

Posted 21 March 2008 - 02:31 PM

View PostKevinADC, on 21 Mar, 2008 - 12:03 PM, said:

Thats not a problem, thats the normal behavior one would expect. You can code a "back" link that does the same thing as the back button.

<a href="java script: history.go(-1)">Back</a>


Or just adivse the users to click the back button to return to the form.

NOTE: remove the space this forum injects between "java" and "script" in the above code.


Can I embed that into a Perl subroutine, a la:

sub output_fail
{ chop($failedFields);
	$resultPage="<html><head>".
		"<title>There was a problem with your registration</title>".
		"</head><body>".
		"<h2>The following field was filled in incorrectly:</h2>".
		"<br><h3>$failedFields</h3></br>".
		"<br><h3>Please <a href="java script: history.go(-1)">".
		"go back and try again.</a></h3></br>".
		"</body></html>";
	print $resultPage;
}



I get the following error:

[Fri Mar 21 21:25:55 2008] [error] [client 127.0.0.1] [Fri Mar 21 21:25:55 2008] registration.pl: Bareword found where operator expected at /Applications/MAMP/cgi-bin/registration.pl line 112, near ""<br><h3>Please <a href="javascript", referer: http://localhost:8888/perl/registration.html



I tried declaring the script type in there too but more errors.
Was This Post Helpful? 0
  • +
  • -

#4 KevinADC   User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: Form values

Posted 21 March 2008 - 11:58 PM

That section of code you posted is not written correctly. Should be:

sub output_fail
{ chop($failedFields);
	print qq{<html><head>
<title>There was a problem with your registration</title>
</head><body>
<h2>The following field was filled in incorrectly:</h2>
<br><h3>$failedFields</h3></br>
<br><h3>Please <a href="java script: history.go(-1)">
go back and try again.</a></h3></br>
</body></html>};

}

Was This Post Helpful? 0
  • +
  • -

#5 b_real   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 29-December 06

Re: Form values

Posted 22 March 2008 - 07:21 AM

That works perfectly! The qq operator is well handy!

I was following a tutorial written in 1999 that used the original way I had it - printing out a variable that contains the html. Not entirely sure why its wrong tho - Guess it falls down when you want to add some javascript in there.

Thanks for your help Kevin, much appreciated.
Was This Post Helpful? 0
  • +
  • -

#6 KevinADC   User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: Form values

Posted 22 March 2008 - 03:13 PM

The reason it fails is there are a few syntax errors in the code you posted. Either the tutorial is bad or you didn't understand something.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1