0

I am trying to store the value in custom table from admin form but it is always redirect to admin dashboard when I submit the form.

form page admin url: http://magentodev.gworks.mobi/magento2/admin/gworksrc/cancel/

<form action="/magento2/admin/gworksrc/cancel/" method="post">
 <input type="number" name="timeinterval" id="timeinterval" />
 <input type="submit" value="SUBMIT" id="timesubmit" />
</form>

I have tried with various type of action URL but nothing work

 action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>
 action=""
 action="<?php echo $this->getUrl('gworksrc/cancel/index'); ?>"

I found the same problem here, but it is syntax error but my form look simple I can't found any syntax error.

Thanks

7

You form must have form key to allow submit data. See formkey.phtml that used in core forms

0

Use this, I hope this is use full for you,

 action="<?php echo $this->getUrl('gworksrc/cancel'); ?>"
0

After put some efforts found solution.

In admin form you should need to add one hidden form input tag for carry session otherwise it redirects to admin dashboard page.

FormKey

<input name="form_key" type="hidden" value="<?php echo $block->updateCancelTime() ?>" />

Admin Form Look Like below

<form action="<?php echo $this->getUrl('gworksrc/cancel'); ?>" method="post">
 <input type="number" name="timeinterval" id="timeinterval" />
 <input type="submit" value="SUBMIT" id="timesubmit" />
 <input name="form_key" type="hidden" value="<?php echo $block->updateCancelTime() ?>" />
</form>

Admin Block for return form key

public function updateCancelTime(){

    return $this->formKey->getFormKey();
}

Reference: http://ka.lpe.sh/2012/09/13/magento-submitting-form-in-admin-redirects-to-dashboard/

above URL for Magento 1.X, I could covert into Magento 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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