Solved

Real Men answer Low Point Questions

Posted on 2006-11-13
18
295 Views
Last Modified: 2007-02-01
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
Comment
Question by:Raydot
  • 5
  • 4
  • 2
  • +4
18 Comments
 
LVL 35

Assisted Solution

by:Raynard7
Raynard7 earned 50 total points
ID: 17935855
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
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17935922
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17936359
listening...
0
 
LVL 12

Assisted Solution

by:AmigoJack
AmigoJack earned 50 total points
ID: 17937380
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
 
LVL 19

Assisted Solution

by:VoteyDisciple
VoteyDisciple earned 163 total points
ID: 17937417
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
 
LVL 18

Expert Comment

by:ingwa
ID: 17937475
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
 
LVL 3

Author Comment

by:Raydot
ID: 17939669
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
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 163 total points
ID: 17939747
foreach($_POST as $key => $value) {
    echo "Posted value for $key is '$value'";
}
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 3

Author Comment

by:Raydot
ID: 17939754
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
 
LVL 3

Author Comment

by:Raydot
ID: 17939772
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
 
LVL 12

Expert Comment

by:AmigoJack
ID: 17940232
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
 
LVL 2

Assisted Solution

by:eheimer
eheimer earned 50 total points
ID: 17940351
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
 
LVL 2

Expert Comment

by:eheimer
ID: 17940366
Sorry, didn't mean to repeat AmigoJack's answer.
0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17940708
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
 
LVL 3

Author Comment

by:Raydot
ID: 18445690
What's off topic?  The question title, I think, welcomes both kinds of answers!
0
 
LVL 3

Author Comment

by:Raydot
ID: 18445746
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

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

11 Experts available now in Live!

Get 1:1 Help Now