bytesource Posted August 14, 2014 Posted August 14, 2014 Hi, I am trying to handle a form submit using the JQuery ajax function. However, the following always results in a 404 page not found error: <?php $subscribe = $config->paths->templates . 'includes/partials/' . 'subscribe.php'; ?> [...] $.ajax({ url: "<?php echo $subscribe ?>", data: $('#subscribe').serialize(), type: 'POST', [...] After submitting the form, I always get the following error in Google Chrome's page inspector: POST: http://localhost:8080/home/sovonex/Programs/rubystack-2.0.0-12/apps/processwire/htdocs/site/templates/includes/partials/subscribe.php 404 (Not Found) Including PHP files into template files has not caused any problems before, but here something seems to be different, and I suspect it has to do with how POST requests are handled. Cheers, Stefan
Nico Knoll Posted August 14, 2014 Posted August 14, 2014 I think that it is not possible to directly access php files in the "templates" directory (because if everyone could do it it would be a big insecurity). Of course you can include them via PHP because this get's rendered before the page is returned to the user. But jQuery/Javascript acts more like a real user. And for them everything (except images, javascript files, stylesheets, etc.) in /site/ and in /wire/ is locked. What you have to do: Create a template in the backend called e.g. "subscribe". Then create a page using this template e.g. named "subscribe", too. You now can access this page via http://localhost:8080/home/sovonex/Programs/rubystack-2.0.0-12/apps/processwire/htdocs/subscribe/ or something similar. That's the page you should point your post request on. 1
kongondo Posted August 14, 2014 Posted August 14, 2014 See some other options by Ryan here: https://processwire.com/talk/topic/407-processing-contact-forms/?p=3106
bytesource Posted August 14, 2014 Author Posted August 14, 2014 Handling the PHP file as a PW template worked like a charm! Thanks a lot for your help! 1
kongondo Posted August 14, 2014 Posted August 14, 2014 Good to know. I have marked Nico's post as the best answer given his solution worked for you. Btw, I am curious why you were getting 404s as opposed to 403s? 1
Nico Knoll Posted August 14, 2014 Posted August 14, 2014 I guess that's somehow a javascript / jQuery thing (404 instead of 403). Maybe it just recognized that the page is not accessible and therefore can not be found. http://stackoverflow.com/questions/17509717/jquery-returns-status-code-404-instead-of-403 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now