Функция PHP не определена Ошибка и синтаксическая ошибка неуместного </ p> в сгенерированном HTML

Чтобы решить сложную проблему поиска вики, мы внедрили решение Javascript в файл PHP.

К сожалению, у меня две проблемы. Во-первых, функция не вызывается, а во-вторых, я вижу синтаксическую ошибку в консоли ошибок, которую я не могу решить. Во-первых, вот код внутри файла PHP:

$htmlOut .= <<<ENDOFBLOCK <script language="javascript"> function appendAndSubmit(){ var platform1 = document.getElementById( 'p1').checked; var platform2 = document.getElementById( 'p2').checked; var text = document.getElementById('search').value; if (platform1) text = 'Applies to=Platform 1.0 ' + text; if (platform2) text = 'Applies to=Platform 2.0 ' + text; alert( text); document.getElementById('search').value = text; document.forms['searchform'].submit();} </script> ENDOFBLOCK ; 

Итак, первая проблема заключается в том, что я вижу, что appendAndSubmit не определен в консоли ошибок.

Вторая проблема – синтаксическая ошибка. Сгенерированный HTML-источник:

 <p><script language="javascript"> function appendAndSubmit(){ var platform1 = document.getElementById( 'p1').checked; var platform2 = document.getElementById( 'p2').checked; var text = document.getElementById('search').value; if (platform1) text = 'Applies to=Platform 1.0 ' + text; if (platform2) text = 'Applies to=Platform 2.0 ' + text; alert( text); document.getElementById('search').value = text; document.forms['searchform'].submit();} </p> </script><div align="center" style="background-color:transparent"><form name="searchbox" id="searchbox" class="searchbox" action="/wiki/index.php?title=Special:Search"><input class="searchboxInput" name="search" type="text" value="" size="50" /><br /><input type="checkbox" name="1" value="&quot;Applies to=Platform 1.0&quot;" id="p1" />&nbsp;<label for="">Platform 1.0</label><input type="checkbox" name="2" value="&quot;Applies to=Platform 2.0&quot;" id="p2" />&nbsp;<label for="">Platform 2.0</label><br /><input type="submit" name="fulltext" class="searchboxSearchButton" value="Go!" onClick="appendAndSubmit();" /></div></form> 

Обратите внимание, что </p> происходит до </script> , а <p> до <script> .

Может ли кто-нибудь сказать мне, что я делаю неправильно?

Вызов функции appendAndSubmit находится здесь:

  $htmlOut .= Xml::element( 'input', array( 'type' => 'submit', 'name' => 'fulltext', 'class' => 'searchboxSearchButton', 'value' => 'Go!', 'onClick' => 'appendAndSubmit();' ) ); 

Полный метод:

  public function getSearchPlatform() { // Use button label fallbacks global $wgContLang; // Use button label fallbacks if ( !$this->mButtonLabel ) { $this->mButtonLabel = wfMsgHtml( 'tryexact' ); } if ( !$this->mSearchButtonLabel ) { $this->mSearchButtonLabel = wfMsgHtml( 'searchfulltext' ); } $htmlOut .= <<<ENDOFBLOCK <script type="text/javascript"> function appendAndSubmit(){ var platform1 = document.getElementById( 'p1').checked; var platform2 = document.getElementById( 'p2').checked; var text = document.getElementById('search').value; if (platform1) text = 'Applies to=Platform 3.0 ' + text; if (platform2) text = 'Applies to=Platform 4.0 ' + text; alert( text); document.getElementById('search').value = text; document.forms['searchform'].submit();} </script> ENDOFBLOCK ; // Build HTML $htmlOut .= Xml::openElement( 'div', array( 'align' => 'center', 'style' => 'background-color:' . $this->mBGColor ) ); $htmlOut .= Xml::openElement( 'form', array( 'name' => 'searchbox', 'id' => 'searchbox', 'class' => 'searchbox', 'action' => SpecialPage::getTitleFor( 'Search' )->escapeLocalUrl(), ) ); $htmlOut .= Xml::element( 'input', array( 'class' => 'searchboxInput', 'name' => 'search', 'type' => 'text', 'value' => $this->mDefaultText, 'size' => $this->mWidth, ) ); $htmlOut .= $this->mBR; // Checkbox $htmlOut .= Xml::element( 'input', array( 'type' => 'checkbox', 'name' => '1', 'value' => '"Applies to=Platform 1.0"', 'id' => 'p1' ) ); // Label $htmlOut .= '&nbsp;' . Xml::label( 'Platform 2.0' ); // Checkbox $htmlOut .= Xml::element( 'input', array( 'type' => 'checkbox', 'name' => '2', 'value' => '"Applies to=Platform 2.0"', 'id' => 'p2' ) ); // Label $htmlOut .= '&nbsp;' . Xml::label( 'Platform 2.0' ); // Line break $htmlOut .= $this->mBR; $htmlOut .= Xml::element( 'input', array( 'type' => 'submit', 'name' => 'fulltext', 'class' => 'searchboxSearchButton', 'value' => 'Go!', 'onClick' => 'appendAndSubmit();' ) ); // Hidden fulltext param for IE (bug 17161) if( $type == 'fulltext' ) { $htmlOut .= Xml::hidden( 'fulltext', 'Search' ); } $htmlOut .= Xml::closeElement( 'div' ); $htmlOut .= Xml::closeElement( 'form' ); // Return HTML return $htmlOut; }