This is a discussion on "Multiple Choice Form Values" within the PHP Forum section. This forum, and the thread "Multiple Choice Form Values are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Multiple Choice Form Values
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Multiple Choice Form Values
One of the fileds in my Form has multiple Tick boxes. Each tick box is labeled 'service'
I expected the values to be emailed to me in order, eg: service1, service2, service4 But only one was coming through. . . To get around this I labeled each tick box differently and manualy added a ',' commer at the end of each to separate them up:
service1, , service3, , , service6, service7, , , service11, Any recommendations as to a better way to capture multiple answers in one field please? |
|
|
|
#2
|
|||
|
|||
|
How's this?
Note - I dislike repeated code in my PHP (such as checking a series of variables with a pattern of names) as it makes the code hard to extend if more repetitions are added later, so I've provided a slightly complex loop that could easily be expanded if the service increased from 5 to 50 a day! |
|
#3
|
|||
|
|||
|
That is fantastic thank you
|
|
#4
|
|||
|
|||
|
Hi,
I have been using the code you suggested but from the POST php page after my form is submitted and I have come across a problem. First off I changed the
Here is the code:
Quote:
|
|
#5
|
|||
|
|||
|
Quote:
You can use a $service.$k type construct as an array subscript which is what I did in my example, but you can't use it to make up a variable name which is what you're attempting. What version of PHP are you using? If you're using 4.1 or later, you really should be using code like my original suggestion .... but it looks like you may be using 4.0.something or even older if that didn't work. In the older versions ... as I recall .. there's an array called $HTTP_POST_VARS which should be used in place of the $_REQUEST of my original code (and you do need to add a method="POST" to the form tag) |
|
#6
|
|||
|
|||
|
Hi
I am using php 4.3.11, but here I tried $HTTP_POST_VARS anyway I have amended to code like you suggested (below). The form is named form1 and has POST method already. The fields are named Service1 to Service17 I removed the $ so it is not using a variable name. But I dont understand how the function will know to recieve info from the Service fileds? I understood by writing $Service I was calling the field info? The result is still 'No Services Selected' every time
The reason I changed the $report to $message is because it is within an email message and there are other $message .= "info info" above and below it refering to other fileds on the form. |
|
#7
|
|||
|
|||
|
The code
If you're at 4.3.11, then you should be using $_GET if you're submitting the form via the GET method, $_POST if you're using the POST method, or $_REQUEST if you want the code to work whichever method is used for the submission. I note that you're using this as part of a bigger script (yes, I would have expected that). If my comments above don't lead you to a solution, can I suggest that you cut out the majority of that script and reduce the problem to a piece of code about the length of my earlier example and post it ... I'll probably be able to spot the problem and give a specific fix quite quickly! |
|
#8
|
|||
|
|||
|
I realised the line you rmentioned was missing the $_POST so I changed it to this:
As far as I can see it is the same as your orginal script only using POST
|
|
#9
|
|||
|
|||
|
Your PHP worked for me using the form:
|
|
#10
|
|||
|
|||
|
I added the Hidden Field and the Services come through fine now Thank you.
Out of interest - If I wanted to add Checked Values to the check boxes on the form, could this script be amended somehow to accomodate them? AK |
![]() |
| Tags |
| multiple, choice, form, values |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| My javascript for multiple choice questions (COMPLETED) | RohanShenoy | Webforumz Cafe | 0 | Dec 4th, 2007 07:52 |
| JS for multiple choice questions (i worte it myself) | RohanShenoy | JavaScript Forum | 20 | Nov 8th, 2007 18:40 |
| Setting Form Values to Previously Entered Values | masonbarge | PHP Forum | 6 | Oct 17th, 2006 17:36 |
| form not updating values | djanim8 | Classic ASP | 0 | Dec 10th, 2005 19:05 |
| Passing values from Datagrid to another form | caryma | ASP.NET Forum | 4 | Aug 17th, 2005 08:06 |