M
M
Michael2016-12-02 23:22:33
Magento
Michael, 2016-12-02 23:22:33

How to build a form in Magento 2?

I'm working on a survey with showing different types of response fields and the possibility of editing in the future (by the client). All fields will be called to display by key.
There was a problem with models and form generation.
What's in Magenta?
It uses models, repositories, registers, and interfaces to provide work with objects. If you need to link components, clients and addresses, for example, then methods for working with addresses are added to the client model.
How does it usually happen?
For a form, a block with dependencies on the repository and the form itself is enough; on the landing page save data.
What is already there?
For the survey, I created basic models, for the survey itself, I also created a "body kit" in the form of an interface, a repository, and a register.
I'm trying to figure out how to combine questions + answers + results.
Do I need to write a "body kit" for all components (survey, survey-answ, survey-quest, surv-res) of the survey?
How do I combine questions and answers and saved answers? Maybe you need a special helper or enough special methods in models like getResultAnswer($questId, $customerId).
I would like to do this:

<?php
$question = $block->getQuestion('identifier');
$questionText = $question->getQuestion();
$questionAnswers = $question->?
$questionFieldType = $question->getFieldType();

echo $questionText;
...
print select | radio | checkbox
?>

In general, point to the true path.
I hope that after many rewriting of the question it became clearer :)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question