Hi,
I'm just trying to create a button which when you click it will run a php file that adds a page (without page refresh):
This is the jquery/ajax:
<script>
$(document).ready(function(){
$("button").click(function(){
$.post("/site/templates/func_addpage.php/", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
});
</script>
<button id="but_add">Add to wishlist</button>
This is the php file I'm trying to run "func_addpage.php"
<?php namespace ProcessWire;
/* add to a page object with parent path and new pages template name */
$newPage = $pages->add('prod_ratings', '/wishlists', $randTitle, array(
'title' => $sanitizer->text($randTitle),
'api_test_hash' => $randHash
))->setOutputFormatting(true);
?>
This code works if I just run it to the page on it's own, without a button click.
The issue is when I try to run the php file by using a button click, I just receive an error.
I've been reading up on this in the documentation and forum, and I can't seem to find a solution.
I've tried making the php file a template, and then trying to call it. I've tried moving the php file into a folder in the root directory, instead of the templates folder.
Any guidance would be appreciated. Thanks.