Re: Taking Multiple Values for The Same Form Field.

2005-10-29 Thread Ovid
--- Sara [EMAIL PROTECTED] wrote:

 Thanks for the quick respons, just need a bit more help. Now I need
 to write 
 these values in a text file (I am fully aware of writing to files)
 but where 
 I am gettin' confused is that : I told you that Name is a required
 field, 
 but Email is optional. so what if :
 
 my @name = ('Sara', 'John', 'Doe'); # 3 names coming from form.
 my @email = ('[EMAIL PROTECTED]'); # coming from form as Email Optional
 field is 
 ONLY filled for John.
 
 The problem is $name[0] does not corresponds with $email[0] and so
 on 
 Otherwise I would have used while or foreach for @name and @email to
 write 
 it to file like it:

As of CGI.pm version 2.63, if the name is supplied in the query string
but has no value, CGI.pm should return an empty string for that.  This
should let you keep your @name and @email arrays in synch.  Even if you
are using a POST, there should be a query string in the entity-body and
CGI.pm *should* handle this correctly.

Cheers,
Ovid

-- 
If this message is a response to a question on a mailing list, please send
follow up questions to the list.

Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Taking Multiple Values for The Same Form Field.

2005-10-29 Thread Randal L. Schwartz
 Ovid == Ovid  [EMAIL PROTECTED] writes:

Ovid As of CGI.pm version 2.63, if the name is supplied in the query string
Ovid but has no value, CGI.pm should return an empty string for that.  This
Ovid should let you keep your @name and @email arrays in synch.  Even if you
Ovid are using a POST, there should be a query string in the entity-body and
Ovid CGI.pm *should* handle this correctly.

... unless the browser is returning only one email value (because the
other two are not touched), which is quite possible.

If you need to correlate fields, use distinct names:

name1   email1
name2   email2
name3   email3

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Taking Multiple Values for The Same Form Field.

2005-10-29 Thread Wiggins d'Anconia

Bob O'Neill wrote:

Use list context:

  my @names = $q-param('name');

Cheers,
Ovid



I've found this thread very helpful, and have changed it to use Vars (from  
http://users.easystreet.com/ovid/cgi_course/) as I need a hash.  This has 
replaced the following:


foreach $entry (param()) {
$fieldhash{$entry}=param($entry);

Checkentry(param($entry));
}

with:

my $q=new CGI;
my %fieldhash=$q-Vars;

which is much neater.  My subroutine Checkentry untaints the input.  Is 
there an easier way which will allow the hash values created by Vars to be 
passed to my subroutine without stepping through a foreach loop? 



If I understand correctly then you want a hash reference to pass the 
whole hash around at once.


perldoc CGI

Should help, CVars understands its context, so calling it in scalar 
context will result in it returning a hashref instead of a hash.


my $params_ref = $q-Vars;

http://danconia.org



Bob





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response