Need help with php in page

I am trying to use a php search script on a page.
I can echo a simple "hello world" fine.

I get this error though when trying my script, any help is appreciated.

Server Error

Undefined index: kw
  1. XenForo_Application::handlePhpError() in XenForo/Pages/test.php at line 2
  2. require() in XenForo/Pages/plugin.php at line 7
  3. XenForo_Pages_plugin::includePhpFile()
  4. call_user_func_array() in XenForo/ControllerPublic/Page.php at line 46
  5. XenForo_ControllerPublic_Page->actionIndex() in XenForo/FrontController.php at line 310
  6. XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
  7. XenForo_FrontController->run() in /home/xxxxxr/public_html/testxf/index.php at line 13
Here is my code in test.php:
PHP:
<?php
$search = $_POST["kw"];
if ($search == '') // If value does not equal anything
{
$search = "media";
} else { // if value is not empty
;
}
?>

My plugin.php file for callback looks like this:
PHP:
<?php
class XenForo_Pages_plugin
{
    public static function includePhpFile(XenForo_ControllerPublic_Abstract  $controller, XenForo_ControllerResponse_Abstract &$response)
    {
        ob_start();
        require('library/XenForo/Pages/test.php');
        $myContent = ob_get_contents();
        ob_end_clean();
 
        $params = array(
            'myContent'  => $myContent
        );
 
        $response->params = array_merge(
            $response->params,
            $params
        );
    }
}
 
I had one more question I wanted to ask...

I want to replace "media" in this code so it would show the page title of whatever page the user is on. How could I go about this?
Code:
<?php
$search = $_POST["kw"];
if ($search == '') // If value does not equal anything
{
$search = "media";
} else { // if value is not empty
;
}
?>
 
That may be available in $response->params. Do a dump in your callback function to see what's in there:

Code:
exit(var_dump($response->params));

$page['title'] should be available in there.
 
Thanks again, Jake. I finally got it with this:
PHP:
<?php
$search = (!empty($_POST["kw"]) ? $_POST["kw"] : '');
if ($search == '') // If value does not equal anything
{
$search = $response->params['page']['title'];
} else { // if value is not empty
;
}
?>

Thanks, kicken :)
 
I have everything working the way I want but I have one more problem I cannot figure out. I keep getting this error: Security error occurred. Please press back, refresh the page, and try again.
It happens when I select an option from the form below. The form is on a form.php page that is called by my included test.php page. Any help is greatly appreciated.

Code:
<script type="text/javascript">
<!-- Begin
function Sort_%%ID%%(){
  document.forms['sort_%%ID%%'].submit();
}
// End -->
</script>
<form name="sort_%%ID%%" id="sort_%%ID%%" method="post" action="" style="width:100%;margin:0; text-align:right;">
  <select name="sortnum_%%ID%%" onchange="Sort_%%ID%%();" style="width: 225px;">
    <option value="BestMatch">Best Match</option>
    <option value="EndTimeSoonest">Items Ending First</option>
    <option value="StartTimeNewest">Newly-Listed Items First</option>
    <option value="PricePlusShippingLowest">Price + Shipping: Lowest First</option>
    <option value="PricePlusShippingHighest">Price + Shipping: Highest First</option>
  </select>
<input name="country" type="hidden" value="%%country%%" />
</form>

It found this thread and it looks like I need to add this to my form but I am stuck on how to accomplish this.

Code:
<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
 
Rich (BB code):
<script type="text/javascript">
<!-- Begin
function Sort_%%ID%%(){
  document.forms['sort_%%ID%%'].submit();
}
// End -->
</script>
<form name="sort_%%ID%%" id="sort_%%ID%%" method="post" action="" style="width:100%;margin:0; text-align:right;">
  <select name="sortnum_%%ID%%" onchange="Sort_%%ID%%();" style="width: 225px;">
    <option value="BestMatch">Best Match</option>
    <option value="EndTimeSoonest">Items Ending First</option>
    <option value="StartTimeNewest">Newly-Listed Items First</option>
    <option value="PricePlusShippingLowest">Price + Shipping: Lowest First</option>
    <option value="PricePlusShippingHighest">Price + Shipping: Highest First</option>
  </select>
<input name="country" type="hidden" value="%%country%%" />
<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
</form>
 
Top Bottom