1

I am passing data from below sample .phtml file to controller:

<form name="sendsms" action="<?php $params = [];
echo $block->getUrl("admin_sms/Sendsms/SendSMS", $params); ?>" method="POST">
    Mobile Number: <input class="input-text admin__control__text" type="text" name="mobile_number"><br>
    Message Body :<textarea class="input-text admin__control__text" name="message_body"></textarea><br>
    <input type="submit" name="send_sms" class="ui-button-text" value="send SMS"><br>
</form>

Below is a controller:

<?php

namespace Vendor\module_name\Controller\Adminhtml\Sendsms;

use Magento\Backend\App\Action;

class SendSMS extends Action
{
    protected $_resultForwardFactory;

    /**
     * @param \Magento\Backend\App\Action\Context $context
     */
    public function __construct(
        \Magento\Backend\App\Action\Context $context
    )
    {
        parent::__construct($context);
    }

    /**
     * Forward to edit
     *
     * @return \Magento\Backend\Model\View\Result\Forward
     */
    public function execute()
    {
        echo "execute";
        die();
    }
}

Block file contains below getUrl function:

public function getUrl($route = '', $params = [])
{
    return $this->_urlBuilder->getUrl($route, $params);
}

When I am trying to submit form, it keep getting redirected to dashboard in admin panel.

1 Answer 1

1

Avoid declaring the $params array inside the action of <form> tag.

Also use $this->getUrl() instead of $block->getUrl()

Try this instead

<?php 
$params = [];
<form name="sendsms" action="<?php echo $this->getUrl("admin_sms/Sendsms/SendSMS",$params);?>" method="POST">
Mobile Number: <input class="input-text admin__control__text" type="text" name="mobile_number" /><br/>
Message Body :<textarea  class="input-text admin__control__text" name="message_body"></textarea><br/>
<input type="submit" name="send_sms" class="ui-button-text" value="send SMS"/><br/>
</form>
1
  • Thanks for the help. Yes, it was issue with $params array declaration inside form action, making changes as per your answer solved this problem. Jun 29, 2016 at 10:15

Your Answer

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

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