本文整理汇总了PHP中kartik\widgets\ActiveForm::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveForm::validate方法的具体用法?PHP ActiveForm::validate怎么用?PHP ActiveForm::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kartik\widgets\ActiveForm
的用法示例。
在下文中一共展示了ActiveForm::validate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionUpdate
/**
* Updates an existing Questionnaire model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if (\Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
\Yii::$app->response->format = 'json';
return \kartik\widgets\ActiveForm::validate($model);
}
$persondetails = \app\models\Participant::findOne(['pk_person' => $model->fk_person]);
if ($model->load(Yii::$app->request->post())) {
$model->creation_name = Yii::$app->user->identity->username;
$model->altered = 1;
$persondetails->filtered = $persondetails->filtered + 1;
$model->hbp_med_list = $_POST['Questionnaire']['enalapril'] . "," . $_POST['Questionnaire']['atenolol'] . ", " . $_POST['Questionnaire']['propranolol'] . "," . $_POST['Questionnaire']['hydrochlorthiazide'] . "," . $_POST['Questionnaire']['frusemide'] . "," . $_POST['Questionnaire']['aldactone'] . "," . $_POST['Questionnaire']['methyldopa'] . "," . $_POST['Questionnaire']['nifedipine'] . "," . $_POST['Questionnaire']['hydralazine'];
if ($_POST['Questionnaire']['own_none'] == 1) {
$model->household_own = "0,0,0,0,0,0,1";
} else {
$model->household_own = $_POST['Questionnaire']['car'] . "," . $_POST['Questionnaire']['refridgerator'] . ", " . $_POST['Questionnaire']['bicycle'] . "," . $_POST['Questionnaire']['radio'] . "," . $_POST['Questionnaire']['television'] . "," . $_POST['Questionnaire']['own_none'];
}
$persondetails->filtered = 1;
if ($model->save(FALSE) && $persondetails->save(FALSE)) {
Yii::$app->session->setFlash('success', 'The questionnaire saved successfully');
return $this->redirect(['participant/apptmnts']);
}
} else {
return $this->render('update', ['model' => $model, 'persondetails' => $persondetails]);
}
}
示例2: run
/**
* @inheritdoc
* @param int $id
* @return int|mixed
* @throws NotFoundHttpException
*/
public function run($id)
{
/** @var Form|HasProperties $form */
if (null === ($form = Form::findById($id))) {
throw new NotFoundHttpException();
}
$post = Yii::$app->request->post();
$form->abstractModel->setAttrubutesValues($post);
/** @var AbstractModel|SpamCheckerBehavior $model */
$model = $form->getAbstractModel();
if (Yii::$app->request->isAjax && isset($post['ajax'])) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
/** @var \app\models\Object $object */
$object = Object::getForClass(Form::className());
$propGroups = ObjectPropertyGroup::find()->where(['and', 'object_id = :object', 'object_model_id = :id'], [':object' => $object->id, ':id' => $id])->asArray()->all();
$propIds = ArrayHelper::getColumn($propGroups, 'property_group_id');
// Spam checking
$activeSpamChecker = SpamChecker::getActive();
$data = [];
$haveSpam = false;
if ($activeSpamChecker !== null && !empty($activeSpamChecker->api_key)) {
$data[$activeSpamChecker->name]['class'] = $activeSpamChecker->behavior;
$data[$activeSpamChecker->name]['value']['key'] = $activeSpamChecker->api_key;
$properties = Property::getForGroupId($propIds[0]);
foreach ($properties as $prop) {
if (!isset($activeSpamChecker->{$prop->interpret_as}) || empty($activeSpamChecker->{$prop->interpret_as})) {
continue;
}
$data[$activeSpamChecker->name]['value'][$activeSpamChecker->{$prop->interpret_as}] = is_array($post[$form->abstractModel->formName()][$prop->key]) ? implode(' ', $post[$form->abstractModel->formName()][$prop->key]) : $post[$form->abstractModel->formName()][$prop->key];
}
$model->attachBehavior('spamChecker', ['class' => SpamCheckerBehavior::className(), 'data' => $data]);
$haveSpam = $model->isSpam();
}
$date = new \DateTime();
/** @var Submission|HasProperties $submission */
$submission = new Submission(['form_id' => $form->id, 'date_received' => $date->format('Y-m-d H:i:s'), 'ip' => Yii::$app->request->userIP, 'user_agent' => Yii::$app->request->userAgent, 'spam' => (int) $haveSpam]);
if (false === Yii::$app->user->isGuest) {
$submission->processed_by_user_id = Yii::$app->user->identity->getId();
}
if (!($form->abstractModel->validate() && $submission->save())) {
return "0";
}
if (isset($post[$form->abstractModel->formName()])) {
$data = ['AddPropetryGroup' => [$submission->formName() => array_keys($form->getPropertyGroups())], $submission->abstractModel->formName() => $post[$form->abstractModel->formName()]];
if (isset($_FILES[$form->abstractModel->formName()])) {
$_FILES[$submission->abstractModel->formName()] = $_FILES[$form->abstractModel->formName()];
}
$submission->saveProperties($data);
}
return $submission->id;
}
示例3: actionCheckcustomeruniquecode
/**
*Check customer code is unique // use with Active form and field ajax validation
*/
public function actionCheckcustomeruniquecode()
{
if (Yii::$app->request->isAjax) {
$model = new Customer();
if ($model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
} else {
throw new NotFoundHttpException();
}
}
示例4: actionCreateAjax
public function actionCreateAjax($selector = 'selectorPersonas')
{
// si no se especifica el parametro $selector se toma 'selectorPersonas' por defecto, esto comportamiento contempla
// el caso de que en el mismo form se use mas de un select2 para buscar personas (por ejemplo personas/change)
$model = new Personas();
$model->id_tipo_doc = 96;
// DNI por defecto
$model->estado = Personas::ESTADO_ACTIVO;
// Al estar habilitado la validation ajax, $_POST['ajax'] viene seteado, si vino por el submit, esta variable no existe
// Siempre se devuelve el validate
if (isset($_POST['ajax'])) {
Yii::$app->response->format = 'json';
$model->load(Yii::$app->request->post());
return ActiveForm::validate($model);
}
// si no viene seteado $_POST['ajax'] se asume que se entro por el submit
if ($model->load(Yii::$app->request->post())) {
if ($model->save()) {
Yii::$app->response->format = 'json';
return ['modelP' => $model];
} else {
Yii::$app->response->format = 'json';
return ActiveForm::validate($model);
}
}
return $this->renderAjax('createajax', ['model' => $model, 'selector' => $selector]);
}
示例5: run
/**
* @param int $id
* @return int|mixed
* @throws NotFoundHttpException
*/
public function run($id)
{
/** @var Form|HasProperties $form */
if (null === ($form = Form::findById($id))) {
throw new NotFoundHttpException();
}
$post = \Yii::$app->request->post();
$form->abstractModel->setAttrubutesValues($post);
/** @var AbstractModel|SpamCheckerBehavior $model */
$model = $form->getAbstractModel();
if (\Yii::$app->request->isAjax && isset($post['ajax'])) {
\Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
/** @var \app\models\Object $object */
$object = Object::getForClass(Form::className());
$propGroups = ObjectPropertyGroup::find()->where(['and', 'object_id = :object', 'object_model_id = :id'], [':object' => $object->id, ':id' => $id])->asArray()->all();
$propIds = ArrayHelper::getColumn($propGroups, 'property_group_id');
// Spam checking
$activeSpamChecker = SpamChecker::getActive();
$data = [];
$spamResult = [];
if ($activeSpamChecker !== null && !empty($activeSpamChecker->api_key)) {
$data[$activeSpamChecker->name]['class'] = $activeSpamChecker->behavior;
$data[$activeSpamChecker->name]['value']['key'] = $activeSpamChecker->api_key;
$properties = Property::getForGroupId($propIds[0]);
foreach ($properties as $prop) {
if (!isset($activeSpamChecker->{$prop->interpret_as}) || empty($activeSpamChecker->{$prop->interpret_as})) {
continue;
}
$data[$activeSpamChecker->name]['value'][$activeSpamChecker->{$prop->interpret_as}] = is_array($post[$form->abstractModel->formName()][$prop->key]) ? implode(' ', $post[$form->abstractModel->formName()][$prop->key]) : $post[$form->abstractModel->formName()][$prop->key];
}
$model->attachBehavior('spamChecker', ['class' => SpamCheckerBehavior::className(), 'data' => $data]);
$spamResult = $model->check();
}
$haveSpam = false;
if (is_array($spamResult) === true) {
foreach ($spamResult as $result) {
if (ArrayHelper::getValue($result, 'ok', false) === true) {
$haveSpam = $haveSpam || ArrayHelper::getValue($result, 'is_spam', false);
}
}
}
$date = new \DateTime();
/** @var Submission|HasProperties $submission */
$submission = new Submission(['form_id' => $form->id, 'date_received' => $date->format('Y-m-d H:i:s'), 'ip' => Yii::$app->request->userIP, 'user_agent' => Yii::$app->request->userAgent, 'spam' => (int) $haveSpam]);
if (false === Yii::$app->user->isGuest) {
$submission->processed_by_user_id = Yii::$app->user->identity->getId();
}
if (!($form->abstractModel->validate() && $submission->save())) {
return "0";
}
if (isset($post[$form->abstractModel->formName()])) {
$data = ['AddPropetryGroup' => [$submission->formName() => array_keys($form->getPropertyGroups())], $submission->abstractModel->formName() => $post[$form->abstractModel->formName()]];
if (isset($_FILES[$form->abstractModel->formName()])) {
$_FILES[$submission->abstractModel->formName()] = $_FILES[$form->abstractModel->formName()];
}
$submission->saveProperties($data);
}
if ($haveSpam === false) {
if (!empty($form->email_notification_addresses)) {
try {
$emailView = !empty($form->email_notification_view) ? $form->email_notification_view : '@app/widgets/form/views/email-template.php';
Yii::$app->mail->compose($emailView, ['form' => $form, 'submission' => $submission])->setTo(explode(',', $form->email_notification_addresses))->setFrom(Yii::$app->mail->getMailFrom())->setSubject($form->name . ' #' . $submission->id)->send();
} catch (\Exception $e) {
// do nothing
}
}
}
return $submission->id;
}
示例6: actionVisit
public function actionVisit($id, $visit)
{
$model = $this->findModel($id);
if (\Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
\Yii::$app->response->format = 'json';
return \kartik\widgets\ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post())) {
$model->appoint_date = date("Y-m-d", strtotime($model->appoint_date));
$model->updated_name = Yii::$app->user->identity->username;
$model->updated_time = date("Y-m-d H:i:s");
$model->altered = 1;
$model->save(FALSE);
Yii::$app->session->setFlash('success', 'The record has been updated successfully');
return $this->redirect(['participant/listpart']);
} else {
return $this->render('updatevisit', ['model' => $model]);
}
}
示例7: actionAjaxvalidate
/**
* Ajax 验证菜单名称
* @return array
*/
public function actionAjaxvalidate()
{
if ($id = Yii::$app->request->post('id')) {
$model = TMenu::findOne($id);
} else {
$model = new TMenu();
}
if (Yii::$app->request->isAjax) {
$model->load(Yii::$app->request->post());
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model, 'menuname');
}
}
示例8: actionUpdatebp
public function actionUpdatebp($id)
{
$model = $this->findModel($id);
if (\Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
\Yii::$app->response->format = 'json';
return \kartik\widgets\ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$model->updated_date = new \yii\db\Expression('NOW()');
$model->update_name = \Yii::$app->user->identity->username;
if ($model->save()) {
Yii::$app->session->setFlash('success', 'The record has been updated successfully');
return $this->redirect(['participant/index']);
}
} else {
$fkperson = \app\models\Participant::findOne(['pk_person' => $model->fk_person]);
return $this->render('updatebp', ['model' => $model, 'persondetails' => $fkperson]);
}
}
示例9: actionCreateAjax
public function actionCreateAjax()
{
$model = new Vehiculos();
$model->estado = Vehiculos::ESTADO_ACTIVO;
// Al estar habilitado la validation ajax, $_POST['ajax'] viene seteado, si vino por el submit, esta variable no existe
// Siempre se devuelve el validate
if (isset($_POST['ajax'])) {
Yii::$app->response->format = 'json';
$model->load(Yii::$app->request->post());
return ActiveForm::validate($model);
}
// si no viene seteado $_POST['ajax'] se asume que se entro por el submit
if ($model->load(Yii::$app->request->post())) {
if ($model->save()) {
Yii::$app->response->format = 'json';
return ['modelP' => $model];
} else {
Yii::$app->response->format = 'json';
return ActiveForm::validate($model);
}
}
return $this->renderAjax('createajax', ['model' => $model]);
}