Hiding hidden inputs as a string (using PHP Simple HTML DOM Parser)

So, I have a form containing 4 inputs, 2 texts, 2 hidden. I took two text input values ​​from the name, which (get_me_two, get_me_three), and I also captured the form action (get_me.php). What I'm looking for now is to capture 2 hidden entrances, but not the values. I want to capture the entrances themselves.

EG: Here is my form:

<form action="get_me.php" method="post"> <input type="text" name="get_me_two"> <input type="text" name="get_me_three"> <input type="hidden" name="meta_required" value="from"> <input type="hidden" name="meta_forward_vars" value="0"> </form> 

And what I want to get from here is two hidden inputs, not values, a complete line.

I'm not sure how to capture them with: PHP Simple HTML DOM Parser if anyone knows how cool it is, if not, if there is an alternative that would also be great. As soon as I captured them, I plan to transfer 2 input values ​​to another page with hidden lines and, of course, the action of the form.

Also, if anyone is interested in my full code, which includes the simple html dom functionality.

 <?php include("simple_html_dom.php"); // Create DOM from URL or file $html = file_get_html('form_show.php'); $html->load(' <form action="get_me.php" method="post"> <input type="text" name="get_me_two"> <input type="text" name="get_me_three"> <input type="hidden" name="meta_required" value="from"> <input type="hidden" name="meta_forward_vars" value="0"> </form>'); // Get the form action foreach($html->find('form') as $element) echo $element->action . '<br>'; // Get the input name foreach($html->find('input') as $element) echo $element->name . '<br>'; ?> 

So, the final result will capture 3 values, and then 2 hidden inputs (full lines). Help would be greatly appreciated as it made me breathe a little while trying to achieve this.

+6
source share
2 answers

If you are using DomDocument , you can do the following:

 <?php $hidden_inputs = array(); $dom = new DOMDocument('1.0'); @$dom->loadHTMLFile('form_show.php'); // 1. get all inputs $nodes = $dom->getElementsByTagName('input'); // 2. loop through elements foreach($nodes as $node) { if($node->hasAttributes()) { foreach($node->attributes as $attribute) { if($attribute->nodeName == 'type' && $attribute->nodeValue == 'hidden') { $hidden_inputs[] = $node; } } } } unset($node); // 3. loop through hidden inputs and print HTML foreach($hidden_inputs as $node) { echo "<pre>" . htmlspecialchars($dom->saveHTML($node)) . "</pre>"; } unset($node); ?> 
0
source

I do not use SimpleDom (I always go all the way and use DOMDocument), but could you please do something like ->find('input[@type=hidden]') ?

If SimpleDOM does not allow this selector, you can simply iterate over the results ->find('input') and select the hidden ones by comparing the attributes themselves.

+4
source

Source: https://habr.com/ru/post/891471/


All Articles