/**
  * Checks a submitted form. Returns true on success, an (X)HTML error message
  * on failure.
  *
  * @return mixed
  */
 public function validate()
 {
     $o = '';
     foreach ($this->form->getFields() as $field) {
         $o .= $this->validateField(Field::make($field));
     }
     if ($this->form->hasCaptcha() && !$this->isCaptchaCorrect()) {
         $o .= '<li>' . $this->l10n['error_captcha_code'] . '</li>' . PHP_EOL;
         Controller::focusField($this->form->getName(), 'advancedform-captcha');
     }
     return $o == '' ? true : '<ul class="advfrm-error">' . PHP_EOL . $o . '</ul>' . PHP_EOL;
 }
 /**
  * Returns the mail view.
  *
  * @return string
  */
 public function render()
 {
     $o = '';
     if (!$this->showHidden) {
         $o .= strip_tags($this->l10n['message_sent_info']) . PHP_EOL . PHP_EOL;
     }
     foreach ($this->form->getFields() as $field) {
         $field = Field::make($field);
         if ($this->isFieldVisible($field)) {
             $o .= $this->renderField($field);
         }
     }
     return $o;
 }
 /**
  * Returns the mail view.
  *
  * @return string (X)HTML
  */
 public function render()
 {
     $o = '';
     $o .= '<div class="advfrm-mailform">' . PHP_EOL;
     if (!$this->showHidden) {
         $o .= '<p>' . $this->l10n['message_sent_info'] . '</p>' . PHP_EOL;
     }
     $o .= '<table>' . PHP_EOL;
     foreach ($this->form->getFields() as $field) {
         $field = Field::make($field);
         if ($this->isFieldVisible($field)) {
             $o .= $this->renderField($field);
         }
     }
     $o .= '</table>' . PHP_EOL . '</div>' . PHP_EOL;
     return $o;
 }
Example #4
0
 /**
  * Returns the view of a form by instatiating the template.
  *
  * @return string (X)HTML.
  *
  * @global string The (X)HTML fragment for insertion into the HEAD element.
  * @global array  The configuration of the plugins.
  */
 protected function renderTemplate()
 {
     global $hjs, $plugin_cf;
     $fn = Data::folder() . 'css/' . $this->form->getName() . '.css';
     if (file_exists($fn)) {
         $hjs .= tag('link rel="stylesheet" href="' . $fn . '" type="text/css"') . PHP_EOL;
     }
     $fn = Data::folder() . 'js/' . $this->form->getName() . '.js';
     if (file_exists($fn)) {
         $hjs .= '<script type="text/javascript" src="' . $fn . '"></script>' . PHP_EOL;
     }
     $fn = Data::folder() . $this->form->getName() . '.tpl' . ($plugin_cf['advancedform']['php_extension'] ? '.php' : '');
     $advfrm_script = file_get_contents($fn);
     foreach ($this->form->getFields() as $field) {
         $field = Field::make($field);
         $fieldView = new FieldView($this->form->getName(), $field);
         $advfrm_script = str_replace('<?field ' . $field->getName() . '?>', $fieldView->render(), $advfrm_script);
     }
     extract($GLOBALS);
     ob_start();
     eval('?>' . $advfrm_script);
     return ob_get_clean();
 }
    /**
     * Renders the stylesheet.
     *
     * @param Form $form A form.
     *
     * @return string
     */
    protected function renderCSS($form)
    {
        $css = <<<EOT
#advfrm-{$this->id} {}
#advfrm-{$this->id} div.break {
    clear: both;
}
#advfrm-{$this->id} div.float {
    float: left; margin-right: 1em;
}
#advfrm-{$this->id} div.label {
    /* float: left; width: 12em; margin-bottom: 0.5em; */
}
#advfrm-{$this->id} div.field {
    margin-bottom: 0.5em;
    /* float: left; */
}
/* the individual fields */

EOT;
        foreach ($form->getFields() as $field) {
            $field = Field::make($field);
            $css .= '#advfrm-' . $this->id . '-' . $field->getName() . ' {}' . PHP_EOL;
        }
        return $css;
    }
Example #6
0
 /**
  * Determines the addresses of sender and recipients, and returns whether
  * that succeeded.
  *
  * @return bool
  *
  * @global array  The localization of the plugins.
  * @global string The (X)HTML fragment with error messages.
  */
 protected function determineAddresses()
 {
     global $plugin_tx, $e;
     $from = '';
     $from_name = '';
     foreach ($this->form->getFields() as $field) {
         $field = Field::make($field);
         if ($field->getType() == 'from_name') {
             $from_name = stsl($_POST['advfrm-' . $field->getName()]);
         } elseif ($field->getType() == 'from') {
             $from = stsl($_POST['advfrm-' . $field->getName()]);
         }
     }
     if ($this->isConfirmation && empty($from)) {
         $e .= '<li>' . $plugin_tx['advancedform']['error_missing_sender'] . '</li>' . PHP_EOL;
         return false;
     }
     if ($this->isConfirmation) {
         $this->mail->set('From', $this->form->getReceiver());
         $this->mail->set('FromName', $this->form->getReceiverName());
         $this->mail->AddAddress($from, $from_name);
     } else {
         $this->mail->set('From', $from);
         $this->mail->set('FromName', $from_name);
         $this->mail->AddAddress($this->form->getReceiver(), $this->form->getReceiverName());
         foreach (explode(';', $this->form->getCC()) as $cc) {
             if (trim($cc) != '') {
                 $this->mail->AddCC($cc);
             }
         }
         foreach (explode(';', $this->form->getBCC()) as $bcc) {
             if (trim($bcc) != '') {
                 $this->mail->AddBCC($bcc);
             }
         }
     }
     return true;
 }
Example #7
0
 /**
  * Returns the form editor.
  *
  * @param string $id A form ID.
  *
  * @return string (X)HTML.
  *
  * @global array  The paths of system files and folders.
  * @global string The script name.
  * @global array  The configuration of the plugins.
  * @global array  The localization of the core.
  * @global array  The localization of the plugins.
  * @global string The (X)HTML fragment containing error messages.
  * @global object The CSRF protector.
  */
 public static function editForm($id)
 {
     global $sn, $plugin_cf, $tx, $plugin_tx, $e, $_XH_csrfProtection;
     $ptx = $plugin_tx['advancedform'];
     $form = Data::fetchForm($id);
     if (!isset($form)) {
         $e .= '<li><b>' . sprintf($plugin_tx['advancedform']['error_form_missing'], $id) . '</b></li>';
         return self::renderFormsAdministration();
     }
     /*
      * general settings
      */
     $o = '<div id="advfrm-editor">' . PHP_EOL . '<h1>' . $id . '</h1>' . PHP_EOL;
     $action = $sn . '?advancedform&amp;admin=plugin_main&amp;action=save&amp;form=' . $id;
     $o .= '<form action="' . $action . '" method="post" accept-charset="UTF-8"' . ' onsubmit="return advfrm_checkForm()">' . PHP_EOL;
     $o .= '<table id="advfrm-form">' . PHP_EOL;
     $fields = array('name', 'title', 'to_name', 'to', 'cc', 'bcc', 'captcha', 'store', 'thanks_page');
     foreach ($fields as $det) {
         $name = 'advfrm-' . $det;
         $o .= '<tr>' . '<td><label for="' . $name . '">' . $ptx['label_' . $det] . '</label></td>';
         switch ($det) {
             case 'captcha':
             case 'store':
                 $checked = $form->data[$det] ? ' checked="checked"' : '';
                 $o .= '<td>' . tag('input type="checkbox" id="' . $name . '" name="' . $name . '"' . $checked) . '</td>';
                 break;
             case 'thanks_page':
                 $o .= '<td>' . self::renderPageSelect($name, $form->data[$det]) . '</td>';
                 break;
             default:
                 $o .= '<td>' . tag('input type="text" id="' . $name . '" name="' . $name . '"' . ' value="' . XH_hsc($form->data[$det]) . '" size="40"') . '</td>';
         }
         $o .= '</tr>' . PHP_EOL;
     }
     $o .= '</table>' . PHP_EOL;
     /*
      * field settings
      */
     $o .= '<div class="toolbar">';
     foreach (array('add', 'delete', 'up', 'down') as $tool) {
         $o .= '<a onclick="advfrm_' . $tool . '(\'advfrm-fields\')">' . self::renderToolIcon($tool) . '</a>' . PHP_EOL;
     }
     $o .= '</div>' . PHP_EOL;
     $o .= '<table id="advfrm-fields">' . PHP_EOL;
     $o .= '<thead><tr>' . '<th>' . $ptx['label_field'] . '</th>' . '<th>' . $ptx['label_label'] . '</th>' . '<th colspan="3">' . $ptx['label_type'] . '</th>' . '<th>' . $ptx['label_required'] . '</th>' . '</tr></thead>' . PHP_EOL;
     foreach ($form->getFields() as $field) {
         $field = Field::make($field);
         $o .= '<tr>' . '<td>' . tag('input type="text" size="10" name="advfrm-field[]"' . ' value="' . $field->getName() . '" class="highlightable"') . '</td>' . '<td>' . tag('input type="text" size="10" name="advfrm-label[]" value="' . XH_hsc($field->getLabel()) . '" class="highlightable"') . '</td>' . '<td><select name="advfrm-type[]"' . ' onfocus="this.oldvalue = this.value"' . ' class="highlightable">';
         $types = array('text', 'from_name', 'from', 'mail', 'date', 'number', 'textarea', 'radio', 'checkbox', 'select', 'multi_select', 'password', 'file', 'hidden', 'output', 'custom');
         foreach ($types as $type) {
             $sel = $field->getType() == $type ? ' selected="selected"' : '';
             $o .= '<option value="' . $type . '"' . $sel . '>' . $ptx['field_' . $type] . '</option>';
         }
         $o .= '</select></td>' . '<td>' . tag('input type="hidden" class="hidden" name="advfrm-props[]"' . ' value="' . XH_hsc($field->getPropertyString()) . '"') . '<td><a>' . self::renderToolIcon('props') . '</a>' . PHP_EOL;
         $checked = $field->isRequired() ? ' checked="checked"' : '';
         $o .= '<td>' . tag('input type="checkbox"' . $checked . ' onchange="this.' . 'nextSibling.value = this.checked ? 1 : 0"') . tag('input type="hidden" name="advfrm-required[]" value="' . $field->isRequired() . '"') . '</td>' . '</tr>' . PHP_EOL;
     }
     $o .= '</table>' . PHP_EOL;
     $o .= tag('input type="submit" class="submit" value="' . ucfirst($tx['action']['save']) . '" style="display:none"');
     $o .= $_XH_csrfProtection->tokenInput();
     $o .= '</form>' . PHP_EOL . '</div>' . PHP_EOL;
     /*
      * property dialogs
      */
     $o .= '<div id="advfrm-text-props" style="display:none">' . PHP_EOL . '<table>' . PHP_EOL;
     $properties = array('size', 'maxlength', 'default', 'constraint', 'error_msg');
     foreach ($properties as $prop) {
         $o .= '<tr id="advfrm-text-props-' . $prop . '"><td>' . $prop . '</td>' . '<td>' . tag('input type="text" size="30"') . '</td></tr>' . PHP_EOL;
     }
     $o .= '</table>' . PHP_EOL . '</div>' . PHP_EOL;
     $o .= '<div id="advfrm-select-props" style="display:none">' . PHP_EOL;
     $o .= '<p id="advfrm-select-props-size">' . $ptx['label_size'] . ' ' . tag('input type="text"') . '</p>' . PHP_EOL;
     $o .= '<p id="advfrm-select-props-orient">' . tag('input type="radio" id="advrm-select-props-orient-horz"' . ' name="advrm-select-props-orient"') . '<label for="advrm-select-props-orient-horz">&nbsp;' . $ptx['label_horizontal'] . '</label>&nbsp;&nbsp;&nbsp;' . tag('input type="radio" id="advrm-select-props-orient-vert"' . ' name="advrm-select-props-orient"') . '<label for="advrm-select-props-orient-vert">&nbsp;' . $ptx['label_vertical'] . '</label>' . '</p>' . PHP_EOL;
     $o .= '<div class="toolbar">';
     foreach (array('add', 'delete', 'up', 'down', 'clear_defaults') as $tool) {
         $o .= '<a onclick="advfrm_' . $tool . '(\'advfrm-prop-fields\')">' . self::renderToolIcon($tool) . '</a>' . PHP_EOL;
     }
     $o .= '</div>' . PHP_EOL;
     $o .= '<table id="advfrm-prop-fields">' . PHP_EOL . '<tr>' . '<td>' . tag('input type="radio" name="advfrm-select-props-default"') . '</td>' . '<td>' . tag('input type="text" name="advfrm-select-props-opt" size="25"' . ' class="highlightable"') . '</td>' . '</tr>' . PHP_EOL . '</table>' . PHP_EOL . '</div>' . PHP_EOL;
     return $o;
 }