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

asked May 18, 2016 at 5:29

3 Answers 3

8

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

answered May 18, 2016 at 6:39
0
0

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

 action="<?php echo $this->getUrl('gworksrc/cancel'); ?>"
answered May 18, 2016 at 5:59
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

answered May 18, 2016 at 6:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.