Version: 2.9.2 Reporter: whitespace —
This is an archived bug report. If you are experiencing a similar issue, upgrade to the latest release and if that does not solve the problem, submit a new bug report
The
form_backtrack()
ee()->session->tracker
array.
0 => ‘pages/three’,
1 => ‘pages/two’,
2 => ‘pages/one’
If a form is declared with
ee()->functions->form_declaration()
then the form action URL is the site’s index page. Hence when the form is submitted, ‘index’ is pushed into the first position in the tracker array.
0 => ‘index’,
1 => ‘pages/three’,
2 => ‘pages/two’,
3 => ‘pages/one’
We can use
ee()->functions->form_backtrack('1')
to send the user back to the form page, which would be ‘pages/three’ here. (NB: the documentation for form_backtrack() at https://ellislab.com/expressionengine/user-guide/development/usage/functions.html#form-backtrack suggests that a negative number should be passed as the argument, but this didn’t work for me, and I can’t see how it would after looking at the code in /libraries/Functions.php)
However: the tracker functionality will not duplicate page references, so if the user is submitting a form from the site’s index page, the tracker array will not change – e.g. if the user has previously visited ‘pages/four’, the contents of the tracker array would be the same both before and after submission:
0 => ‘index’,
1 => ‘pages/four’
Thus, if we want to redirect the user back to the site index (where they submitted the form) having visited other pages prior to arriving on the index page,
ee()->functions->form_backtrack('1')
will send them to the immediately previous page (‘pages/four’ in the example above) instead of back to the site index.
Since this seems to be
form_backtrack()
‘s sole purpose, it would be helpful if it handled this special case automatically.
To get around this issue I’ve added a check as to whether the current page is the site index when declaring the form, and passing through an additional hidden form field if so:
$form_details = array(
'id' => 'form_id',
'hidden_fields' => array(
'ACT' => $this->EE->functions->fetch_action_id('Module_name', 'function_name'),
),
);
if ($this->EE->session->tracker[0] == 'index') {
$form_details['hidden_fields']['homepage'] = '1';
}
return $this->EE->functions->form_declaration($form_details);
Then, within the function bound to the action:
// redirect to index page if we came from there, previous page otherwise
header('Location: ' . ($this->EE->input->post('homepage', TRUE) ? $this->EE->functions->form_backtrack(0) : $this->EE->functions->form_backtrack(1)));
ExpressionEngine implements Markdown Extra and BBCode. Please see the Markdown Extra docs and the BBCode Wikipedia article for a full reference.
**bold**
, __bold__
, *italics*
, _italics_
, ~strike/del~
, `code()`
bold, italics, strike/del, code()
Link: [link title](https://example.com)
Image: ![alt text](https://example.com/image.jpg)
[blockquote]...[/blockquote]
, [quote]...[/quote]
, and Markdown style:
> Some quoted text. > > This is all one quote.
[code]...[/code]
, and you can also specify the language for syntax highlighting, [code=php]...[/code]
GitHub flavored Markdown code fences are also supported:
``` public function decoderRing($str) { return str_rot13($str); } ```