• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

understand php callback

Kintaro

Well-known member
#1
Hi,
I'm trying to understand php callback but I miss something.

I have to make a new page in xenforo with a form and then manipulate the form's data.

form example:

HTML:
<form action="#" name="compute" method="post">
        <input type="checkbox" name="won" /><br />
        <input type="text" name="myRank" /><br />
        <input type="text" name="opponentRank" /><br />
        <input type="radio" name="geo" value="national" /><br />
        <input type="radio" name="geo" value="regional"/><br />
        <input type="radio" name="geo" value="provincial" /><br />
        <input type="submit" name="compute" value="Go!" />
        <a href="<?php echo $_SERVER["SCRIPT_NAME"];?>">Refresh</a>
    </form>
compute data example (same page):
PHP:
if(isset($_POST['compute'])){
    $points = ($_POST["won"] == "on") ? win($_POST["myRank"], $_POST["hisRank"]) : defeat($_POST["myRank"], $_POST["hisRank"]);
    echo $points;
}
now It's correct to use Xenforo Page to do something like this or is better make an add-on?
 
F

Floris

Guest
#4
A product, which is an add-on, in the form of a plugin. Basically we're talking about the same thing.

The limit is: how well can you code it in PHP?

You need to create a route, a controller, a public viewer, and code to handle the submitted data and templates to show different scenarios (form + result + potential error notices)

I made a plugin that lets you add an extra page, this takes care of everything for you, except your custom code, you'd have to edit the template to show the form, and write php code to handle the data that's submitted.

If you want the plugin let me know, I will open a PM with you on this site to get you the .zip
You can find more about the extra page add-on I made here. (just can't register or download from the site).
 

Kintaro

Well-known member
#5
Well, I'm a a beginner trying to learn.
Oh I think I have your add-on! I can't remember if I was registered to xenfans before the "archiving" or maybe downloaded here. I will try giving an eye on that code.
In case I will PM you.

Thank you again.