4

In cakephp 3 I got error Unexpected field in POST data. Actually that field is not in my table, but I want to use in controller.

Masud
  • 61
  • 1
  • 2
  • 1
    Welcome to StackOverflow my Friend! Please show us your code if you want us to help you! Else your question could be closed, because it is to broad to answer right now.. – Carl0s1z Jul 19 '17 at 08:34

2 Answers2

8

The Security Component in CakePHP is not forgiving. If you want to allow a field thru that should not go thru the Security Component hashing process, you need to use the unlockedField method that comes with the FormHelper class as such:

$this->Form->unlockField('field');

If this does not work, you will need to provide us with the pertinent code

AKKAweb
  • 3,795
  • 4
  • 33
  • 64
0

I was getting the similar error in cakephp 3.4 I was using the simple html form and input fields. I was passing the input fields data in array. like below:-

<form action="" method="post">    
<input name="data[1][category_1]" id="category_1">
</form>

Then i do some R&D and found that we need to use the cakephp form helper to create the form and its fields like below :-

In case of pass form data in array

<?= $this->Form->create($user, ['url' => ['controller' => 'Users', 'action' => 'saveOrder']]); ?>
    <?= $this->Form->input("Data.1.category_1"); ?>
<?= $this->Form->end() ?>

In case of simple input fields you can do the code like below

<?= $this->Form->create($user, ['url' => ['controller' => 'Users', 'action' => 'saveOrder']]); ?>
    <?= $this->Form->input("category"); ?>
<?= $this->Form->end() ?>

This work form me and resolve the error Unexpected field in POST data in cakephp 3.4

kantsverma
  • 606
  • 1
  • 11
  • 31