Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/styllloz/public_html/qa-include/qa-base.php on line 1175

Warning: session_start(): Cannot start session when headers already sent in /home/styllloz/public_html/qa-include/app/users.php on line 162

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/users.php on line 1267

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/page.php on line 356
Reconfigure the HTML form ActiveForm in yii2? - code-flow.club | Q&A

Reconfigure the HTML form ActiveForm in yii2?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
18 views
Hello, have a complex shape for me, help her cheat on ActiveForm

Here is the form HTML:


Here are my settings:

<?php $form = ActiveForm::begin(['method' => 'POST', 'id' => 'appointment_form']); ?> <?= $form->field($model, 'name1', ['inputOptions' => ['class' => 'input__field input__field--kohana', 'id' => 'input-29']])->label([ 'class' => 'input__label input__label--kohana', 'for' => 'input-29', 'template' => 'Your Name{label}' ]); ?><?= $form->field($model, 'email1', ['inputOptions' => ['class' => 'input__field input__field--kohana', 'id' => 'input-30']])->label([ 'class' => 'input__label input__label--kohana', 'for' => 'input-30', 'template' => 'the Email Address{label}' ]); ?><?= $form->field($model, 'phone', ['inputOptions' => ['class' => 'input__field input__field--kohana', 'id' => 'input-31']])->label([ 'class' => 'input__label input__label--kohana', 'for' => 'input-31', 'template' => 'Phone Number'{label}' ]); ?><?= $form->field($model, 'datepicker', ['inputOptions' => ['class' => 'input__field input__field--kohana', 'id' => 'datepicker']]); ?><?= $form->field($model, 'body1', ['inputOptions' => ['class' => 'input__field input__field--kohana', 'id' => 'textarea']])->label([ 'class' => 'input__label input__label--kohana', 'for' => 'textarea', 'template' => 'Message{label}' ]) ?><?php ActiveForm::end(); ?>


Here is the controller:
/** * Displays the homepage. * * @return string */ public function actionIndex() { /* Create an instance of the class */ $model = new AppointmentForm(); /* get the data from the form and run the function send contact, if all is well, print message on successful sending a message to the mail */ if ($model->load(Yii::$app->request->post()) && $model->appointment(Yii::$app->params['adminEmail'])) { Yii::$app->session->setFlash('contactFormSubmitted'); return $this->refresh(); /* otherwise, print the feedback form */ } else { return $this->render('index'); } }


Model:

/** * Sends an email to the specified email address using the information collected by this model. * @param string $email1 the target email address * @return bool whether the model passes validation */ public function appointment($email1) { $content = "Email: ". $this->email1 . ""; $content .= "Name: ". $this->name1 . ""; $content .= "Phone: ". $this->phone . ""; $content .= "Datepicker: ". $this->datepicker . ""; $content .= "Body: ". $this->body1 . ""; if ($this->validate()) { Yii::$app->mailer->compose("@app/mail/layouts/html", ["content" => $content]) //->setTo($email) ->setTo('swallowsveta97@yandex.ru') ->setFrom([\\Yii::$app->params['supportEmail'] => $this->name1]) //->setFrom([$this->email => $this->name]) //->setFrom('swallowsveta97@yandex.ru') //->setFrom([\\Yii::$app->params['supportEmail'] => $this->name]) ->setPhone($this->phone) ->setDatepicker($this->datepicker) ->setTextBody1($this->body1) ->send(); return true; } return false; }


But the error I encountered:

1. in C:\\Users\\acer\\OSPanel\\domains\\medicalyii2\\vendor\\yiisoft\\yii2\\helpers\\BaseHtml.php at line * See [[getAttributeName()]] for explanation of attribute expression. * * @param Model $Model the model object * @param string $attribute the attribute name or expression * @return string the generated input name * @throws InvalidArgumentException if the attribute name contains non-word characters. */ public static function getInputName($model, $attribute) { $formName = $model->formName(); if (!preg_match(static::$attributeRegex, $attribute, $matches)) { throw new InvalidArgumentException('Attribute name must contain word characters only.'); } $prefix = $matches[1]; $attribute = $matches[2]; $suffix = $matches[3]; if ($formName === " && $prefix === ") { return $attribute . $suffix; } elseif ($formName !== ") { 2. yii\\base\\ErrorHandler::handleFatalError()
by | 18 views

1 Answer

0 like 0 dislike
A bit reduced Your code to generate the form.
<?php\r$form = ActiveForm::begin([\r'id' => 'appointment_form', 'fieldConfig' => [ 'options' => [ 'tag' => 'span', 'class' => 'input input--kohana' ], 'template' => '{input}{label}{error}', 'inputOptions' => ['class' => 'input__field input__field--kohana'], 'labelOptions' => [ 'class' => 'input__label input__label--kohana', ] ] ]); ?> <?= $form->field($model, 'name')->textInput()->label("" . $model->getAttributeLabel('name') . "") ?> <!-- ОСТАЛЬНЫЕ ПОЛЯ ФОРМЫ  -->\r<?= $form->field($model, 'body')->textInput()->label() ?> <?= Html::submitButton('Submit'); ?>\r<?php\rActiveForm::end();\r?>

I think that it would be better. Some of the attributes for fields you add yourself, if necessary.
That's just a template for a label not entirely sure it is possible that it can duplicate, but do not come up as.

p.s. Before this line is not necessary to form a variable and then pass it to email template.
Simply pass the model.
// Remove!!! /* $content = "Email: ". $this->email1 . ""; $content .= "Name: ". $this->name1 . ""; $content .= "Phone: ". $this->phone . ""; $content .= "Datepicker: ". $this->datepicker . ""; $content .= "Body: ". $this->body1 . "";*/ if ($this->validate()) { Yii::$app->mailer->compose("@app/mail/layouts/html", ["content" => $this])

And in the template to process and generate html.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Apr 13, 2019 by julia_____kuleshova
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
35,181 users