Author Topic: Form with checkbox  (Read 2678 times)

0 Members and 1 Guest are viewing this topic.

Offline shlomit

  • Hero Member
  • *****
  • Posts: 117
Form with checkbox
« on: May 31, 2013, 04:07:52 PM »
Hi

I have checkbox  in the form for csvwrite.  When checking multiple selections, i got only one value in the database field (Category)

Here is an example

<FORM action=http://www.xxxxx.com/cgi-bin/csvwrite.pl method=POST  ENCTYPE="multipart/form-data"

<INPUT TYPE="checkbox" NAME="Category" VALUE="vanilla">vanilla
<INPUT TYPE="checkbox" NAME="Category" VALUE="chocolate">chocolate
<INPUT TYPE="checkbox" NAME="Category" VALUE="strawberry">strawberry

<input type="submit" value="thankyoua" name="thankyou" style="float: right">

</form>

** Note - in other csvwrite.pl script i have, in version from 2005 this problem does not happen , only with this one from 2006

Thanks

shlomit
« Last Edit: May 31, 2013, 05:59:30 PM by shlomit »

Offline Rob

  • Hero Member
  • *****
  • Posts: 201
Re: Form with checkbox
« Reply #1 on: June 01, 2013, 07:33:28 AM »
Hi Shlomit,

Each checkbox must have its own unique name.  Also, the name of each checkbox must be included as a field in your database.   

If you want to utilize the one field called Category then you will need to switch over from a checkbox to a drop down menu. 

I hope this helps,

Rob

« Last Edit: June 01, 2013, 07:37:41 AM by Rob »

Offline shlomit

  • Hero Member
  • *****
  • Posts: 117
Re: Form with checkbox
« Reply #2 on: June 01, 2013, 11:40:03 AM »
Hi Rob

thanks for your reply

i switched it from checkbox to dropdown menu and it is the same. in dropdown menu you can choose more then one  option (and this is what I need) by holding the shift. i did this and submit the form. i got only the first choice.

as I said in my previous message, this Do NOT happen in the 2005 version, either in checkbox or in dropdown menu
in version 2005 you can choose multiple selections and they all shows in the Category field, separated by commas.

there must be a solution for this, if the script cannot do this, this is very serious problem.

shlomit

Offline digiPETE

  • Jr. Member
  • **
  • Posts: 37
Re: Form with checkbox
« Reply #3 on: June 01, 2013, 02:30:28 PM »
Shlomit,

That's a head scratcher! I am definitely doing exactly that on a couple of forms - using multiple check boxes with the same field name. All checked choices pile up neatly in one field, and I'm using a script from January of 2006.

Not much help, but a couple of clues - it's funny that you're only seeing the first selection. If one over writes the previous one, you should be seeing the last one.

Also, perhaps try a different field name. "Category" is not on the list of names not to use, but it's possible that name is locking horns with something else on your page.

Lastly, if you have done this before, and the selections show up separated by commas - the only way this would happen is if the Input Value includes the comma. Ie. Value="Vanilla ,"  Which is a good idea by the way - the way you show in your example, the data would be one word "vanillachocolatestrawberry".

BTW - I'm assuming the delimiters you're using are not commas. That might be the problem too.


dP
« Last Edit: June 01, 2013, 02:35:18 PM by digiPETE »

Offline shlomit

  • Hero Member
  • *****
  • Posts: 117
Re: Form with checkbox
« Reply #4 on: June 01, 2013, 04:36:38 PM »
Hi digiPETE

head scratcher ? it drives my nuts :)

thank for you answer.

well, i already tried to play with all the possibilities before I came here with this problem, including changing the name of the field from Category to many other names, putting the comma as you suggested etc etc. no results. :)

Yes, it's funny that I am only seeing the first selection' not the last one .I checked it now again, and this is the situation

I don't know if it matters but my script is from - 17/Aug/2006

Shlomit
« Last Edit: June 01, 2013, 04:39:13 PM by shlomit »

Offline digiPETE

  • Jr. Member
  • **
  • Posts: 37
Re: Form with checkbox
« Reply #5 on: June 01, 2013, 05:05:52 PM »
Shlomit,

Well, then it's quite possibly a difference in the CSVWrite.pl versions.

I'm still a little curious about the whole "separated by commas" thing. How did you accomplish that before?

Also, is this the last field in the database? If this field were "moved up" in the order of fields, does it also wipe out all of the remaining entries?

dP

Offline shlomit

  • Hero Member
  • *****
  • Posts: 117
Re: Form with checkbox
« Reply #6 on: June 01, 2013, 06:11:45 PM »
Hi dp

not sure I understood your question about the separated commas. Don't you get the selected choises separated by commas regulary ?
did you have to do it on the form ? in my 2005 version the script does it. I didn't need to do anything.

about changing the order of the fields, I am not sure it is safe to do this. if you open the database and change the first line of the fields it cause a big mess to the data. (?) cause every line in the data is based on the order you put it first....

shlomit

« Last Edit: June 01, 2013, 06:17:23 PM by shlomit »

Offline digiPETE

  • Jr. Member
  • **
  • Posts: 37
Re: Form with checkbox
« Reply #7 on: June 01, 2013, 11:02:31 PM »
Shlomit,

No, (regarding the commas) the scripts don't add anything that I don't tell them to.

Here's how I would approach your example.

Code: [Select]
<FORM action=http://www.xxxxx.com/cgi-bin/csvwrite.pl method=POST  ENCTYPE="multipart/form-data"

<INPUT TYPE="checkbox" NAME="Category" VALUE="(vanilla)&nbsp;">vanilla
<INPUT TYPE="checkbox" NAME="Category" VALUE="(chocolate)&nbsp;">chocolate
<INPUT TYPE="checkbox" NAME="Category" VALUE="(strawberry)&nbsp;">strawberry

<input type="submit" value="thankyoua" name="thankyou" style="float: right">

</form>

This creates a clean separation between the chosen responses. Especially if you have a dozen or more options.

Regarding the order of the fields, my experience has been that these scripts could care less about what order the fields are in. The only thing that they complain about is if a field is missing. Obviously.

Regarding the comma separations - there is nothing in the documentation that says field values will receive any separation, or added characters, or anything you didn't ask it to do. Here is an example of something I have done with success:

Code: [Select]
<input type="text" name="Event_Date" />Event date (with calendar popup)
<input type="hidden" name="Event_Date" value" - at - " />
<input type="text" name="Event_Date"  />Event Time (with time selections)

The result is an entry in the Event_Date field that has "date - at - time" and nothing else inserted in between. Nor, would I want anything else inserted in between. All I want I want to see is what tell it, and nothing more. These scripts to exactly that.

Now, when I use my example, what I get are values included inside of parentheses so my clients can clearly tell each value apart.  Often times, there these strange characters (I'm sure you've seen them - a black diamond with a ? character inside). I've never gotten any complaints about those funny characters, so I don't complain here.


Quote
about changing the order of the fields, I am not sure it is safe to do this. if you open the database and change the first line of the fields it cause a big mess to the data. (?) cause every line in the data is based on the order you put it first....

True - you would need to start with a fresh database to try my experiment. And the more I think about it, the results might not mean much, but it could be a clue. Something isn't right somewhere.


dP
« Last Edit: June 01, 2013, 11:32:30 PM by digiPETE »

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: Form with checkbox
« Reply #8 on: June 02, 2013, 10:34:46 AM »
I'm traveling so I cannot look at the code right now. Shlomit, I think you are referring to the free version when you say the 2005. Also, the script handles checkboxes differently per browser; IE has has nothing between entries, FF adds an empty nondescript character etc.  also Pete is right. Make sure the field is not AFTER te ID in the database. When doing so the script acts funny. You can manually change the order of fields in a program like excel. The fields are in order based on how they are written to the db. But the script handles them in any order.

Jason
Founder of www.slipdex.com

Offline shlomit

  • Hero Member
  • *****
  • Posts: 117
Re: Form with checkbox
« Reply #9 on: June 02, 2013, 06:30:00 PM »
dp and Jason

thanks again. Jason, i never used a free version. so this is not the case.
all the scripts i have from 2005 in 3 sections on the site act great with checkboxes
the other 4 scripts version 2006 have this problem.
the Category does not show after the ID and not the last or first in the field order on the database file.

dp as for the comma, I do get all the selected choices in the checkbox in 2005 version. this has been since ever. little correction to what I have said before - the commas shows because I put it on the form and forgot about it.

see the screen shot attached. you don't need to understand the language. I just made a test for you to see now.
look at the scope field and the Region field.



I am really confused.

shlomit

« Last Edit: June 02, 2013, 07:11:56 PM by shlomit »

Offline Rob

  • Hero Member
  • *****
  • Posts: 201
Re: Form with checkbox
« Reply #10 on: June 02, 2013, 07:56:03 PM »
Hi Shlomit,

Jason makes a good point about how the different browsers handle the data differently.  Moreover, you will want to make your coding as cross browser compatible as possible which brings me back to the checkboxes having unique field names. 

Why not just create a different database field for each category such as category1 for vanilla and category2 for chocolate and category3 for strawberry, etc.

Also, even if you are able to figure out how to have one field name containing all of the flavors; all of the flavors will then be displayed in the output.  In other words, if someone were to search on "Category" all of the flavors would be displayed rather than the 1 flavor that they were searching for.     


Rob
« Last Edit: June 02, 2013, 08:02:44 PM by Rob »

Offline shlomit

  • Hero Member
  • *****
  • Posts: 117
Re: Form with checkbox
« Reply #11 on: June 02, 2013, 08:30:18 PM »
Hi Rob

The answer for your question is simple (to my opinion)

A user has to check if his Farm is in the North, Center or South in Israel, if he wants to submit a new Job on the agri Job listing.
The field for this has to be for example -  Location.
then on the ad what should I put on the template ?? now I put [[Location]] and his chosen (North, Center or South ) shows there on the page.

if someone want to sell his tractor and he lives in Italy, he has to chose between the countries. on the template I put [[State]] and the country shows there

I need it for the template more then for the scvsearch.pl script.

Shlomit

Offline Rob

  • Hero Member
  • *****
  • Posts: 201
Re: Form with checkbox
« Reply #12 on: June 03, 2013, 06:12:17 AM »
Hi Shlomit,

As a work around you could create 3 check boxes with three separate field names and 3 separate values.  EX: Location1 would have a value of "North", Location2 would have a value of "Center" and Location 3 would have a value of "South". 

On your search results template you would include the three field names: [[Location1]], [[Location2]], [[Location3]].   However, only the location that was selected and saved to the database will be displayed on your search results template.  The downside to this is that the user could select multiple check boxes.  In order to prevent this from occurring you would need to use radio buttons rather than check boxes.  Or, you could use a drop down menu.     



Rob

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: Form with checkbox
« Reply #13 on: June 03, 2013, 07:13:03 AM »
Hi Shlomit,

Can you send me the 2005 version fo the script so I can see if I can test it. I unfortunately don't seem to have the older script.

Jason
Founder of www.slipdex.com

Offline shlomit

  • Hero Member
  • *****
  • Posts: 117
Re: Form with checkbox
« Reply #14 on: June 03, 2013, 08:20:19 AM »
Rob

this is not so good, since when i have countries i will have to make many many selelctions.

http://www.ads.agrisupportonline.com/csv/csvread.pl?show=6673&mytemplate=tp1

see this example.

even if it is for 3 option as you mentioned. the location field on the template will look like this:

 , , Sourth or this North, , or this , center,
you know what I mean ?

shlomit