Grabbing hidden inputs as a string (Using PHP Simple HTML DOM Parser)

后端 未结 2 1524
不知归路
不知归路 2021-01-05 10:28

So I have a form that has 4 inputs, 2 text, 2 hidden. I\'ve grabbed the two text input values from the name, which are (get_me_two, get_me_three) and I\'ve also grabbed the

2条回答
  •  北海茫月
    2021-01-05 10:47

    If you use DomDocument, you could do the following:

    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 "
    " . htmlspecialchars($dom->saveHTML($node)) . "
    "; } unset($node); ?>

提交回复
热议问题