• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

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.
0
Raydot
Asked:
Raydot
  • 5
  • 4
  • 2
  • +4
5 Solutions
 
Raynard7Commented:
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

http://au2.php.net/manual/en/function.print-r.php
http://au2.php.net/manual/en/control-structures.foreach.php

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
0
 
VoteyDiscipleCommented:
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).
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
listening...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AmigoJackCommented:
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 :-)
0
 
VoteyDiscipleCommented:
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...)
0
 
Mark GilbertSenior Performance EngineerCommented:
If you want to try out DOM, there is a great set of classes at xajaxproject.org 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).
0
 
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'] etc...it'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?


0
 
VoteyDiscipleCommented:
foreach($_POST as $key => $value) {
    echo "Posted value for $key is '$value'";
}
0
 
RaydotAuthor Commented:
Raynard7, you actually did answer my question...is 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!
0
 
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?
0
 
AmigoJackCommented:
since $_POST is an array, you can use
count($_POST)

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.
0
 
eheimerCommented:
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.
0
 
eheimerCommented:
Sorry, didn't mean to repeat AmigoJack's answer.
0
 
VoteyDiscipleCommented:
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.
0
 
RaydotAuthor Commented:
What's off topic?  The question title, I think, welcomes both kinds of answers!
0
 
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now