Sign in to follow this  
sebastiaan

delete pages from javascript

Recommended Posts

Posted (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 by sebastiaan
added files

Share this post


Link to post
Share on other sites

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. 

 

  • Like 3

Share this post


Link to post
Share on other sites
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

  • Like 1

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.