Passing a message from Source to Template

Started by Alex4108, March 10, 2012, 08:08:31 PM

Previous topic - Next topic

Alex4108

So I'm stuck... yet again coding with SMF.

I have an addition to the Forum Shop mod, that allows me to give credits to just one user.  The page is structured a bit like this:

<input fields>
<submit button to index.php?action=actions;step=2>

From what I understand, this is a bit how the SMF System will run when I click Submit

1. Go to Sources, and run the function for step=2
2. Load the Template that the Source calls in step=2 (In this case, being ShopAdmin2)

What I need to do, is pass a message from when the Source runs (if everything was okay, any errors, etc.) to the Template page. 

Originally, I thought maybe a $context['blah']['blahblah'] = "MESSAGE"; method would work, but the Template was not too thrilled with that.
I also can't really set $_GET or $_POST values, so those are out of the question.

So my question, is how should I pass a message from a Source to a Template?

live627


Alex4108


Suki

Why you can't set get or post vars?

step is a get var.

You also don't need a separate function, you can manipulate the form data in the same function by doing:

if (isset($_GET['step']) && $_GET['step'] == 2)
{
// code to validate/manipulate the form data, here you can set a custom message too

if (something_went_wrong)
$context['custom_error'] = $txt['my_custom_error'];

}

and on your template you simple call $context['custom_error']   wherever you want it to appear, you set $context['custom_error'] as null by default (inside the same function) so it only appears if an error occur when someone hit the save button


If you want to use  separate page, then you need to specify your own action int he form and create that action in de action array on index.php or create it via hooks:

<form action=', $scripturl ,'?action=myownaction
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Advertisement: