XF 2.0 Passing values from a textbox to .php function

hutch2323

New member
Hello again!

I'm attempting to build a custom query page whereby a user (for admin use only) can enter a username into a textbox, click a search button, and retrieve the stored information connected to the username. Currently, I have blocks of code, but I'm not entirely sure how to combine it. Basically, I'm trying to figure out how to send the value from the myText textbox to my .php function.

HTML:
<!DOCTYPE html>
<html>
<body>

Search Name: <input type="text" id="myText" value="">

<button onclick="myFunction()">Search</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myText").value;
}
</script>

</body>
</html>

Here, the username will be stored in the variable x. I also have the callback created for this:

HTML:
<xf:callback class="\Test\QTest" method="getHtml" params="x"></xf:callback>

For the xf:callback, I'm not entirely sure where this should be placed. I would imagine within the javascript in the first HTML snippet, but I'm new to XF, so not 100% sure. I'm also not sure how the parameter should be passed to the function.

Then for the .php file, I currently have:

PHP:
<?php

namespace Test;

class QTest{

    public static function getHtml($contents, $params){
   
        $db = \XF::db();
        $email = $db->fetchOne('SELECT email FROM xf_user WHERE username = ?', $params);
        $timezone = $db->fetchOne('SELECT timezone FROM xf_user WHERE username = ?', $params);
        $output = "email: " . $email. " - timezone: " . $timezone. "<br>";
       
        return $output;
    }
}
?>

Not sure if this .php is correct or not. Not sure if I am using the $contents (if I even need it) and $params correctly. Any tips on how I can put this all together? I've tried a few different things but it doesn't seem to want to work for me.
 
Last edited:
Top Bottom