?
Solved

PHP survey form and checkbox ("array")

Posted on 2006-06-04
8
Medium Priority
?
541 Views
Last Modified: 2008-03-06
Hi!

I am creating an online PHP survey form.


The problem is:
I have a checkbox to ask clients to make a final confirmation of their input. Once the '''Submit" button is clicked, the output is displayed on the screen. all out is displayed properly except confirmation field. I expect to view "Confirmed". Instead "array" is displayed.

___________________The script of  checkbox creation __________________________________________
<div class="confirm"><input type="checkbox" name="confirm[]" value="confirmed">      I confirm that I filled out this application form accurately at the risk of perjury.</div>
_____________________________________________________________________________________

___________ The script to view the output of $confirm ______________________________________

echo "<tr><th>Confirm Accuracy:</th><td>".$confirm."</td></tr>";

_____________________________________________________________________________________


Hope you experts may kindly help me again!

duta
June 4, 2006, at 1:06 pm
0
Comment
Question by:duta
  • 3
  • 3
  • 2
8 Comments
 
LVL 2

Assisted Solution

by:feha
feha earned 1000 total points
ID: 16828116
if you have just separate check box to confirm than use as
<div class="confirm"><input type="checkbox" name="confirm" value="confirmed">

as it does not need to be an array do not use      name="confirm[]"

to display use:
echo "<tr><th>Confirm Accuracy:</th><td>".$_POST['confirm']."</td></tr>";

hope this helps

0
 
LVL 6

Accepted Solution

by:
soapergem earned 1000 total points
ID: 16828117
You named your checkbox "confirm[]". Do you have multiple checkboxes with this name, by any chance? If you do, good. If not, and this is your only checkbox, change the name to "confirm" (without the brackets). By having those square brackets there, it places the result into an array, so the value you are looking for would actually be in $confirm[0] (or it wouldn't be anywhere if the box wasn't checked).

Oh, and by the way, DO NOT USE $confirm TO REFERENCE THE DATA. USE $_REQUEST['confirm']. Assuming that register_globals is turned on is bad practice. If you kept the same name and used this format, the value would be in $_REQUEST['confirm'][0]
0
 
LVL 6

Expert Comment

by:soapergem
ID: 16828120
feha beat me to it.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:duta
ID: 16828170
TO: feha and soapergem:

Thank you so much for your very kind, prompt response.

Your tips worked just great.
I would like to split the points between you, if you may kindly not mind.

Hope you may come back to help me again!

duta
June 4, 2006, at 1:58 pm
0
 

Author Comment

by:duta
ID: 16828189
TO: feha and soapergem:

Hi again!

I tried to split evenly (because your tips arrived almost simultaneously and worked great) and to accept both as "Accepted Answer". But it turned out against my intention that one of them is registered as "Assisted Answer" and the other as "Accpeted Answer".

Hope that this may help clear an misunderstanding.

Thanks again!  Both of you are just great!

duta

June 4, 2006, at 2:02 pm
0
 
LVL 6

Expert Comment

by:soapergem
ID: 16828208
That's fine by me. Thanks for the split! =)
0
 
LVL 2

Expert Comment

by:feha
ID: 16828229
great nice it worked for you :-)

feha
 www.vision.to
0
 

Author Comment

by:duta
ID: 16828240
TO: feha and soapergem:

Thank you so much for your kind understanding.
feha, you are creating a nice web site.

Thanks again!

duta

June 4, 2006, at 2:15 pm
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question