Reputation: 3214
I'm currently creating a form on a page in OctoberCMS that executes a PHP code block.
HTML/Twig:
{{ form_open({ request: 'onHandleForm' }) }}
Please enter a string: <input type="text" name="value"/>
<input type="submit" name='submitform' value="Submit me!"/>
{{ form_close() }}
<p>Last submitted value: {{ lastValue }}</p>
PHP:
function onHandleForm()
{
$this['lastValue'] = post('value');
}
As you can see this is very simple, PHP creates a twig tag with a value equal to the user input which is then output in the HTML.
However, every time I try to reload the page after posting something I get the error:
The page that you're looking for used information that you entered. Returning to that page might cause any action you took to be repeated. Do you want to continue?`
I've tried every method I can find but I can't get that error to stop coming up. I know it has something to do with the server trying to repost the same data when you reload the page but I can't for the life of me figure out how to fix it, I've tried every single method of reloading the page using PHP that I can find and none of them seem to work.
Please don't close this as a duplicate, if any of the existing posts helped me I wouldn't be making a new one.
Update: I'm not sure but it seems like reloading the page is not getting rid of the error: I just added onsubmit="window.location.reload()"
to my form and now when I submit it reloads the page but the error persists.
Upvotes: 2
Views: 3097
Reputation: 1799
You can refresh the page from the ajax handler inside controller if you return this:
return redirect()->refresh();
Upvotes: 4