Mackski Posted May 11, 2014 Share Posted May 11, 2014 I recently had an issue with email being sent twice, although the code was only being executed once.Turns out, the default method of wrapping a button in a <a> tag causes Firefox to abort the first request which subsequently fires off my email function, after which returning a 200 which fires it again. As far as I know, IE may not like the wrapping of a button in an anchor (although this is un-tested) Here is the offending code being used: $href = $this->config->urls->admin.'page/edit/?id='.$this->input->get->id.'&email_client=true'; $field = $this->modules->get('InputfieldButton'); $field->attr('id+name', 'email_client'); $field->attr('class', $field->class); $field->attr('value', 'Email Client'); $field->attr('href',$href); The work around is to not wrap the button in an anchor, rather use javascript onclick. $href = 'window.location.href="'.$this->config->urls->admin.'page/edit/?id='.$this->input->get->id.'&email_client=true"'; $field->attr('onclick',$href); Hope this helps someone in the future. Link to comment Share on other sites More sharing options...
Pete Posted May 11, 2014 Share Posted May 11, 2014 You shouldn't wrap a <button> tag in an <a> tag anyway. An <a> is for linking some text, a button is to do something on a form. You shouldn't mix the two together and your workaround isn't required either. Can you show us the rest of the form? There will almost certainly be a better way. You should have some sort of form action with the URL you're using above for a start that's part of (presumably) a $form that you've got elsewhere in your code, and the button should submit against that rather than what you're doing. Link to comment Share on other sites More sharing options...
Mackski Posted May 11, 2014 Author Share Posted May 11, 2014 Hi Pete, however InputfieldButton.module indicates otherwise: public function ___render() { $href = $this->attr('href'); if($href) $this->attr('href', ''); $out = parent::___render(); if($href) { $out = trim($out); $out = "<a href='$href'>$out</a>"; $this->attr('href', $href); } return $out; } This is the only reason I used the code in this way.To explain further, I wanted to append some custom buttons, with custom actions in the page edit form.Rather than create a new inputfield for a custom anchor, I just utilize the button.module.As you state, it's not a role of the button to achieve this. Just wondering why it's part of the core? 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