Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | List of all members
FormController Class Reference
Inheritance diagram for FormController:
Controller BaseController

Public Member Functions

 actionSubmit ()
 actionThankyou ()
 loadModel ($id)
 actions ()

Additional Inherited Members

- Public Attributes inherited from Controller
 $menu = array()
 $breadcrumbs = array()
- Protected Member Functions inherited from BaseController
 beforeAction ($action)

Detailed Description

Definition at line 3 of file FormController.php.

Member Function Documentation

FormController::actions ( )

Returns a list of external action classes.

Returns
array

Definition at line 207 of file FormController.php.

{
return array(
'captcha' => array(
'class' => 'CCaptchaAction',
'backColor' => 0xFFFFFF,
'fixedVerifyCode' => YII_DEBUG ? 'polomo' : null
),
);
}
FormController::actionSubmit ( )

process submitted fg form

Definition at line 8 of file FormController.php.

References loadModel().

{
Yii::import('fg.widgets.form.helpers.FGFormWidgetHelper');
$isAjaxRequest = Yii::app()->getRequest()->isAjaxRequest;
if($isAjaxRequest) {
$response = array(
'status'=>true
);
}
$form_id = (int)$_POST['form_id'];
$action = $_POST['submitAction'];
if(!isset($_SESSION['formdatas'])):
$_SESSION['formdatas'] = array();
endif;
if(!isset($_SESSION['formdatalists'])):
$_SESSION['formdatalists'] = array();
endif;
$model = $this->loadModel($form_id);
if($action == "prev" || ($action != "prev" && $model->validateInput()))
{
// generate formdata arrays
$formObject = $model->JSONToArray();
$formdataForJSON = array();
$formdataList = array();
if($action != "prev"):
foreach($formObject['elements'] as $element) {
if(isset($element['name'])) {
$elementObject = FGElement::getInstance($element['type']);
$val = @$_POST[$element['name']];
$val = $elementObject->serializeFormData($val, $element);
$formdataForJSON[$element['name']] = $val;
$formdataList[] = array(
'label'=>isset($element['label'])? $element['label'] : $element['name'],
'value'=>$val
);
}
}
// store current input to session
$_SESSION['formdatas'][$form_id] = $formdataForJSON;
$_SESSION['formdatalists'][$form_id] = $formdataList;
endif;
// save formdata
if($action == "submit"):
// create JSON of all previous inputs from session
$finalFormData = array();
// $finalFormdataList = array();
foreach($_SESSION['formdatas'] as $formdatas):
$keys = array_keys($formdatas);
foreach($keys as $key):
$finalFormData[$key] = $formdatas[$key];
endforeach;
endforeach;
$formdata = new FGFormdata();
$formdata->form_id = $model->id;
$formdata->referer = $_POST['referer'];
$formdata->ip = Yii::app()->request->userHostAddress;
//$formdata->json = CJSON::encode($formdataForJSON);
$formdata->user_id = Yii::app()->session->sessionID;
$formdata->json = CJSON::encode($finalFormData);
$formdata->save();
unset($_SESSION['formdatas']);
try {
// send submit to form owner
//$formObject = $model->JSONToArray();
$subject = 'Form submitted on '.Yii::app()->name;
$notification = new Notification($subject,
Yii::app()->controller->renderMail('fg.views.form.email_form',
$subject,
array(
'model' => $model,
'formdata'=>$formdata,
'formdataList'=>$_SESSION['formdatalists'])
,true));
$notification->recipients[] = new EmailRecipient($formObject['email'],Yii::app()->params['adminEmail']);
Yii::app()->notificationManager->notifyAbout($notification);
// old mail function
/*
$mailer = Yii::createComponent('fg.extensions.mailer.EMailer');
$mailer->From = Yii::app()->params['adminEmail'];
$mailer->FromName = Yii::app()->name;
$mailer->CharSet = 'utf-8';
$mailer->ContentType = 'text/html';
$mailer->AddAddress($formObject['email']);
$mailer->Subject = 'Form submitted on '.Yii::app()->name;
$mailer->Body = $this->renderPartial('email_form', array(
'model'=>$model,
'formdata'=>$formdata,
'formdataList'=>$_SESSION['formdatalists']//$formdataList
), true);
$mailer->Send();
*/
}
catch(Exception $e) {}
// clear session errors for this form
FGFormWidgetHelper::clearErrors($model->id);
$redirectUrl = $model->thankyoupage;
endif;
if($action == "next"):
$redirectUrl = $model->nextpage;
endif;
if($action == "prev"):
$redirectUrl = $model->prevpage;
endif;
//$my = Yii::app()->getModules(false);
if($isAjaxRequest)
{
$response['redirectUrl'] = $redirectUrl;
//$response['redirectUrl'] = $my['fg']['thankYouPage'];
}
else
{
// go to thank you page
$this->redirect($redirectUrl);
//$this->redirect($my['fg']['thankYouPage']);
}
}
else
{
if($isAjaxRequest)
{
$response['status'] = false;
$response['errors'] = array();
foreach($model->getErrors() as $attribute=>$errors) {
$response['errors'][$attribute]=$errors;
}
}
else
{
// set session erros for this form
FGFormWidgetHelper::setErrors($form_id, $model->getErrors());
// return to current form
$this->redirect($_POST['return_url']);
}
}
if($isAjaxRequest) {
FGHelper::sendJSON($response);
}
}
FormController::actionThankyou ( )

validate form via ajax request

Returns
JSON array of errors form thank you page

Definition at line 183 of file FormController.php.

{
$this->render('thankyou');
//$my = Yii::app()->getModules(false);
//$this->redirect($my['fg']['thankYouPage']);
}
FormController::loadModel (   $id)
Parameters
int$id
Returns
FGForms fg form model load fg form model

Definition at line 195 of file FormController.php.

References FGForms\model().

Referenced by actionSubmit().

{
$model=FGForms::model()->findByPk($id);
if($model===null)
throw new CHttpException(404, 'The requested form does not exist');
return $model;
}

The documentation for this class was generated from the following file: