@@ -120,6 +120,75 @@ If you add the `--no-interaction` option when running the command, it will submi
120
120
121
121
If the submitted data is invalid the command will fail.
122
122
123
+
124
+ ## Using simpler forms with custom names
125
+
126
+ ``` php
127
+ <?php
128
+
129
+ use Symfony\Component\Console\Command\Command;
130
+ use Symfony\Component\Console\Input\InputInterface;
131
+ use Symfony\Component\Console\Input\InputOption;
132
+ use Symfony\Component\Console\Output\OutputInterface;
133
+ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
134
+ use Matthias\SymfonyConsoleForm\Console\Helper\FormHelper;
135
+
136
+ class TestCommand extends Command
137
+ {
138
+ protected function configure()
139
+ {
140
+ $this->setName('form:demo');
141
+ $this->addOption('custom-option', null, InputOption::VALUE_OPTIONAL, 'Your custom option', 'option1')
142
+ }
143
+
144
+ protected function execute(InputInterface $input, OutputInterface $output)
145
+ {
146
+ $formHelper = $this->getHelper('form');
147
+ /** @var FormHelper $formHelper */
148
+
149
+ $formData = $formHelper->interactUsingNamedForm('custom-option', ChoiceType::class, $input, $output, [
150
+ 'label' => 'Your label',
151
+ 'help' => 'Additional information to help the interaction',
152
+ 'choices' => [
153
+ 'Default value label' => 'option1',
154
+ 'Another value Label' => 'option2',
155
+ ]
156
+ ]);
157
+
158
+ // $formData will be "option1" or "option2" and option "--custom-option" will be used as default value
159
+ ...
160
+ }
161
+ }
162
+ ```
163
+
164
+ ## Nested Forms
165
+
166
+ If you have a complex compound form, you can define options and reference form children using square brackets:
167
+
168
+ ``` php
169
+ <?php
170
+
171
+ use Symfony\Component\Console\Command\Command;
172
+ use Symfony\Component\Console\Input\InputInterface;
173
+ use Symfony\Component\Console\Output\OutputInterface;
174
+ use Matthias\SymfonyConsoleForm\Console\Helper\FormHelper;
175
+
176
+ class TestCommand extends Command
177
+ {
178
+ protected function configure()
179
+ {
180
+ $this
181
+ ->addOption('user[username]', null, InputOption::VALUE_OPTIONAL)
182
+ ->addOption('user[email]', null, InputOption::VALUE_OPTIONAL)
183
+ ->addOption('user[address][street]', null, InputOption::VALUE_OPTIONAL)
184
+ ->addOption('user[address][city]', null, InputOption::VALUE_OPTIONAL)
185
+ ->addOption('acceptTerms', null, InputOption::VALUE_OPTIONAL)
186
+ ;
187
+ }
188
+ ...
189
+ }
190
+ ```
191
+
123
192
# TODO
124
193
125
194
- Maybe: provide a way to submit a form at once, possibly using a JSON-encoded array
0 commit comments