Real Men answer Low Point Questions

I'm trying a social experiment to see how many people the subject leads to this question and/or how much flaming I get -- but perhaps my litle disclaimer fouls the control.  Having said that, hey, please leave a comment on either my real question (below) or just to say, "I came here because of the subject line, and I hope you get hit by the M53 bus on your way home, jerk."

As promised, here's the actual question:
Is there any PHP code that would cycle through all of the Form elements in a form, say, just to print them out?  Is there a for loop I could write that would just cruise the Docment Object Model for all elements in a form, as opposed to having to go after them one at a time with $_POST?  I know I could find the answer on the Web, but I'd like to hear what the Experts think.
Who is Participating?
VoteyDiscipleConnect With a Mentor Commented:
foreach($_POST as $key => $value) {
    echo "Posted value for $key is '$value'";
Raynard7Connect With a Mentor Commented:
You would only know what was submitted; but you could do print_r($_POST) which would show you all the elements that were posted,

alternativley you could do foreach on the $_POST

on your experiment - I find that the people who ask low point questions are on the whole very frustrating, ask multiple questions in one post - are unsure what they really want - and often have no idea what they are doing and want someone to do their work for them rather than learn
I'll make three comments, I guess:

1.  Some people are gonna click any unvisited link at the top of the list no matter what the subject says.... not that it isn't eye-catching.  (-:

2.  How is iterating through elements in a DOM tree better/different than iterating through elements in $_POST ?

3.  PHP doesn't have any implicit access to a DOM tree, since it's generating flat HTML -- that is, plain text.  To get such a tree you'd have to get the finished product in HTML and parse it (I've seen a couple tools out there that can do so).
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
AmigoJackConnect With a Mentor Commented:
actual question:
VoteyDisciple is right - it has nothing to do with php. however, it is possible via javascript to iterate through all elements within a html-document - i did this once and was quite fascinated that its rather simple to do so. the only issue is when creating any output - you have to watch out for the javascript part itself - otherwise you would list content recursively endless (...or the browser dies).

thoughts that came to my mind reading your title:
- nice points, havent seen such an odd one here :-)
- whats the real problem? *interest*
- i wish all people would actually use a title. at least he didnt wrote "HEEEEEEEELP" :-/
- who has the right to define "real" men? :-[
- would feminists critizise on that title? :-P
- i have already answered 500s that were more than simple, there are people out there who throw out 500s for basic things... :-/
- low points sometimes means the asker knows how to weight his problem right :-)
VoteyDiscipleConnect With a Mentor Commented:
Normally I'd be afraid of veering wildly off-topic with this comment, but in this case...

Feminists critical of the title would be making a classic inverse error.  There's no assertion that women don't answer low-point.  We "know" only the statement (if you're a real man ==> then you'll answer a low-point question) and its contrapositive (if you don't answer a low-point question ==> you're not a real man).

Women who DO answer the question neither confirm nor disprove either (equivalent) statement.  Women who DON'T answer the question aren't real men, primarily (I think) because they aren't actually men in the first place.  So while these hypothetical feminists could conceivably be upset that there are more assertion being made here about men than women, the assertion itself is not insulting.  (-:

(Sorry, but it's not often one can reply to a sentence containing the word "feminist" with a reply that uses the phrases "inverse error" and "contrapositive" and I couldn't resist.)

I think Experts Exchange should adopt the eBay auction model.  I'll post a solution, but I'LL tell you how many points it should be worth.  If you want to see my answer you'll have to cough up the number of points I want.

(Note: I actually think that's a really bad idea, but it's a nice extreme...)
Mark GilbertSenior Performance EngineerCommented:
If you want to try out DOM, there is a great set of classes at in which you create functions in php and then call them using javascript.  There are form handlers there too, so I don't see a problem with you processing your form.  The only problem I can think of off hand regarding a form is that it doesn't work nicely with binary inputs (such as a file field).
RaydotAuthor Commented:
Wow, I knew this would get some interesting things said.  Me, I try not to be annoying or walk away, but is this really a 500 point question? Every question in this Q is 500 points!  As for "real men," I don't mean to exclude women, but it's pretty clear to me that 85% of EE's experts are male.  Increasing points...

I did mix DOM and PHP together indiscriminately, I just didn't think it through enough.  I guess what I'm saying is, if I know I'm interested in every item on the page, can't I just loop through?  Do I have to pull them all by $_POST['item1'], $_POST['item2']'s a lot of typing.  Not that I'm lazy, it just seems inefficient.  That's really what I'm after, is there a better way?

RaydotAuthor Commented:
Raynard7, you actually did answer my there a way to get a count on how many things are in $_POST, similar to argc in C++?  I don't think that's an additional question as much as an extension of the foreach answer, but if you think so let me know and I'll...bump the points!
RaydotAuthor Commented:
So...VoetyD, this will return a value for every item that's actually been entered, and if the user leaves something blank, it's skipped?
since $_POST is an array, you can use

so we come down to basics. again! :P which leads me back to saying this is far away from being worth 500 points. the best questions come from askers who want to learn instead of those who just want a quick and/or easy solution - no matter what its pros and cons are.
eheimerConnect With a Mentor Commented:
To find out how many elements are in $_POST you can use: count($_POST);

VoteyD, I think you made a potentially incorrect assumption in your comment above that all feminists are women.  ;-)  In any case, I think feminists would say that there's no such thing as a "real man" anyway so it probably makes little difference to them.  They'd just look at the question comments and think "hmmm, all those commenters must be women".  Or something.
Sorry, didn't mean to repeat AmigoJack's answer.
I don't think I made that assumption anywhere?  I looked back over it and I believe I did phrase it correctly.

Anyway, if the user leaves a TextBox blank then $_POST will still contain an entry for it.  If a user doesn't check a checkbox, doesn't click a submit button (if there are more than one) or fails to check any of the radio buttons with a particular name, then no value will come through at all -- PHP will be 100% unaware that such form elements ever existed.
RaydotAuthor Commented:
What's off topic?  The question title, I think, welcomes both kinds of answers!
RaydotAuthor Commented:
Thank you all for your support.

One last comment.  I know a lot has been said about the points issues.  Googling EE it turns out a lot of people out there think it's a joke, and a lot of the "old timers" don't use it much any more because there's some kind of macho posturing thing all over the place.  So my question  is EE, what's your plan to move forward? I see a lot of suggestions but not a lot happening!

Please take this in the constructive-critical way in which it's intended.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.