0

I have a custom module for generate random keys. The concept is when admin clicks the add new button it will automatically creates the random codes, at the time of editing i have removed all buttons and added extra field button to send mail. Upto this i have no problem, but at the time of clicking send mail button i am facing problem,

I have written some scripts for onclick event, Edit/Tab/Form.php:

$fieldset->addField('promo_email', 'text', array(
                            'label' => Mage::helper('promogenerator')->__('Send Mail'),
                            'name'  => 'promo_email',
                            'after_element_html' => '<button type="button" onclick="sendmail()">Send Mail</button>' 
                        ));

I have written the scripts at, Edit.php:

$this->_formScripts[] = "

    function sendmail(){
        var email = jQuery('#promo_email').val(),
        code = jQuery('#promocode').val();
        window.location.href = '{$this->getUrl(`*/*/send`, array(`id` => $this->getRequest()->getParam(`id`)))}';
    }
";

the problem is in url, the script function not redirect me to the send url, it redirects me to the index page.

I really don't know how to give the url in scripts. Can someone point me the correct solution.

1 Answer 1

1

Instead of $this->getUrl try using

Mage::helper('adminhtml')->getUrl(....);

[EDIT]
Change your formScripts to this

$this->_formScripts[] = "

    function sendmail(){
        var email = jQuery('#promo_email').val(),
        code = jQuery('#promocode').val();
        window.location.href = '".$this->getUrl(`*/*/send`, array(`id` => $this->getRequest()->getParam(`id`)))."';
    }
";
5
  • Thanks @Marius. but it is redirect me to promogenerator/edit/id/5/key/3420826223a1e7a36245f1c9649bdd91/%7BMage::helper(%60adminhtml%60)->getUrl(%60*/*/send%60,%20array(%60id%60%20=>%20()->getParam(%60id%60)))%7D
    – Gayathri
    Commented Oct 1, 2015 at 8:27
  • @Astro See my update.
    – Marius
    Commented Oct 1, 2015 at 8:31
  • I am getting page not found error.. but i have sendAction function at my controller.
    – Gayathri
    Commented Oct 1, 2015 at 8:36
  • Try debugging step by step. I got it to redirect properly. That's all I could do for now.
    – Marius
    Commented Oct 1, 2015 at 8:38
  • the error in single quotes, its working fine after correcting the quotes window.location.href = '".$this->getUrl('*/*/send', array('id' => $this->getRequest()->getParam('id')))."';
    – Gayathri
    Commented Oct 1, 2015 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.