How can I do to enter several values in the same input? For example, if I want to send an email notification to several recipients, using PHP, Javascript, etc., in the Yii framework?
In the one form (not HTML) I have the following:
public function createAlert(){
$id = $_POST['idAlert'];
$alertModel = Model_Email::model()->findByPk($id);
if($alertModel != NULL){
$alertModel->email = $this->email;
$alertModel->id_search = $this->id_search;
$alertModel->time_of_recurrence_unit = $this->time_of_recurrence_unit;
$alertModel->date_start = $this->date_start;
$alertModel->id_preference = $this->id_preference;
$alertModel->status = 'ENABLED';
$alertModel->save();
}
else{
$emailModel = new Model_Email();
$emailModel->email = $this->email;
$emailModel->id_search = $this->id_search;
$emailModel->time_of_recurrence_unit = $this->time_of_recurrence_unit;
$emailModel->date_start = $this->date_start;
$emailModel->id_preference = $this->id_preference;
$emailModel->status = 'ENABLED';
if($emailModel->validate() && $emailModel->save()){
return true;
}
else{
return false;
}
}
}
What creates a notification that will be sent to the user and in case there is already such notification will modify it.
Meanwhile, in the Controller I have the following:
public function actionSave(){
if(!Yii::app()->user->isGuest){
$emailModel = new Form_search_email_notification();
if(isset($_POST['ajax']) && $_POST['ajax'] === 'email-form'){
echo CActiveRecord::validate($emailModel);
Yii::app()->end;
}
if(isset($_POST['Form_search_email_notification'])){
$emailModel->email = $_POST['Form_search_email_notification']['email'];
$emailModel->id_search = $_POST['Form_search_email_notification']['id_search_combo'];
$emailModel->id_preference = $_POST['Form_search_email_notification']['id_preference'];
$emailModel->time_of_recurrence_unit = $_POST['Form_search_email_notification']['time_of_recurrence_unit'];
if($emailModel->validate() && $emailModel->createAlert()){
Yii::app()->user->setFlash('success', 'Notificación creada');
$this->redirect('/alert/list');
}
}
$this->redirect(array('alert/list'));
}
}
I appreciate beforehand if someone can help me, that the code I put it just to show what I do, what I want to know is how to apply it for several values at the same time, that is, several recipients in this case.
Oh, by the way, the idea would be to enter a recipient, press enter and enter another, and so on, something like when they put tags in some places.