Gossamer Forum
Home : General : Perl Programming :

how to split an in a form... (HELP!)

Quote Reply
how to split an in a form... (HELP!)
Hi !

I would like to know if it is possible to print a file with options form a form.

The form should be:
<select size="1" name="option">
<option value="value0,value1,value2,value3,value4">1</option>
<select size="1" name="option">
<option value="value0,value1,value2,value3,value4">1</option>
<select size="1" name="option">
<option value="value0,value1,value2,value3,value4">1</option>

The script should split "value". I tried this but it prints only the last "option".

open (AFILE,">>$afile") &#0124; &#0124; print "Content-type: text/html\n\n cannot open $afile(r): $!\n";

foreach ($FORM{'option'}) {
($1,$2,$3,$4,$5)=split(/,/,$_);
print AFILE join "\|", $1,$2,$3,$4,$5,"\|\n";
}

close(AFILE);


Any suggestions?

Thanks very much.

Quote Reply
Re: how to split an in a form... (HELP!) In reply to
Yes, I don't know what you are doing with that form but you should have a multple select field or use radio buttons instead. But this will still work. You also need to close your <select> tag.
Code:
open (AFILE,">>$afile") | | print "Content-type: text/html\n\n cannot open $afile(r): $!\n";

@array = split(/\~\~/,$FORM{'option'});
foreach (@array) {
($1,$2,$3,$4,$5)=split(/,/,$_);
print AFILE join "\|", $1,$2,$3,$4,$5,"\|\n";
}

close(AFILE);
Try that.

------------------
WFMY-TV Webmaster
Quote Reply
Re: how to split an in a form... (HELP!) In reply to
Hi

mmmhh.... I have the same result.

there are

3 select fields called "option" in my form but only one (last one) is printed in the file.

Perhaps I should call my select fields "option1", "option2", ecc.

What do you think?

Thanks.
Quote Reply
Re: how to split an in a form... (HELP!) In reply to
I don't know what I was thinking...

[This message has been edited by Chris071371 (edited December 16, 1999).]
Quote Reply
Re: how to split an in a form... (HELP!) In reply to
Sorry. It must be

<select size="1" name="option">
<option value="value0,value1,value2,value3,value4">1</option>
<option value="value0,value1,value2,value3,value4">1</option>
<option value="value0,value1,value2,value3,value4">1</option>

etc.


for each "option"

Quote Reply
Re: how to split an in a form... (HELP!) In reply to
I see, you could name them "option1", option2, and "option3" and use the code I showed for checkboxes above.

[This message has been edited by Chris071371 (edited December 16, 1999).]
Quote Reply
Re: how to split an in a form... (HELP!) In reply to
I got a syntax error about @array$_
Quote Reply
Re: how to split an in a form... (HELP!) In reply to
Here it is:
open (AFILE,">>$afile") | | print "Content-type: text/html\n\n cannot open $afile(r): $!\n";

@array = qw($FORM{'option1'} $FORM{'option2'} $FORM{'option3'});

foreach (@array) {
@array2 = split(/\,/, $_};
print AFILE join "\|", @array2,"\|\n";
}

close (AFILE);





------------------
WFMY-TV Webmaster
Quote Reply
Re: how to split an in a form... (HELP!) In reply to
mmmh this way I'm sending

$FORM{'option1'}|$FORM{'option2'}|$FORM{'option3'}

exactly like this!
Quote Reply
Re: how to split an in a form... (HELP!) In reply to
open (AFILE,">>$afile") | | print "Content-type: text/html\n\n cannot open $afile(r): $!\n";
@array = qw($FORM{'option1'} $FORM{'option2'} $FORM{'option3'});

foreach $form(@array) {
print AFILE ($form =~ s/\,/\|/g Wink"\n";
}

close (AFILE);

The smiley should be a ; then a )

------------------
WFMY-TV Webmaster

[This message has been edited by Chris071371 (edited December 17, 1999).]
Quote Reply
Re: how to split an in a form... (HELP!) In reply to
open (AFILE,">>$afile") | | print "Content-type: text/html\n\n cannot open $afile(r): $!\n";
@array = ($FORM{'option1'}, $FORM{'option2'}, $FORM{'option3'});

foreach (@array) {
@array2 = split(/\,/, $_};
print AFILE join "\|", @array2,"\|\n";
}

close (AFILE);



------------------
WFMY-TV Webmaster
Quote Reply
Re: how to split an in a form... (HELP!) In reply to
Ok Robert,

What exactly does the outputted text need to look like?

option1|option2|option3

or

option1&#0124; &#0124;
option2&#0124; &#0124;
option3&#0124; &#0124;

--mark
Quote Reply
Re: how to split an in a form... (HELP!) In reply to
Chris,

have you tried this routine on your machine?

I'm still having problems :-(((((

thanks.