Marco Ro Posted April 18, 2018 Share Posted April 18, 2018 Hi guys, I'm not sure if this is a pw issue, anyway I would like to check. I have ajax call for a contact form that give me back every time an 404 error. I tried differente solution but doesn't work. I tried: <?php echo $config->urls->templates?> <?= $pages->get('/')->url ?> In both cases the url isn't wrong, but in console keep show me the 404 error. This is my ajax code var datiform = $("#Form").serialize(); $.ajax({ type: "POST", url: "<?php echo $config->urls->templates?>form/engine.php", data: datiform, crossDomain: true, dataType: "html", success: function(){ alert("success" + datiform); }, error: function(){ alert("no success " + datiform); } }); I can't understand why <?php echo $config->urls->templates?> not works, if it works well example for the pictures. Link to comment Share on other sites More sharing options...
Zeka Posted April 18, 2018 Share Posted April 18, 2018 3 Link to comment Share on other sites More sharing options...
Marco Ro Posted April 18, 2018 Author Share Posted April 18, 2018 There is a big world around PW! every time discover something new it leaves me speechless! But yes, don't have possibility to directly access php files in the "templates" directory and other locations in PW's file system it's really a great things! Good to know, I was going crazy o.o Thank you (again) @Zeka fro your support! 1 Link to comment Share on other sites More sharing options...
Marco Ro Posted April 19, 2018 Author Share Posted April 19, 2018 Sorry @Zeka there is the possibility the pw block or do something else to the data ? if I try to use parse_str to decode them not works? I mean I have this ajax: var data = $("#FormWksp").serialize(); //chiamata ajax $.ajax({ type: "POST", url: "form-wksp-engine.php", data: data, dataType: "html", success: function() { alert("success" + data ); }, error: function() { alert("no success " + data); } }); And then I try to take it in this way in the engine.php file $email = urldecode($_POST['email']); // this works $phone = urldecode($_POST['phone']); // this works $company = urldecode($_POST['company']); // this works $nation = urldecode($_POST['nation']); // this works $messaggio = urldecode($_POST['messaggio']); // this works $_POST_data = urldecode($_POST["data"]); // this no works $articles = []; parse_str($_POST_data, $articles); $nome = $articles['nome']; // this no works I will use the $articles for make a foreach($articles as $name => $value). But suppose the $_POST_data = urldecode($_POST["data"]) or $_POST_data = $_POST["data"] get the data, but is not so. Could be the pw in some way do something? Because now I move outside the root the engine.php for test it, and works, but this data not pass. Link to comment Share on other sites More sharing options...
Zeka Posted April 19, 2018 Share Posted April 19, 2018 @MarcoPLY You still posting to PHP file. Instead, you can create a template, for example 'ajax'. Create a template file for this template. Now you have endpoint URL for your requests. site.com/ajax/ Then in your template file, you can do something like if($config->ajax) { if($input->post->email) { do something } } else { // $session->redirect("/"); // or //throw new Wire404Exception(); } Furthermore, you can enable URL segments for 'ajax' template and then you will be able to make requests to URLs like 'ajax/form/', 'ajax/cta/' etc. if($input->urlSegment2) throw new Wire404Exception(); if(!$config->ajax) throw new Wire404Exception(); if($input->urlSegment1 && $input->urlSegment1 == 'form') { do something } Hope you got the main idea. 1 Link to comment Share on other sites More sharing options...
Marco Ro Posted April 19, 2018 Author Share Posted April 19, 2018 (edited) ok, but I have move outside pw the engine.php, now is in the same folder of site and wire folders. If I use the normal $email = urldecode($_POST['email']); I can take data to send the e-mail. so, I need anyway to make a template inside the site/template and create a template e page in the backend? I found the problem and not was about pw. I don't need use parse_str because the date are already in array. So $POST = $_POST; it's enough. Edited April 19, 2018 by MarcoPLY Link to comment Share on other sites More sharing options...
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