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

small problem

Status
Not open for further replies.

Zas

Programmer
Oct 4, 2002
211
0
0
US
what is the best way to tell the user that they need to go back, and fill out the form, and exit the script, if i have NOT filled out print "Content-type:text/html\n\n"; yet.

The problem is I donot want to set my cookies unless I know for sure everything will work. But I cannot do that, unless I tell the user not too.

So whats the best way?

if (...
 
Is it server side, or client side validation that's required?

P
 
server side i believe--

i need to make that $INPUT{'variable'} is not null.
if it is, close and tell them to go BACK. if its not, continue.

by the way, thanks for the quik response.
 
When you say $INPUT{'variable'}, I assume you're parsing a string of variables into a hash called %INPUT?

If all you need to do is validate for non nulls, include a small JavaScript snippet to check that any nulls are replaced with default variables
Code:
<FORM name=&quot;fred&quot; onSubmit=&quot;ValidateForm(this)&quot; action=&quot;yourscript.pl&quot; method=&quot;POST&quot;>

Your Form HTML here

Code:
function ValidateForm(theForm)
{ if (theForm.[variable name].value=&quot;&quot;)
   {
     theForm.[variable name].value=&quot;Fredcozthatzthedefault&quot;
   }
.
.
.
return (true)
}

HTH Paul
 
cool. so thats xml or something?

i'll try it out after school
 
Why not this?
Code:
use CGI qw/:standard/;

if(param('variable' =~ /criteria/){
   $cookie = cookie(-name=>'sessionID',
			     -value=>'xyzzy',
			     -expires=>'+1h',
			     -path=>'/cgi-bin/database',
			     -domain=>'.yours.com',
			     -secure=>1);
    print header(-cookie=>$cookie);  
    print header();
    }
}
else{
   print header();
   print &quot;Please click back and fill in form<br>\n&quot;;
   exit;
   }

That's skeleton and bones, and untested, but do you get the idea?

--jim
 
OOPS!!

If you need a specific value you can pop an alert (Message Dialog) saying the value cannot be blank, or any other validation rules that can be performed in the browser, and set the variable.value=&quot;&quot;; return(false);

PS excuse the syntax, as I was typing on the lamb;

HTH

Paul
 
Zas,

It's JavaScript for the client side before it hits the server;

I know JS isn't a subject here, but it takes a bit of woirk off the server.

Jim - apologies for cutting across your post - simult typing


Paul
 
Wow. Thanks for the tips.

Gotta eat, I'll let you know how it turns out later.
 
so:

<FORM name=&quot;fred&quot; onSubmit=&quot;ValidateForm(this)&quot; action=&quot;yourscript.pl&quot; method=&quot;POST&quot;>


Your Form HTML here

ÿ
function ValidateForm(theForm)
{ if (theForm.varname.value=&quot;&quot;)
{
theForm.varname.value=&quot;whatdoiputhere&quot;
}
.
.
.
return (false)
}


do i need &quot;ÿ&quot;, where do i put the message pop up? i'm sorry i know nothing of java script.

and---
is there a way to make sure that $npass is equal to $npass2, and if not, error and stop the script?

please reply...
 
and is <FORM name=&quot;fred&quot; onSubmit=&quot;ValidateForm(this)&quot; action=&quot;yourscript.pl&quot; method=&quot;POST&quot;> actually have &quot;(this)&quot; in it?
 
Yes, you need &quot;&quot; and (this) in your script. To make a message pop up, use
Code:
alert(&quot;whatever you want it to say&quot;);
You might want to check out a javascript tutorial, as there are plenty out there.
 
function ValidateForm(theForm)
{ if (theForm.varname1.value!=theForm.varname2.value)
{
theForm.varname1.value=&quot;&quot;;
alert(&quot;Variables are not equal&quot;);
theForm.varname1.focus();
return (false);
}
return (true)
}
 
shouldn't i really have the <script> js thing at the top and bottom?
 
I donot know whats wrong-
neither of the scripts work.

<script language=&quot;JavaScript&quot;>
function ValidateForm(theForm)
{ if (theForm.npass.value=&quot;&quot;; return(false);)
{
theForm.npass.value=&quot;Fredcozthatzthedefault&quot;
alert(&quot;Variables are not filled out&quot;);
}
.
.
.
return (false)
}
</script>

<script language=&quot;JavaScript&quot;>
function ValidateForm(theForm)
{ if (theForm.npass.value!=theForm.npass2.value)
{
theForm.npass.value=&quot;&quot;;
alert(&quot;Variables are not equal&quot;);
theForm.npass.focus();
return (false);
}
return (true)
}
</script>

dont work.
 
and:
use CGI qw/:standard/;
$cookie = cookie(-name=>'name',
-value=>'$cid',
-expires=>'+1h',
-path=>'/cgi-bin/user/',
-secure=>1);
print header(-cookie=>$cookie);
print header();

ends up on the page:

Set-Cookie: name=%24cid; path=/cgi-bin/user/; expires=Fri, 25-Oct-2002 14:24:03 GMT; secure Date: Fri, 25 Oct 2002 13:24:03 GMT Content-Type: text/html; charset=ISO-8859-1 Content-Type: text/html; charset=ISO-8859-1

i need something could set cookies after the content, without printing &quot;Cookie = NAME $CID&quot; etc..
 
Zas, try this one, apologies to anyone who takes offence for posting non-perl in this forum!!!
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html lang=&quot;en&quot;>
<head>
<title>Your Title</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>

</head>
<body>
<SCRIPT language=JavaScript>
<!--
function FormValidator(theForm)
{  if (theForm.Name.value == &quot;&quot;)
  { alert(&quot;Please enter a value for the \&quot;Name\&quot; field.&quot;);
    theForm.Name.focus(); return (false);
  }
  if (theForm.Name.value.length < 3)
  { alert(&quot;Please enter at least 3 characters in the \&quot;Name\&quot; field.&quot;);
    theForm.Name.focus(); return (false);
  }
  if (theForm.Country.value.length == &quot;&quot;)
  {alert(&quot;Please enter your country in the \&quot;country\&quot; field.&quot;)
   theForm.Country.focus();return (false);
  }
  if (theForm.Email.value == &quot;&quot;)
  { alert(&quot;Please enter a value for the \&quot;Email\&quot; field.&quot;);
    theForm.Email.focus();return (false);
  }
  if (theForm.Email.value.length < 5)
  { alert(&quot;Please enter at least 5 characters in the \&quot;Email\&quot; field.&quot;);
    theForm.Email.focus();return (false);
  }
  var atPresent=-1;
  var i=0;
  for (i=0;i<theForm.Email.value.length; i++)
  {
  	if (theForm.Email.value.charCodeAt(i)==64)
  	  {
  		atPresent=i;
  	  }
  }
  if (atPresent == -1)
    { alert(&quot;Your email address does not contain the \@ symbol\nPlease amend this issue before continuing&quot;);
      theForm.Email.focus();return(false);
    }
  return (true);
}
//--></SCRIPT>
<FORM name=email_Form1 onsubmit=&quot;return FormValidator(this)&quot; action=&quot;/cgi-bin/myscript.pl&quot; method=&quot;post&quot;>
      <center>
      <TABLE border=0>
        <TBODY>
        <TR>
          <TD align=right><label for=&quot;_name&quot;><p><EM>Name*</EM></label></TD>
          <TD><INPUT size=&quot;35&quot; name=&quot;Name&quot; id=&quot;_name&quot;></TD>
        </TR>
        <TR>
          <TD align=right><label for=&quot;_title&quot;><p><EM>Title</EM></label></TD>
          <TD><INPUT size=&quot;35&quot; name=&quot;Title2&quot; id=&quot;_title&quot;></TD></TR>
        <TR>
          <TD align=right><label for=&quot;_company&quot;><p><EM>Company</EM></label></TD>
          <TD><INPUT size=&quot;35&quot; name=&quot;Company&quot; id=&quot;_company&quot;></TD></TR>
        <TR>
          <TD align=right valign=&quot;top&quot;><label for=&quot;_address&quot;><p><EM>Address</EM></label></TD>
          <TD><TEXTAREA name=&quot;Address&quot; rows=&quot;5&quot; cols=&quot;39&quot; id=&quot;_address&quot;></TEXTAREA></TD>
        </TR>
        <TR>
          <TD align=&quot;right&quot;><label for=&quot;_country&quot;><p><EM>Country*</EM></label></TD>
          <td><input size=&quot;35&quot; name=&quot;Country&quot; type=&quot;text&quot; id=&quot;_country&quot;></td>
        </TR>
        <TR>
          <TD align=right><label for=&quot;_email&quot;><p><EM>E-mail*</EM></TD>
          <TD><INPUT size=&quot;35&quot; name=&quot;Email&quot; id=&quot;_email&quot;></TD>
        </TR>
        <TR>
          <TD align=right><label for=&quot;_phone&quot;><p><EM>Phone</EM></label></TD>
          <TD><INPUT size=&quot;35&quot; name=&quot;Phone&quot; id=&quot;_phone&quot;></TD>
        </TR>
        <TR>
          <TD align=right><label for=&quot;_fax&quot;><p><EM>Fax</EM></label></TD>
          <TD><INPUT size=&quot;35&quot; name=&quot;Fax&quot; id=&quot;_fax&quot;></TD>
        </TR>
        <TR>
          <TD align=right valign=&quot;top&quot;><label for=&quot;_comments&quot;><p><EM>Comments<BR>or<BR>Requests</EM></label></TD>
          <TD><TEXTAREA name=&quot;Comments&quot; rows=&quot;5&quot; cols=&quot;39&quot; id=&quot;_comments&quot;></TEXTAREA></TD>
        </TR>
        <TR>
          <TD COLSPAN=&quot;2&quot; ALIGN=&quot;RIGHT&quot;><INPUT type=&quot;image&quot; value=&quot;Submit Form&quot; img src=&quot;submit.gif&quot; name=&quot;submit&quot; alt=&quot;Click here to process your request&quot;></TD>
        </tr>
      </TBODY>
    </TABLE>
 </center>
</FORM>
</BODY>
</HTML>
 
ok- this works:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html lang=&quot;en&quot;>
<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html&quot;; charset=&quot;iso-8859-1&quot;>
</head>

<body>
<SCRIPT language=JavaScript>
<!--
function FormValidator(theForm)
{
if (theForm.npass.value == &quot;&quot;)
{ alert(&quot;Please enter a value for the \&quot;npass\&quot; field.&quot;);
theForm.npass.focus(); return (false);
}

if (theForm.Name.npass.length < 3)
{ alert(&quot;Please enter at least 3 characters in the \&quot;npass\&quot; field.&quot;);
theForm.npass.focus(); return (false);
}

if (theForm.npass2.value == &quot;&quot;)
{ alert(&quot;Please enter a value for the \&quot;npass2\&quot; field.&quot;);
theForm.npass2.focus(); return (false);
}

if (theForm.opass.value == &quot;&quot;)
{ alert(&quot;Please enter a value for the \&quot;opass\&quot; field.&quot;);
theForm.opass.focus(); return (false);
}

return (true);
}
//--></SCRIPT>

<Form method=post onsubmit=&quot;return FormValidator(this)&quot; action=$rootdir/cgi-bin/user/prefchangep.pl>
<br>New Password:
<label for=&quot;_npasso&quot;><Input name=npass id=&quot;_npass&quot; size=30 maxlength=15>
<br>New Password Again:
<label for=&quot;_npass2&quot;><Input name=npass2 id=&quot;_npass2&quot; size=30 maxlength=15>
<br>Old Password:
<label for=&quot;_opass&quot;><Input name=opass id=&quot;_opass&quot; size=30 maxlength=15>
<br>
<br><INPUT type=submit value=&quot;Change Password&quot;><INPUT type=reset value=&quot;Reset Password&quot;>
</form>

in html....


but i need it to work in perl/cgi
in other words if i use it in pref.html it works, but if i use it in pref.pl, it will not work.

since this is a perl form, how can i get it to work in perl?
 
Hi Zas,

When you say a Perl Form, do you mean a HTML form that is written by a Perl Script?

I use HTML forms to pass parameters to CGI scripts, and within the HTML use Javascript to validate that which can be validated independently of the browser.

If your talking about returning HTML from the server with similar characteristcs, ie alert boxes, focus on forms, you could generate the Javascript on the fly as you are preparing the HTML

eg build up header
build up script based on server side validation
build up footer (main form, with the correct variables already passed in, passed back out)

HTH
Paul
 
as in it is in &quot;perl.pl&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top