Magento Contact form in ajax - magento

I have a Contact form on the footer of my site. The form is loaded from contacts module( i.e contacts->form.phtml). When clicked on submit button it sends the mail but directs me to 'http://www.example.com/contacts/index/' . Instead of directing me to this page is it possible to send mail via ajax and stay on same page? Please help me..I am on top of this for more than a day.

you can do this without ajax , you need to modify `
public function postAction() in
app/code/core/Mage/Contacts/controllers/IndexController.php
and in this function replace
$this->_redirect('*/*/');
with
$this->_redirectReferer();
it will do your work without ajax , from which ever page you will submit form it will redirect you on same page after submit .
thanks and let me know if you have any problems in this.

Related

Ajax is not working on first click on submit in contact form 7

I have a form created in contact form 7. But Ajax submission is not working on the first click of submit. On first click it leads to URL like https://example.com/resolution-table-reservation-management-system/#wpcf7-f651-o1 and when click second time on submit the ajax works. I have checked that my header and footer have wp_head() and wp_footer(); functions. and also checked after deactivating all the other plugins. But still ajax is not working. Is there any solution to this? Please help. I don't know how to solve this.

how to create middleware in laravel

I have created the project which has login page login.blade.php which has only Regno to login-in.
once it login is the success it will redirect to home.blade.php and it followed by 4 more pages when clicking of next button in each page
page2.blade.php,page3.blade.php,page4.blade.php,page5.blade.php and finally, it should redirect to login page itself. The problem is the browser back button should not allow it to go back to the previous page.
can anyone suggest me how to create middleware for this?
thank you.
The browser's back button is not controlled by the server, where Laravel runs. There is no way for you to block it or interact with it in any way inside your PHP code.
What you can do is send XMLHHTTPRequest (XHR) with JavaScript. They ensure that on a button click you will stay on the same page in the browser and then your JS-code can read the server response (your rendered page templates) and replace the current content with the one from that response. You can read more on this when you google for AJAX, e.g. this article: https://www.sitepoint.com/use-jquerys-ajax-function/
Read this thing. I once implemented in the same way. By setting cache control in response header.
https://stackoverflow.com/a/51821808/10239067

Laravel route after post in same page ""

We are using Laravel, we have a form post on the "/",
$router->get('/', 'AppController#show');
The form is a script that appear through a modal window, once we post the form it uses route:
$router->post('/', 'AppController#store');
and function
public function store()
{
return view('app');
}
How we can stay on page without any return action after the post ?
With the current method it reloads the "/" page,
Are there a way to keep the "/" page as it is without reloading after the submit button?
Apologise for my english, i hope you understand our issue.
Thanks in advance,
You will need to make an ajax call to that resource. You can do with with plain javascript or you can use jQuery for this. $.post('/').
Dependant on your version, version 5.4 has a covenant axios.post method that you can use with Vue to send your ajax requests.
For a simple app jQuery may be the best simple option for you.

How to submit a form using codeigniter without changing the url?

I'm Unable to submit the form within the same page and getting result in the same page.
Put in the action of the your form the current URL.
action="<?php echo current_url();?>"
You probably need
redirect('controllerName')
So once you send data from the form to the controller, that controller does the processing and then redirects back to the index().
Use Ajax and Javascript to submit form without changing the url.

Handling redirects with Codeigniter and jQuery mobile?

I'm building a mobile web app with jQuery mobile and Codeigniter & TankAuth. When a user logs in or out, they are redirected from the TankAuth login/logout controller to a page of my choice. The problem is that while the ajax navigation loads the page in question, the URL to the TankAuth controller stays the same.
There is quite a lot of code involved, so I will describe it the best I can:
Consider the variable $this->session->flashdata('prev_page') is page1.
The TankAuth login controller is called first time via auth/login, loads login form view.
The form is submitted to the same controller which then processes it and redirects to necessary page:
if ($this->tank_auth->login(
$this->form_validation->set_value('login'),
$this->form_validation->set_value('password'),
$this->form_validation->set_value('remember'),
$data['login_by_username'],
$data['login_by_email'])) {// success
redirect($this->session->flashdata('prev_page'));
}
jQuery mobile loads page1 via AJAX but the URL remains as auth/login.
How do I fix this? Please let me know if you need any more info.
If my understanding about your problem is correct, you are using ajax for authenticating mobile users and normal redirect method for big screen users.
If that's the situation, then this will do the magic:
if ($this->tank_auth->login(
$this->form_validation->set_value('login'),
$this->form_validation->set_value('password'),
$this->form_validation->set_value('remember'),
$data['login_by_username'],
$data['login_by_email']))
{// success
$this->load->library('user_agent');
if($this->agent->is_mobile()) {
echo $this->session->flashdata('prev_page');
//Now this value 'll reach ajax when authentication is success.
//Inside Ajax:
//success: function(data) {
// validate data for checking if user is logged in or not.
// if(login_is_success)
// window.location.href = data;
//}
}
else
redirect($this->session->flashdata('prev_page'));
}
I added data-url="true" to the the form in opening <form> tag in question, everything worked fine from there.

Resources