sebastiaan Posted July 16, 2018 Share Posted July 16, 2018 (edited) Good afternoon, i have made a module that gets child pages from my contact form, now i am trying to make it so you select checkboxes and then be able to delete them. since i wasnt able to make event listener on the .module i created a .js file where i handle al the logic but now i am stuck on the delete part since you cant reference $pages in the .js file how would i go about deleting pages commentManager.js commentManager.module Edited July 16, 2018 by sebastiaan added files Link to comment Share on other sites More sharing options...
elabx Posted July 16, 2018 Share Posted July 16, 2018 You cannot delete the pages directly from javascript, you have to make a call to the server. My recommendation from what I can tell from your module, is to turn the list of checkboxes into an actual form: $out = "<form action='.' method='post'>; Remember to close the form tag and also add a button for submit! Check the boxes, click the submit button an there goes the request to the server. You then check on your execute() method for the comment input like: public function ___execute() { if(count($_POST['comment']){ foreach($_POST['comment'] as $comment){ wire('pages')->delete($comment); } } //rest of the code One difference here from what I read on your code, the wire() function which holds all the PW variables you are used to use on templates. After you delete them, the rest of your logic can stay the same, as it will only find the pages that haven't been deleted. 3 Link to comment Share on other sites More sharing options...
sebastiaan Posted July 17, 2018 Author Share Posted July 17, 2018 10 hours ago, elabx said: You cannot delete the pages directly from javascript, you have to make a call to the server. My recommendation from what I can tell from your module, is to turn the list of checkboxes into an actual form: $out = "<form action='.' method='post'>; Remember to close the form tag and also add a button for submit! Check the boxes, click the submit button an there goes the request to the server. You then check on your execute() method for the comment input like: public function ___execute() { if(count($_POST['comment']){ foreach($_POST['comment'] as $comment){ wire('pages')->delete($comment); } } //rest of the code One difference here from what I read on your code, the wire() function which holds all the PW variables you are used to use on templates. After you delete them, the rest of your logic can stay the same, as it will only find the pages that haven't been deleted. thanks it worked 1 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