<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1016569" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1016569</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/make-all-form-fields-required#comment-1096361</link>
    <description> &lt;p&gt;Thanks Wil,&lt;/p&gt;
&lt;p&gt;I&#039;ll try this as soon as I can...And then let you know...&lt;/p&gt;
 </description>
     <pubDate>Sat, 15 Dec 2001 21:04:52 +0000</pubDate>
 <dc:creator>rline</dc:creator>
 <guid isPermaLink="false">comment 1096361 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/make-all-form-fields-required#comment-1096355</link>
    <description> &lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I&#039;m not laughing at all! Jeepers, I&#039;m not an expert by a long shot! Well all have to start somewhere. You&#039;ve done a good job, thus far. Let me try and give you some advice...&lt;/p&gt;
&lt;p&gt;Regarding &quot;use CGI&quot; and &quot;use CGI.pm&quot;. I&#039;ll tell you why you should use the first and not the last example. &quot;pm&quot; stands for &quot;P&quot;erl &quot;M&quot;odule. They are all stored in a special directory in the Perl distribution. Perl knows to go looking here for modules by default. You can also define more directories for Perl to go looking for modules. Because Perl knows that what you&#039;re trying to &quot;use&quot; is a perl module, and it knows where to look so it doesn&#039;t need an exact file name/extension. Therefore, you just omit the file extension, and type whatever is before the period.&lt;/p&gt;
&lt;p&gt;OK. I&#039;ve tried to re-write your script a little. What you&#039;re doing wrong is that you&#039;re checking for empty variables before the variables actually gets passed to the script. Therefore there is no such variables defined for them to be empty or not, so Perl doesn&#039;t do anything with that loop. &lt;/p&gt;
&lt;p&gt;Because you&#039;re already using CGI.pm, I&#039;ll change some code for you as well. You don&#039;t need to split variables passed to your form yourself as CGI.pm does a good job of that for you too. Here&#039;s what I would write instead.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;#!/usr/bin/perl&lt;br /&gt;&lt;br /&gt;&amp;nbsp; use CGI;&lt;br /&gt;&amp;nbsp; $query = CGI::new();&lt;br /&gt;&lt;br /&gt;&amp;nbsp; # This imports everything passed to the script &lt;br /&gt;&amp;nbsp; # into the name space &amp;#039;q&amp;#039;.&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; $query-&amp;gt;import_names(&amp;#039;q&amp;#039;);&lt;br /&gt;&lt;br /&gt;&amp;nbsp; if ($ENV{&amp;#039;QUERY_STRING&amp;#039;}) &lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach $name ($query-&amp;gt;param) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; my $value = $query-&amp;gt;param($name);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!$value) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; die (&amp;quot;Required field $name left blank&amp;quot;);&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Here you can acccess all variable name/value pairs.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # I might as well print them all for you.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;quot;$name=$value\n&amp;quot;;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Or you can access all your variables by using &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # $q::var_name or @q::array_name if it was an array.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # This is handy if you know the variable name and you&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # need to access it&amp;#039;s value.&lt;br /&gt;&amp;nbsp; }		&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Hope this helps.&lt;/p&gt;
 </description>
     <pubDate>Sat, 15 Dec 2001 18:00:17 +0000</pubDate>
 <dc:creator>Wil</dc:creator>
 <guid isPermaLink="false">comment 1096355 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/make-all-form-fields-required#comment-1096292</link>
    <description> &lt;p&gt;Hey thanks Wil,&lt;/p&gt;
&lt;p&gt;Your &quot;lazy&quot; method is definitely what I need, as there are over 100 fields in the form (it&#039;s for someone else, not me...I would never have such a huge form). And I am using perl.&lt;/p&gt;
&lt;p&gt;I&#039;m not completely up with CGI.pm, so I&#039;ll tell you what I put where, and then maybe you might tell me why it didn&#039;t work.&lt;/p&gt;
&lt;p&gt;Up the top, below the shebang is use CGI; (I tried use CGI.pm;, but this gave an internal server error)&lt;br /&gt;
Then, after a few variables are defined, I have &lt;/p&gt;
&lt;p&gt;$query = new CGI();&lt;br /&gt;
foreach ($query-&amp;gt;param) {&lt;br /&gt;
    if (!$_) {&lt;br /&gt;
      die (&quot;Required field $_ left blank&quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;/p&gt;
&lt;p&gt;Then, I have the code which gets the form values. I suspect this might be part of the problem, and please don&#039;t laugh too hard if the combined code is ridiculous. I&#039;m looking forward to your help! Here it is:&lt;/p&gt;
&lt;p&gt;if ($ENV{&#039;QUERY_STRING&#039;})		# using form-&amp;gt;get method&lt;br /&gt;
	{&lt;br /&gt;
	@pairs = split(/\&amp;amp;/,$ENV{&#039;QUERY_STRING&#039;});&lt;br /&gt;
	}&lt;br /&gt;
elsif ($ENV{&#039;CONTENT_LENGTH&#039;})		# using form-&amp;gt;post method&lt;br /&gt;
	{&lt;br /&gt;
	read(STDIN, $buffer, $ENV{&#039;CONTENT_LENGTH&#039;});&lt;br /&gt;
	@pairs = split(/&amp;amp;/, $buffer);&lt;br /&gt;
	}&lt;/p&gt;
&lt;p&gt;undef @send;&lt;br /&gt;
undef @send_values;&lt;/p&gt;
&lt;p&gt;foreach $pair (@pairs)&lt;br /&gt;
	{&lt;br /&gt;
	($name, $value) = split(/=/, $pair);&lt;br /&gt;
	$value =~ tr/+/ /;&lt;br /&gt;
	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;&lt;br /&gt;
	$value =~ s/~!/ ~!/g;&lt;/p&gt;
&lt;p&gt;		push @send, $name;&lt;br /&gt;
		push @send_values, $value;&lt;br /&gt;
		$FORM{$name} = $value;&lt;br /&gt;
	}&lt;/p&gt;
&lt;p&gt;Anyway, at present, there are no errors, but when I submit the form with nothing filled in, it just goes through without giving me any error messages. I&#039;m sure you know why...Thanks a lot.&lt;/p&gt;
 </description>
     <pubDate>Fri, 14 Dec 2001 23:17:19 +0000</pubDate>
 <dc:creator>rline</dc:creator>
 <guid isPermaLink="false">comment 1096292 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/make-all-form-fields-required#comment-1096240</link>
    <description> &lt;p&gt;Tell us what programming language you are using?&lt;/p&gt;
&lt;p&gt;In Perl, you would either pre-define your vars, arrays or whatever data structure you are passing to your script and then do a simple test:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;my @required = ($foo,$bar,@foobar...);&lt;br /&gt;&lt;br /&gt;&amp;nbsp; foreach @required {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!$_) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; die (&amp;quot;Required field $_ left blank&amp;quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; }&lt;/code&gt;&lt;/div&gt;&#039;&lt;br /&gt;
If you&#039;re lazy and you don&#039;t want to define all your required form fields before hand, use the query param function of CGI.pm to obtain the entire paramater list passed to the script.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&amp;nbsp; foreach ($query-&amp;gt;param) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!$_) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; die (&amp;quot;Required field $_ left blank&amp;quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; }&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Hope this helps.&lt;/p&gt;
 </description>
     <pubDate>Fri, 14 Dec 2001 09:54:57 +0000</pubDate>
 <dc:creator>Wil</dc:creator>
 <guid isPermaLink="false">comment 1096240 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/make-all-form-fields-required#comment-1096226</link>
    <description> &lt;p&gt;Any options for programing languages used, php, asp, perl ...?&lt;/p&gt;
 </description>
     <pubDate>Fri, 14 Dec 2001 07:35:55 +0000</pubDate>
 <dc:creator>Busy</dc:creator>
 <guid isPermaLink="false">comment 1096226 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
