Magento 2 – How to Get Form Data to Controller

formsmagento2

I have created a custom module in which I have created a form like this

    <form action="<?php echo $this->getUrl('AdminSample/sampleOne/index');?>" method="post" enctype="multipart/form-data">
<table id="views" width="900px">
<tr>
    <td>View 1:</td>
        <td><input data-form-part="product_form" type="file" name="fileToUpload1" id="fileToUpload" required ></td> 
</tr><tr>
    <td>View 2:</td>
        <td><input data-form-part="product_form" type="file" name="fileToUpload2" id="fileToUpload" required></td>
</tr><tr>
    <td>View 3:</td>
        <td><input data-form-part="product_form" type="file" name="fileToUpload3" id="fileToUpload" required></td>
</tr><tr>
    <td>View 4:</td>
        <td><input data-form-part="product_form" type="file" name="fileToUpload4" id="fileToUpload" required></td>
</tr><tr>
    <td>View 5:</td>
        <td><input data-form-part="product_form" type="file" name="fileToUpload5" id="fileToUpload" required></td>
</tr><tr>
    <td>View 6:</td>
        <td><input data-form-part="product_form" type="file" name="fileToUpload6" id="fileToUpload" required></td>
</tr><tr>
    <td>View 7:</td>
        <td><input data-form-part="product_form" type="file" name="fileToUpload7" id="fileToUpload" required></td>
</tr><tr>
    <td>View 8:</td>
        <td><input data-form-part="product_form" type="file" name="fileToUpload8" id="fileToUpload" required></td>
</tr><tr>
    <td>View 9:</td>
        <td><input data-form-part="product_form" type="file" name="fileToUpload9" id="fileToUpload" required></td>
</tr><tr>
    <td>View 10:</td>
        <td><input data-form-part="product_form" type="file" name="fileToUpload10" id="fileToUpload" required></td>
</tr><tr>
    <td>View 11:</td>
        <td><input data-form-part="product_form" type="file" name="fileToUpload11" id="fileToUpload" required></td>
</tr><tr>
    <td>View 12:</td>
        <td><input data-form-part="product_form" type="file" name="fileToUpload12" id="fileToUpload" required></td>
</tr>
</table>


<br><br><br>
<h2>Parts & Colors</h2>
    <input type="button" onclick="addTable()" value="Add Part">
<div id="divResults">
    </div>

<button type="submit">Save</button>
</form>

and i have called custom controller, but i'm getting redirect to admin dashboard. Is there anything wrong in this code?
Please help me to get all images descriptions like name, tmp_name, size and type?

Please ask, If any additional information required to anyone.

This is custom controller i write

<?php
namespace Tym17\AdminSample\Controller\Adminhtml\SampleOne;

class Index extends \Magento\Backend\App\Action
{
  /**
  * Index Action*
  * @return void
  */

    protected $resultRawFactory;



        public function __construct(\Magento\Backend\App\Action\Context $context) {
             parent::__construct($context);
        }
  public function execute()
  { 

    echo "one";
    print_r($_POST);die;
  }
}

Best Answer

Seem that you're missing the form key:

<input name="form_key" type="hidden" value="<?php /* @escapeNotVerified */ echo $block->getFormKey(); ?>" />
Related Topic