nerdexam
Adobe

AD0-E716 · Question #2

An Adobe Commerce Developer is tasked with creating a custom form which submits its data to a frontend controller They have decided to create an action and have implemented the…

The correct answer is C. Form key validation runs on all non-AJAX POST requests, the developer needs to add the for_key. According to the Magento Stack Exchange answer, form key validation is a security feature that prevents CSRF attacks by checking if the form key in the request matches the one generated by Magento. If the developer does not include the form_key in their custom form, the…

Security

Question

An Adobe Commerce Developer is tasked with creating a custom form which submits its data to a frontend controller They have decided to create an action and have implemented the \Magento\Framework\App\Action\HttpPostActioninterface class, but are not seeing the data being persisted in the database, and an error message is being shown on the frontend after submission. After debugging and ensuring that the data persistence logic is correct, what may be cause and solution to this?

Options

  • AMagento does not allow POST requests to a frontend controller, therefore, the submission
  • BThe developer forgot to implement a validatePostDataQ method in their action. They should
  • CForm key validation runs on all non-AJAX POST requests, the developer needs to add the for_key

How the community answered

(67 responses)
  • A
    13% (9)
  • B
    7% (5)
  • C
    79% (53)

Explanation

According to the Magento Stack Exchange answer, form key validation is a security feature that prevents CSRF attacks by checking if the form key in the request matches the one generated by Magento. If the developer does not include the form_key in their custom form, the validation will fail and an error will be shown. Therefore, the developer needs to add the form_key to their requests by using <?= $block->getBlockHtml ('formkey') ?> in their template file. Verified Reference: https://magento.stackexchange.com/questions/95171/magento-2-form-validation

Topics

#form key validation#CSRF protection#frontend controller#POST request

Community Discussion

No community discussion yet for this question.

Full AD0-E716 Practice