[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: [mv] Using checkboxes to write multiple values to one field
****** message to minivend-users from Bill Randle <billr@exgate.tek.com> ******
Ed,
I think you may have misuderstood my previous message. It's not the fact
that your values have spaces in them, it's the fact that minivend groups
all the checked checkbox values together with a NUL byte ('\0'), which
if you're printing strings, means the end of the string.
Try adding the code below to your results page (or the page you go to
from your form with the checkboxes):
<B>Checkbox results are: </B>[perl arg="cgi"]
$myfield = $Safe{cgi}->{myfield};
$myfield =~ s/\0+/|/g;
return $myfield;
[/perl]
Let me know what it shows for various combinations of checked boxes on your
form.
-Bill
Ed LaFrance wrote:
>
> ****** message to minivend-users from Ed LaFrance <edlafrance@printexusa.com> ******
>
> Bill -
>
> Would you mind sharing a little of the code from the page where you use
> checkboxes?
>
> I tried removing the trailing spaces from my fields and I am still getting
> only the first checked option in the database. Note that I have verified
> this by exporting the database and looking at its contents, and by checking
> for values in the field using [if value] logic.
>
> Also note that if I do this
>
> <input type=checkbox name=myfield value="A B"> Option A B
> <input type=checkbox name=myfield value="C "> Option C
> <input type=checkbox name=myfield value="D "> Option D
>
> Minivend saves and retrieves "A B" repeatedly without problems. I can also
> change the form element to a text field and type in as many space-separated
> items as I want, and they are saved and retrieved without trouble. Maybe I
> am misunderstanding this, but I don't think the spaces are the source of my
> trouble.
>
> - Ed L.
>
> At 10:32 AM 4/3/00 -0700, you wrote:
> >****** message to minivend-users from Bill Randle
> ><billr@exgate.tek.com> ******
> >
> >Ed LaFrance wrote:
> > >
> > > ****** message to minivend-users from Ed LaFrance
> > <edlafrance@printexusa.com> ******
> > >
> > > Does anyone know how to use checkboxes to write multiple values to one
> > > arbitrary database field with minivend 3.1x?
> > >
> > > As an example:
> > >
> > > <input type=checkbox name=myfield value="A "> Option A
> > > <input type=checkbox name=myfield value="B "> Option B
> > > <input type=checkbox name=myfield value="C "> Option C
> > >
> > > ...if the user checks all three of these on the form, a form processing
> > > program which follows HTML conventions should interpret the submission as
> > > "myfield=A B C ". It appears that minivend is not doing this; instead, it
> > > is using the first received name/value pair and ignoring the rest, so all
> > > it sees is "myfield=A ".
> > >
> > > I can't find any info on this in the docs or the list archives. Anyone
> > > have any ideas?
> >
> >Ed,
> >
> >I'm using a form with multiple checkboxes and it works fine. I think you
> >may be getting thrown off by the end result you see. Minivend does
> >see and process all of the selected options. What it does, though, is
> >effectively replace the space with a '\0' byte when storing the value.
> >So, if you print out the value as a string, it will end after the first
> >item.
> >
> >The trick is to replace those '\0' bytes with spaces before you print
> >the value and before you store it in your database. E.g.:
> >
> > [perl arg="cgi scratch"]
> > $myfield = $Safe{cgi}->{myfield}; # or $CGI->{myfield}
> > in mv4
> > $myfield =~ s/\0+/ /g;
> > $Safe{scratch}->{myfield} = $myfield; # or
> > $Scratch->{myfield} in mv4
> > [/perl]
> >
> >Add a few more lines and you can even sort the results:
> >
> > [perl arg="cgi scratch"]
> > $myfield = $Safe{cgi}->{myfield}; # or $CGI->{myfield}
> > $myfield =~ s/\0+/ /g;
> > @myfield = split / /, $myfield;
> > $myfield = join ' ', sort @myfield;
> > $Safe{scratch}->{myfield} = $myfield; # or
> > $Scratch->{myfield} in mv4
> > [/perl]
> >
> >You can now access the space seperated results using [scratch myfield].
> >You can,
> >of course, use something other than space as the replacement field
> >seperator. In
> >your case, since you have a space as part of the option value, you may want to
> >use '|', ';' or similar as your seperator. Just replace the / / and ' ' with
> >the character of your choice.
> >
> >Also, you can use [checkbox] to remember previous selections, as in:
> > <input type=checkbox name=myfield value="A " [checked
> > name=myfield multiple=1
> >value="A "]> Option A
> >
> > -Bill
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list