Hi guys, I have a weird problem.
I wrote a simple contact form (example url: /contact/form ) and I want to redirect the user to a thank you page after the submit.
The issue is that it doesn’t redirect the user but shows an alert showing the following message
{"X_OCTOBER_REDIRECT":"https:\/\/my-website.com\/contact\/thank-you-page"}
I tried to debug and i found the following behaviours while changing the form url:
- /contac/form - Removing the last char from “contact” in the url path IT WORKS!
- /contact/form - The desired url (with the final ‘t’ in ‘contact’ ) doesn’t work
- /contacts/form - Adding another char to ‘contact’, it doesn’t work.
I suppose there is some url conflicts but I checked every page and there are no pages that can conflict with it.
Here a little of my code:
contact/form.htm
{{ form_ajax('onSubmitForm') }}
<div class="row">
<div class="col-md-6 mb-1">
<input type="text" class="form-control" name="name" placeholder="Name *" required />
</div>
<!-- ... other fields like above (surname, email, subject, text) -->
<!-- Submit button -->
<div class="col-md-6 mt-4 text-end">
<button type="submit" id="btn-send-contact" class="btn btn-white">Send</button>
</div>
</div>
{{ form_close() }}
ContactForm.php
class ContactForm extends ComponentBase
{
public function componentDetails()
{
//...
}
public function defineProperties()
{
return [
//...
'thankYouPage' => [
'title' => 'Thank you page title',
'description' => 'Thank you page description',
'type' => 'dropdown',
'default' => ''
]
];
}
public function getThankYouPageOptions()
{
return Page::sortBy('baseFileName')->lists('baseFileName', 'baseFileName');
}
public function onSubmitForm()
{
$r = Request::all();
// Field validation (works well)
// ...
// Email send (works well)
// ...
// Redirect to Thank you page - Doesn't work with desired URL
return Redirect::to($this->pageUrl($this->property("thakYouPage")));
}
}
I tried to rewrite the entire contact form page from scratch with another url (/test), including only my component first, then styles, them scripts, then other components, then including layout and making the page identical to the original contact form page: it always worked.
Then I tried to change the file name to the original contact form page file name: it worked.
Finally, changing the url makes the error appear.
Can anyone help me?