Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
FGFormWidget.php
1 <?php
2 class FGFormWidget extends CWidget
3 {
4  public $id;
5  public $showErrors;
6  public $notPublish;
7  protected $model;
8  public $formdata;
9 
10  public function init()
11  {
12 
13  $this->model = FGForms::model()->findByPk($this->id);
14  Yii::import('fg.widgets.form.helpers.FGFormWidgetHelper');
15  $this->processFormHTML();
16  $this->showErrors = true;
17  if(isset($this->notPublish)):$this->showErrors=false;endif;
18  $this->formdata = array();
19  if(isset($_SESSION['formdatas']) && isset($_SESSION['formdatas'][$this->id])):
20  $this->formdata = $_SESSION['formdatas'][$this->id];
21  endif;
22  }
23 
24  public function run()
25  {
26  $errors = FGFormWidgetHelper::getErrors($this->model->id);
27  if($this->showErrors):
28  $this->render('fg.widgets.form.views.form', array(
29  'errors'=>$errors,
30  'formdata' => $this->formdata
31  ));
32  else:
33  $this->render('fg.widgets.form.views.form',array('formdata' => $this->formdata));
34  endif;
35  }
36 
37  protected function processFormHTML()
38  {
39  $attrs = 'action="'.Yii::app()->createUrl('/fg/form/submit').'"';
40  $this->model->html = str_replace('<form', '<form '.$attrs, $this->model->html);
41 
42  // Anpassungen für AK
43  $this->model->html = str_replace('class="ui-droppable ui-sortable','class="anfrage', $this->model->html);
44 
45 
46 
47  // fix proxy-problem in frontend
48  $this->model->html = str_replace('"/proxy', '"', $this->model->html);
49  // end
50 
51  $hiddenFields = array(
52  'form_id' => $this->model->id,
53  'return_url' => Yii::app()->request->requestUri,
54  'referer' => Yii::app()->request->urlReferrer,
55  'submitAction' => "submit"
56  );
57  $fields = '';
58  foreach($hiddenFields as $k => $v) {
59  $fields .= CHtml::hiddenField($k, $v);
60  }
61  $this->model->html = str_replace('</form>', $fields.'</form>', $this->model->html);
62  }
63 }