N
N
Nikita Ronzin2017-03-21 17:41:01
Yii
Nikita Ronzin, 2017-03-21 17:41:01

How to write a rule to check for non-empty lines and save them?

So I save the data from the tabular form to the database, I need to write a rule that would check that if the string is empty then do not save if it is filled then save

<code lang="php">
protected function populatePhoneForFioID($fioId, $typeId, $phoneNumber) {
        if(!empty ($_POST['Number']) ){
        $phone = new Phone;
        $phone->FIO_ID = $fioId;
        $phone->Type_ID = $typeId;
        $phone->Number = $phoneNumber;

            $phone->save();
        }

  }
</code>
<div class="row">
            <?php echo CHtml::form();
            $data2 = CHtml::listData(Type::model()->findAll(), 'ID', 'Type_Phone');
            foreach ($data2 as $key => $value){
                echo $form->hiddenField($phone, '['.$key.']Type_ID', array('value'=>$key));
                echo"<tb>". $value."</br>".
                    $form->textArea($phone, '['.$key.']Number', array('rows'=>1, 'cols'=>40))."</br>"."</tb>";
            } ?>
        </div>

above is the code of the form in which you need to check for empty lines or not

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