Akopia Akopia Services

[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 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


Search for: Match: Format: Sort by: