T
T
ta42016-01-08 17:55:06
Yii
ta4, 2016-01-08 17:55:06

How to place fields in a yii2 form that do not need to be sent, but need to be validated?

There is a form:

<?php $form = ActiveForm::begin(); ?>

                <?= $form->field($model, 'car')->textInput() ?>

                <?= $form->field((new \frontend\models\SignupForm(), 'phone')->textInput() ?>

                <?= Html::submitButton( 'Сохранить') ?>
    <?php ActiveForm::end(); ?>

The form has 2 input fields. When the user enters something in the second field and presses enter, I intercept it and make an ajax request that is not related to this form.
I need to disable the validation of this field when the user clicks "Save", and in general I do not need to submit with the form. Which way to look? Is it generally possible in yii2 to show a field not in a form and validate it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita, 2016-01-08
@bitver

A strange decision, I'm sure that your problem is not solved by interception and similar pandemoniums, but if it's on the topic, then display the field outside the form, who forbids it?
You can also try this <input type="<тип>" form="<идентификатор>">
PS What does the php and yii tags have to do with it? They don't belong at all. HTML and more.

A
Artem, 2016-01-09
@beardedman

Better in such cases, write the problem you are trying to solve. After several readings, I agree with the previous message - why are such pandemoniums made.
In addition, as I understand you have your ajax requests. Use the framework tools - pass the parameter to the form enableAjaxValidation' => true and set the validation parameters in the rules() method.

<?php $form = ActiveForm::begin(['id'=>'registration-form', 
    'enableAjaxValidation' => true]); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question