function bum_show_custom_fields_admin()
{
    //get extra fields
    $profileuser = bum_get_user_to_edit($_GET['user_id']);
    if (!$profileuser->data->ID) {
        exit;
    }
    $fields = get_term_by('slug', $profileuser->roles[0], BUM_HIDDEN_FIELDS);
    $form = new ValidForm('your-profile', '', get_permalink() . '?user_id=' . $_GET['user_id']);
    /*
     * This handles extra fields ( basically reading the field info and putting it into ValidForm )
     * Currently handles `radio`, `checkbox`, `select`, `input_text` ( text field ), and `textarea`
     */
    if ($fields->description) {
        echo '<h3>Custom fields</h3>';
        $fields = json_decode($fields->description);
        foreach ($fields as $field) {
            //get info
            $info = bum_get_field_info($field);
            $fid = 'bum_' . sanitize_title($info['title']);
            //this is handling `radio`, `checkbox`, `select`
            if (in_array($info['cssClass'], array('radio', 'checkbox', 'select'))) {
                if ($info['cssClass'] == 'radio') {
                    $type = VFORM_RADIO_LIST;
                } elseif ($info['cssClass'] == 'checkbox') {
                    $type = VFORM_CHECK_LIST;
                } else {
                    $type = VFORM_SELECT_LIST;
                }
                //Multiple values are seperated by | ( pipe )
                if (strpos($info['meta_value'], '|') !== false) {
                    $info['meta_value'] = explode('|', $info['meta_value']);
                }
                $box = $form->addField('bum_' . $info['id'], $info['title'], $type, array('required' => $info['required'] == 'false' ? false : true), array('required' => 'The following field is required: ' . $info['title']), $info['tip'] ? array('tip' => $info['tip'], 'default' => $info['meta_value']) : array('default' => $info['meta_value']));
                foreach ($info['values'] as $checkbox) {
                    $box->addField($checkbox->value, htmlentities($checkbox->value));
                }
            }
            //this is handling `input_text`, `textarea`
            if (in_array($info['cssClass'], array('input_text', 'textarea'))) {
                if ($info['cssClass'] == 'input_text') {
                    $type = VFORM_STRING;
                } else {
                    $type = VFORM_TEXT;
                }
                $form->addField('bum_' . $info['id'], $info['values'], $type, array('required' => $info['required'] == 'false' ? false : true), array('required' => 'The following field is required: ' . $info['values']), $info['tip'] ? array('tip' => $info['tip'], 'default' => $info['meta_value']) : array('default' => $info['meta_value']));
            }
        }
    }
    echo $form->toWpHtml();
}
 public static function validate($checkType, $value)
 {
     $blnReturn = FALSE;
     if (array_key_exists($checkType, self::$checks)) {
         if (empty(self::$checks[$checkType])) {
             $blnReturn = TRUE;
         } else {
             switch ($checkType) {
                 case VFORM_CAPTCHA:
                     $blnReturn = PhpCaptcha::Validate(ValidForm::get($value));
                     break;
                 default:
                     $blnReturn = preg_match(self::$checks[$checkType], $value);
             }
         }
     } else {
         $blnReturn = preg_match($checkType, $value);
     }
     return $blnReturn;
 }
Exemple #3
0
 /**
  * If this is an active area, this will return the value of the checkbox.
  * @internal
  * @param string $intCount Dynamic counter, defaults to null
  * @return boolean
  */
 public function getValue($intCount = null)
 {
     $strName = $intCount > 0 ? $this->__name . "_" . $intCount : $this->__name;
     $value = ValidForm::get($strName);
     return $this->__active && !empty($value) || !$this->__active ? true : false;
 }
 /**
  * Get the value to validate from either the global request variable or the cached __validvalues array.
  *
  * @internal
  * @param integer $intDynamicPosition Using the intDynamicPosition parameter, you can get the specific value
  * of a dynamic field.
  * @return string|array|null Returns the submitted field value. If no sumitted value is set,
  * return value is the cached valid value. If no cached value is set, return value is the default value. If no
  * default value is set, return value is null. When field type is `ValidForm::VFORM_FILE` and a file is submitted,
  * the return value is the `$_FILES[fieldname]` array.
  */
 public function getValue($intDynamicPosition = 0)
 {
     $varReturn = null;
     if (isset($this->__overrideerrors[$intDynamicPosition]) && empty($this->__overrideerrors[$intDynamicPosition])) {
         $varReturn = null;
     } else {
         $strFieldName = $intDynamicPosition > 0 ? $this->__fieldname . "_" . $intDynamicPosition : $this->__fieldname;
         //if ($this->__type !== ValidForm::VFORM_FILE) {
         // Default value
         $varValidValue = $this->__field->getDefault();
         // Get cached value if set
         if (isset($this->__validvalues[$intDynamicPosition])) {
             $varValidValue = $this->__validvalues[$intDynamicPosition];
         }
         // Overwrite cached value with value from REQUEST array if available
         if (ValidForm::getIsSet($strFieldName)) {
             $varValue = ValidForm::get($strFieldName);
             if (is_array($varValue)) {
                 $varReturn = [];
                 foreach ($varValue as $key => $value) {
                     $varReturn[$key] = $value;
                     // NEVER return unsanitized output
                 }
             } else {
                 $varReturn = $varValue;
                 // NEVER return unsanitized output
             }
         } else {
             $varReturn = $varValidValue;
         }
         //}
         // *** Not ready for implementation yet.
         // else {
         // if (isset($_FILES[$strFieldName]) && isset($_FILES[$strFieldName])) {
         // $varReturn = $_FILES[$strFieldName];
         // }
         // }
     }
     return $varReturn;
 }
 /**
  * Add a field to the MultiField collection.
  *
  * Same as {@link \ValidFormBuilder\ValidForm::addField()} with the only difference that the `MultiField::addField()`
  * does not take a field label since that's already set when initialising the `MultiField`.
  *
  * @param string $name Field name
  * @param integer $type Field type
  * @param array $validationRules Validation rules array
  * @param array $errorHandlers Error handling array
  * @param array $meta The meta array
  * @return \ValidFormBuilder\Element
  */
 public function addField($name, $type, $validationRules = array(), $errorHandlers = array(), $meta = array())
 {
     // Creating dynamic fields inside a multifield is not supported.
     if (array_key_exists("dynamic", $meta)) {
         unset($meta["dynamic"]);
     }
     if (array_key_exists("dynamicLabel", $meta)) {
         unset($meta["dynamicLabel"]);
     }
     // Render the field and add it to the multifield field collection.
     $objField = ValidForm::renderField($name, "", $type, $validationRules, $errorHandlers, $meta);
     // *** Set the parent for the new field.
     $objField->setMeta("parent", $this, true);
     $this->__fields->addObject($objField);
     if ($this->__dynamic) {
         // *** The dynamic count can be influenced by a meta value.
         $intDynamicCount = isset($meta["dynamicCount"]) ? $meta["dynamicCount"] : 0;
         $objHiddenField = new Hidden($objField->getId() . "_dynamic", ValidForm::VFORM_INTEGER, array("default" => $intDynamicCount, "dynamicCounter" => true));
         $this->__fields->addObject($objHiddenField);
         $objField->setDynamicCounter($objHiddenField);
     }
     return $objField;
 }
?>

<?php 
if (isset($errors) && is_wp_error($errors)) {
    ?>
<div class="error"><p><?php 
    echo implode("</p>\n<p>", $errors->get_error_messages());
    ?>
</p></div>
<?php 
}
?>

<div class="registration-wrapper" id="page-profile">
	<?php 
$form = new ValidForm('your-profile', '', bum_get_permalink_profile());
$form->addField('email', 'Email', VFORM_EMAIL, array('required' => true), array('required' => 'You need an email.', 'type' => 'Email not valid.'), array('default' => esc_attr($profileuser->user_email)));
if ($wp_http_referer) {
    $form->addField('wp_http_referer', '', VFORM_HIDDEN, array(), array(), array('default' => esc_url($wp_http_referer)));
}
$form->addField('from', '', VFORM_HIDDEN, array(), array(), array('default' => 'profile'));
$form->addField('action', '', VFORM_HIDDEN, array(), array(), array('default' => 'update'));
$form->addField('user_id', '', VFORM_HIDDEN, array(), array(), array('default' => $user->ID));
$form->addField('checkuser_id', '', VFORM_HIDDEN, array(), array(), array('default' => $user->ID));
/*
 * This handles extra fields ( basically reading the field info and putting it into ValidForm )
 * Currently handles `radio`, `checkbox`, `select`, `input_text` ( text field ), and `textarea`
 */
if ($fields->description) {
    $fields = json_decode($fields->description);
    foreach ($fields as $field) {
 /**
  * See {@link \ValidFormBuilder\ValidForm::isValid()}
  * @see \ValidFormBuilder\ValidForm::isValid()
  */
 public function isValid($strPageId = null)
 {
     if (!is_null($strPageId)) {
         return $this->isValidUntil($strPageId);
     } else {
         return parent::isValid();
     }
 }
 /**
  * Check if the form is submitted by validating the value of the hidden
  * vf__dispatch field.
  *
  * @param boolean $blnForce
  *            Fake isSubmitted to true to force field values.
  * @return boolean [description]
  */
 public function isSubmitted($blnForce = false)
 {
     if (ValidForm::get("vf__dispatch") == $this->__name || $blnForce) {
         return true;
     } else {
         return false;
     }
 }
Exemple #9
0
 public function isSubmitted()
 {
     if (ValidForm::get("vf__dispatch") == $this->__name) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
 public function getForm()
 {
     $strMaxLength = "Your input is too long. Maximum length is %s";
     $strMinLength = "Your input is too short. Minimum length is %s";
     $strRequired = "This field is required.";
     $objForm = new ValidForm("installForm");
     $objForm->setMainAlert("One or more errors occured. Check the marked fields and try again.");
     $objForm->addFieldset("CMS type", NULL, "PunchCMS can be installed for a single website or multiple websites at once.");
     $objForm->addField("single_instance", "Single website", VFORM_BOOLEAN);
     $objForm->addFieldset("Administrator settings", NULL, "This is the account for the admin area. Later you can create an admin per website.");
     $objForm->addField("username", "Username", VFORM_STRING, array("maxLength" => 255, "required" => true), array("maxLength" => $strMaxLength, "required" => $strRequired, "type" => "Enter only letters and spaces."));
     $objForm->addField("passwd", "Password", VFORM_PASSWORD, array("maxLength" => 255, "required" => true), array("maxLength" => $strMaxLength, "required" => $strRequired, "type" => "Enter only letters and numbers."));
     $objForm->addField("email", "Email address", VFORM_EMAIL, array("maxLength" => 32, "required" => true), array("maxLength" => $strMaxLength, "required" => $strRequired, "type" => "Use the format name@domain.extension."), array("tip" => "This address will be used as the sender address for password reminders."));
     $objForm->addFieldset("MySQL settings", NULL, "The database and user must already exist, otherwise the installation will fail.");
     $objForm->addField("db_server", "Server address", VFORM_STRING, array("maxLength" => 255, "required" => true), array("maxLength" => $strMaxLength, "required" => $strRequired, "type" => "Enter the address of the MySQL server."), array("default" => "localhost"));
     $objForm->addField("db_name", "Database name", VFORM_STRING, array("maxLength" => 255, "required" => true), array("maxLength" => $strMaxLength, "required" => $strRequired, "type" => "Enter the name of the designated database."), array("default" => "punchcms"));
     $objForm->addField("db_username", "Username", VFORM_STRING, array("maxLength" => 255, "required" => true), array("maxLength" => $strMaxLength, "required" => $strRequired, "type" => "Enter the username for the database."));
     $objForm->addField("db_passwd", "Password", VFORM_PASSWORD, array("maxLength" => 32, "required" => false), array("maxLength" => $strMaxLength, "type" => "Enter the password for the database."));
     $objForm->setSubmitLabel("Submit");
     return $objForm;
 }
            echo bum_get_permalink_login('action=register');
            ?>
"><?php 
            _e('Register');
            ?>
</a>
	<?php 
        }
        ?>
	</p>
	
	<?php 
        break;
    case 'login':
    default:
        $form = new ValidForm('loginform', '', bum_get_permalink_login());
        $form->addField('log', 'Username', VFORM_STRING, array('required' => true), array('required' => 'You need a username.'), array('tip' => 'Usernames cannot be changed.'));
        $form->addField('pwd', 'Password', VFORM_PASSWORD, array('required' => true), array('required' => 'Enter your password.'));
        $remember = $form->addField('rememberme', '', VFORM_CHECK_LIST);
        $remember->addField('Remember Me', 'forever');
        $form->setSubmitLabel("Login");
        do_action('login_form');
        if ($bum_interim_login) {
            $form->addField('interim-login', '', VFORM_HIDDEN, array(), array(), array('default' => '1'));
        } else {
            $form->addField('redirect_to', '', VFORM_HIDDEN, array(), array(), array('default' => esc_attr($bum_redirect_to)));
        }
        $form->addField('testcookie', '', VFORM_HIDDEN, array(), array(), array('default' => '1'));
        echo $form->toHtml();
        if (!$bum_interim_login) {
            ?>
Exemple #12
0
 /**
  * Generate unique name based on class name
  * @internal
  * @return string
  */
 protected function __generateName()
 {
     return strtolower(ValidForm::getStrippedClassName(get_class($this))) . "_" . mt_rand();
 }
Exemple #13
0
 private function __validate()
 {
     $value = ValidForm::get($this->__name);
     $blnReturn = TRUE;
     if ($this->__active && empty($value)) {
         //*** Not active;
     } else {
         foreach ($this->fields as $field) {
             if (!$field->isValid()) {
                 $blnReturn = FALSE;
                 break;
             }
         }
     }
     return $blnReturn;
 }
<H2 class="registration-title"><?php 
echo ucwords($type);
?>
</H2>
<?php 
$form = new ValidForm('registerform', '', bum_get_permalink_registration());
$form->addField('user_login', 'Username', VFORM_STRING, array('required' => true), array('required' => 'You need a username.'), array('tip' => 'Usernames cannot be changed.'));
$form->addField('user_email', 'Email', VFORM_EMAIL, array('required' => true), array('required' => 'You need an email.', 'type' => 'Email not valid.'));
$form->addField('user_email1', 'Confirm Email', VFORM_EMAIL, array('required' => true), array('required' => 'You need an email.', 'type' => 'Email not valid.'));
$form->addField('user_type', '', VFORM_HIDDEN, array(), array(), array('default' => $type));
/*
 * This handles extra fields ( basically reading the field info and putting it into ValidForm )
 * Currently handles `radio`, `checkbox`, `select`, `input_text` ( text field ), and `textarea`
 */
if ($fields->description) {
    $fields = json_decode($fields->description);
    foreach ($fields as $field) {
        //get info
        $info = bum_get_field_info($field);
        $fid = 'bum_' . sanitize_title($info['title']);
        //this is handling `radio`, `checkbox`, `select`
        if (in_array($info['cssClass'], array('radio', 'checkbox', 'select'))) {
            if ($info['cssClass'] == 'radio') {
                $type = VFORM_RADIO_LIST;
            } elseif ($info['cssClass'] == 'checkbox') {
                $type = VFORM_CHECK_LIST;
            } else {
                $type = VFORM_SELECT_LIST;
            }
            //Multiple values are seperated by | ( pipe )
            if (strpos($info['meta_value'], '|') !== false) {
 public function buildForm($blnSend = true, $blnClientSide = true)
 {
     $objCms = PCMS_Client::getInstance();
     $strReturn = "";
     $this->__maxLengthAlert = $this->__formElement->getField("AlertMaxLength")->getHtmlValue();
     $this->__minLengthAlert = $this->__formElement->getField("AlertMinLength")->getHtmlValue();
     $this->__requiredAlert = $this->__formElement->getField("AlertRequired")->getHtmlValue();
     $this->__validForm->setRequiredStyle($this->__formElement->getField("RequiredIndicator")->getHtmlValue());
     $this->__validForm->setMainAlert($this->__formElement->getField("AlertMain")->getHtmlValue());
     //*** Form starts here.
     $objFieldsets = $this->__formElement->getElementsByTemplate(array("Fieldset", "Paragraph"));
     foreach ($objFieldsets as $objFieldset) {
         switch ($objFieldset->getTemplateName()) {
             case "Paragraph":
                 $this->renderParagraph($this->__validForm, $objFieldset);
                 break;
             case "Fieldset":
                 $this->renderFieldset($this->__validForm, $objFieldset);
                 $objFields = $objFieldset->getElementsByTemplate(array("Field", "Area", "ListField", "MultiField"));
                 foreach ($objFields as $objField) {
                     switch ($objField->getTemplateName()) {
                         case "Field":
                             $this->renderField($this->__validForm, $objField);
                             break;
                         case "ListField":
                             $this->renderListField($this->__validForm, $objField);
                             break;
                         case "Area":
                             $this->renderArea($this->__validForm, $objField);
                             break;
                         case "MultiField":
                             $this->renderMultiField($this->__validForm, $objField);
                             break;
                     }
                 }
         }
     }
     //*** Add conditions
     foreach ($objFieldsets as $objFieldset) {
         $this->addConditions($objFieldset);
         $objFields = $objFieldset->getElementsByTemplate(array("Field", "Area", "ListField", "MultiField"));
         foreach ($objFields as $objField) {
             $this->addConditions($objField);
         }
     }
     $this->__validForm->setSubmitLabel($this->__formElement->getField("SendLabel")->getHtmlValue());
     if ($this->__validForm->isSubmitted() && $this->__validForm->isValid()) {
         if ($blnSend) {
             $objRecipientEmails = $this->__formElement->getElementsByTemplate("RecipientEmail");
             foreach ($objRecipientEmails as $objRecipientEmail) {
                 $strHtmlBody = "<html><head><title></title></head><body>";
                 $strHtmlBody .= sprintf($objRecipientEmail->getField("Body")->getHtmlValue(), $this->__validForm->valuesAsHtml(true));
                 $strHtmlBody .= "</body></html>";
                 $varEmailId = $objRecipientEmail->getField("SenderEmail")->getValue();
                 $objEmailElement = $objCms->getElementById($varEmailId);
                 $strFrom = "webserver";
                 if (is_object($objEmailElement)) {
                     $varEmailId = $objEmailElement->getElement()->getApiName();
                     if (empty($varEmailId)) {
                         $varEmailId = $objEmailElement->getId();
                     }
                     $strFrom = $this->__validForm->getValidField("formfield_" . strtolower($varEmailId))->getValue();
                 }
                 $strErrors = $this->sendMail($objRecipientEmail->getField("Subject")->getHtmlValue(), $strHtmlBody, $strFrom, explode(",", $objRecipientEmail->getField("RecipientEmail")->getHtmlValue()));
                 if (!empty($strErrors)) {
                     throw new Exception($strErrors, E_ERROR);
                 }
             }
             $objSenderEmails = $this->__formElement->getElementsByTemplate("SenderEmail");
             foreach ($objSenderEmails as $objSenderEmail) {
                 $strHtmlBody = "<html><head><title></title></head><body>";
                 $strHtmlBody .= sprintf($objSenderEmail->getField("Body")->getHtmlValue(), $this->__validForm->valuesAsHtml(true));
                 $strHtmlBody .= "</body></html>";
                 $varEmailId = $objSenderEmail->getField("RecipientEmail")->getValue();
                 $objEmailElement = $objCms->getElementById($varEmailId);
                 if (is_object($objEmailElement)) {
                     $varEmailId = $objEmailElement->getElement()->getApiName();
                     if (empty($varEmailId)) {
                         $varEmailId = $objEmailElement->getId();
                     }
                 }
                 $strErrors = $this->sendMail($objSenderEmail->getField("Subject")->getHtmlValue(), $strHtmlBody, $objSenderEmail->getField("SenderEmail")->getHtmlValue(), array($this->__validForm->getValidField("formfield_" . strtolower($varEmailId))->getValue()));
                 if (!empty($strErrors)) {
                     throw new Exception($strErrors, E_ERROR);
                 }
             }
             $strReturn = $this->__formElement->getField("ThanksBody")->getHtmlValue();
         } else {
             $strReturn = $this->__formElement->getField("ThanksBody")->getHtmlValue();
         }
     } else {
         $strReturn = $this->__validForm->toHtml($blnClientSide);
     }
     return $strReturn;
 }