Solved

php - processing checkboxes

Posted on 2014-04-15
3
301 Views
Last Modified: 2014-04-15
Hello,

I have a php program (attached) designed to process checkboxes on a form. Note the echo was to debug & find out why it wasn't working.

Also attached is the HTML page, as it existed upon calling the php program.

Note in the html program, there are several checkbox elements that are NOT checked. Those elements are NOT being picked up in the php program which defeats the whole purpose.

Why are the unchecked elements NOT being picked up?
updt-base-citylinks.php
manage-base-citylinks.htm
0
Comment
Question by:Richard Korts
  • 2
3 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
Unchecked checkboxes are not present in the request variables.  They are not "there and empty;" they are simply missing.  This is the way that it works.  Dumb design, but an unfortunate fact of life.  Please read this over and see if it helps with the understanding.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_5450-Common-Sense-Examples-Using-Checkboxes-with-HTML-JavaScript-and-PHP.html
0
 

Author Comment

by:Richard Korts
Comment Utility
I thought that MIGHT be the case, but I thought THAT was a stupid idea to even consider

I can envision a workaround.

Thanks
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
The workaround might be an input of an identical name attribute with type="hidden" as described in the article.  I have used that successfully.  It's a PHP-only solution because some languages that use raw post input require specialized programming to deal with the request data.  But if you're using PHP and you use the $_GET or $_POST arrays, you'll be on firm ground.

Thanks for the points, ~Ray
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now