Title: Need Fix | PHP Warning | DOMDocument
Last modified: October 15, 2024

---

# Need Fix | PHP Warning | DOMDocument

 *  Resolved [generosus](https://wordpress.org/support/users/generosus/)
 * (@generosus)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/need-fix-php-warning-domdocument/)
 * Hi there,
 * I’m getting the PHP warnings noted below. With the given warnings, how can I 
   identify the code snippet that is causing them?
 * Thank you!
 *     ```wp-block-code
       [15-Oct-2024 17:40:08 UTC] PHP Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1 in /home/customer/www/mysite.com/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(582) : eval()'d code on line 34
       ```
   
 *     ```wp-block-code
       [15-Oct-2024 17:40:08 UTC] PHP Warning: DOMDocument::loadHTML(): Tag xml invalid in Entity, line: 1 in /home/customer/www/mysite.com/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(582) : eval()'d code on line 34
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [generosus](https://wordpress.org/support/users/generosus/)
 * (@generosus)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/need-fix-php-warning-domdocument/#post-18074916)
 * **Update:**
 * Found the code snippet (see below). Based on the above warnings, any idea how
   to fix it?
 * Thank you!
 *     ```wp-block-code
       add_filter( 'gform_submit_button', 'gf_change_submit_button_text', 10, 2 );  function gf_change_submit_button_text( $button, $form ) {    $dom = new DOMDocument();    $dom->loadHTML( '<xml encoding="utf-8" ?>' . $button );    $input = $dom->getElementsByTagName( 'input' )->item(0);    $onclick = $input->getAttribute( 'onclick' );    $onclick .= " this.value='Sending...'"; // Change button text when clicked.    $input->setAttribute( 'onclick', $onclick );    return $dom->saveHtml( $input );}
       ```
   
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/need-fix-php-warning-domdocument/#post-18087202)
 * From the errors, it sounds like the issue isn’t with your snippet, but with the
   XML you’re getting it to parse.
 * Given that you’re just trying to augment the `onclick` attribute of a button,
   perhaps you could achieve the same thing with some basic JavaScript elsewhere
   on the page?
 *  Thread Starter [generosus](https://wordpress.org/support/users/generosus/)
 * (@generosus)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/need-fix-php-warning-domdocument/#post-18102438)
 * Hi [@bungeshea](https://wordpress.org/support/users/bungeshea/),
 * Thanks for the review and suggestion. Although I’m gettting the above PHP warning,
   everything is working on our site and not getting any console errors. So … not
   sure what the implications of the warning are at this time.
 * Perhaps I just need to review and/or change the code line below and see if that
   helps.
 *     ```wp-block-code
       $dom->loadHTML( '<xml encoding="utf-8" ?>' . $button );
       ```
   
 * Again, thank you.
 *  Thread Starter [generosus](https://wordpress.org/support/users/generosus/)
 * (@generosus)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/need-fix-php-warning-domdocument/#post-18102452)
 * **Issue Solved:**
 * Warning caused by a missing “**?**” in front of **xml**.
 * Above line should be:
 *     ```wp-block-code
       $dom->loadHTML( '<?xml encoding="utf-8" ?>' . $button );
       ```
   
 * Cheers!
 * Reference: [PHP DOMDocument loadHTML not encoding UTF-8 correctly](https://stackoverflow.com/questions/8218230/php-domdocument-loadhtml-not-encoding-utf-8-correctly)
    -  This reply was modified 1 year, 7 months ago by [generosus](https://wordpress.org/support/users/generosus/).

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Need Fix | PHP Warning | DOMDocument’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [generosus](https://wordpress.org/support/users/generosus/)
 * Last activity: [1 year, 7 months ago](https://wordpress.org/support/topic/need-fix-php-warning-domdocument/#post-18102452)
 * Status: resolved