Mackski Posted November 5, 2013 Share Posted November 5, 2013 Hi Guys, I'm trying to add an additional button when editing a page in admin. "Save and email".The idea is to save the form, then email it's contents using a template to the supplied email address, such as a booking confirmation, or order confirmation. I've been able to hook and create the button, however I cant seem to work out how to progmatically save the form.As far as I can tell, the button submit's the form but $input->post is empty. Link to comment Share on other sites More sharing options...
ryan Posted November 9, 2013 Share Posted November 9, 2013 There is actually a redirect between the form save and the next form edit. Meaning, you don't get to see anything when the form is actually saving. For debugging purposes in this case, you can use $this->message("your debug message"); and it will be queued for the next page view. If it helps with debugging, you can also temporarily comment out the $session->redirect() in ProcessPageEdit.module. Link to comment Share on other sites More sharing options...
Mackski Posted November 30, 2013 Author Share Posted November 30, 2013 Thanks Ryan,I ended up hooking into ProcessPageEdit::buildForm: $this->addHook('ProcessPageEdit::buildForm', $this, 'addButton'); public function addButton(HookEvent $event) { $href = $this->config->urls->admin.'page/edit/?id='.$this->input->get->id.'&e=1'; $field = $this->modules->get('InputfieldButton'); $field->attr('id+name', 'email_customer'); $field->attr('class', $field->class); $field->attr('value', 'Email Booking To Customer'); $field->attr('href',$href); $event->return = $event->return->append($field); } I then just check for $_GET['e'], and undertake the workflow needed, and redirect back to the original edit page.A bit of a circus, but gets the job done.Is there a better way to utilize hooks for custom workflows like this? 1 Link to comment Share on other sites More sharing options...
ryan Posted December 6, 2013 Share Posted December 6, 2013 If you don't need the page to be saved when the button is clicked, then I think the route you are taking is fine. If you did need the page to be saved, then you'd want your button to be a submit button, and a second (save) hook to be called after the ProcessPageEdit::processInput and to silently do its thing (no redirect). Another route you could take is to setup a separate page with a template that does what you want, and then have your button link to that instead. But the way you've done it is already more compartmentalized (less parts to consider) so I wouldn't change it unless it creates issues with other modules hooking into ProcessPageEdit at some point down the road (which is possible). One issue you probably want to fix here though is the potential for XSS: $href = $this->config->urls->admin.'page/edit/?id='.$this->input->get->id.'&e=1'; Taking a variable directly from $_GET or $input->get and putting it in output (unsanitized) is always dangerous. You'd want to do this: $id = (int) $this->input->get->id; $href = $this->config->urls->admin."page/edit/?id=$id&e=1"; or better, yet this: $id = (int) $event->object->getPage()->id; $href = $this->config->urls->admin."page/edit/?id=$id&e=1"; 5 Link to comment Share on other sites More sharing options...
landitus Posted February 22, 2014 Share Posted February 22, 2014 If you don't need the page to be saved when the button is clicked, then I think the route you are taking is fine. If you did need the page to be saved, then you'd want your button to be a submit button, and a second (save) hook to be called after the ProcessPageEdit::processInput and to silently do its thing (no redirect). Another route you could take is to setup a separate page with a template that does what you want, and then have your button link to that instead. But the way you've done it is already more compartmentalized (less parts to consider) so I wouldn't change it unless it creates issues with other modules hooking into ProcessPageEdit at some point down the road (which is possible). I'm am trying to accomplish a Save and notify button which Ryan's mention that has to have a second save hook. I'm starting with the code for the button (the same Mackski) but I have no idea how to attach this button to save action. How would you implement such hook? 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