0

Is there a built in php function that will return an array (or some sort of list) of all the form elements within a div or within a specific form by either name or id?

My limited experience in javascript tells me that this can probably be occomplished with javascript but i am wondering if it can be done in php. Thanks for your help.

My only other alternative would be to define a variable at the bottom of each form element like:

$allElements = 'name';
$allElements .= ', phone';
$allElements .= ', email'; 
and so on.  

I am wondering if there is a short cut to this method?

user982853
  • 2,470
  • 14
  • 55
  • 82
  • possible duplicate of [How to parse and process HTML with PHP?](http://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-with-php) – Gordon Jan 13 '12 at 23:53

2 Answers2

0

Don't really know what you exactly mean. All variables from a sent form are stored in the $_POST global variable. This will show you the list:

if ($_POST) {
    echo '<pre>';
    echo print_r($_POST);
    echo '</pre>';
}

Maybe you need to parse HTML with PHP - see the answer above.

Sidd Sidd
  • 95
  • 1
  • 1
  • 4
0

You are going to want to parse the HTML.

$HTML = '<div name="phone"></div>';
$string = strstr($HTML, 'name=\"');
$string = strstr($string, '\"');

something like that...

these are your best friends:

stripos() 
strrpos() 
strripos() 
strstr() 
strpbrk()
substr()
Dan Kanze
  • 18,485
  • 28
  • 81
  • 134