T
T
tigra2015-10-26 16:29:03
JavaScript
tigra, 2015-10-26 16:29:03

How to add data to the database using AJAX?

By means of AJAX, an array of the form comes to the action

["ооо рога и копыта", "79515556677", "[email protected]", "57650"]


I so understand at me does not transit validation. Tried like this:
$payinfo = new PaymentForm();
        //$payinfo[0] = $model->name_company;	//[0] - название компании
        //$payinfo[1] = $model->telephone;	//[1] - телефон компании
        //$payinfo[2] = $model->email;		//[2] - email компании
        //$payinfo[3] = $model->summa;		//[3] - общая сумма компании
        //$payinfo->save();

Here is the model.

public function rules()
     {
      return array(
        array('summa, telephone, email, name_company', 'required'),
        array('summa, telephone', 'numerical', 'integerOnly' => true),
        array('email, name_company', 'length', 'max' => 255),
        array('summa, telephone, email, name_company', 'filter', 'filter' => array(new CHtmlPurifier(), 'purify')),
        array('summa, telephone, email, name_company', 'filter', 'filter' => array(new StripTagsFilter(), 'clearString')),
      );
     }


How to add this array to the database?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
holfza, 2015-10-26
@tigroid3

$payinfo = new PaymentForm();
$payinfo->name_company = $array[0];
$payinfo->telephone = $array[1];
$payinfo->email= $array[2];
$payinfo->summa= $array[3];
$payinfo->save();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question