MSP01 Posted March 21, 2018 Share Posted March 21, 2018 Hi, We have a simple submission form where people can sign up. This sends an email to the person signing up. To allow submitter to remove themselves we sen a link with randomized unique ID along with the email. This unique ID is also part of the repeating field. How would one use an external link like this to either delete or disable one of the fields in a repeating field? Should we make a page that catches the ID and runs a hook based on that, or is there a better way? Link to comment Share on other sites More sharing options...
Zeka Posted March 21, 2018 Share Posted March 21, 2018 @MSP01 You can create endpoint (template and page) where you can catch get parameters like ?unsubscribe=140530045 or ?disable=140530045 then do something like if($input->get->unsubscribe || $input->get->disable) { $subscription = $pages->get($sanitizer->pageName($input->get->unsubscribe)); if($subscription->id && $input->get->unsubscribe) { $pages->trash($subscription); } elseif ($subscription->id && $input->get->disable) { ... logic for disabling user subscription } } 2 Link to comment Share on other sites More sharing options...
MSP01 Posted March 28, 2018 Author Share Posted March 28, 2018 Hi, The input part is working fine, and gets passed to a form the user will use to confirm the deletion. A hook is ran when confirmation form is submitted, but frankly I'm very much stuck with actually deleting the repeater item part. $forms->addHookBefore('FormBuilderProcessor::saveForm', function($event) { $sanitizer = wire('sanitizer'); $page = wire('page'); $pages = wire('pages'); $form = $event->arguments(0); if($form->name != 'removesubmission' && $page->template != 'removeSubmission') return; $removeKey = $form->getChildByName('remove_deletekey')->value; $eventPage = $pages->get('template=event, eventParticipant.eventParticipant_deletekey='.$removeKey); if (!empty($eventPage->id)) { $eventPage->of(false); $removeParticipant = $eventPage->eventParticipant->find("eventParticipant_deletekey=".$removeKey); $eventPage->eventParticipant->remove($removeParticipant); $eventPage->save(); } }); There's lots of stuff missing still. But right now I'm just trying to kill the repeater (eventParticipant) item. So a deletekey gets passed from input into the confirmation form. This is picked up in the hook ($removeKey). The correct page and repeater item are found. But how do you actually delete the item? I've been looking into it for several hours now and no luck. The form runs, no errors, but nothing happens either. Link to comment Share on other sites More sharing options...
MSP01 Posted March 28, 2018 Author Share Posted March 28, 2018 I guess I just solved this myself. I needed to use get instead of find in the: $removeParticipant = $eventPage->eventParticipant->find("eventParticipant_deletekey=".$removeKey); Or possibly use the include=hidden. Oh well. It works. 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