clear() public method

Method to clear any session data used with the form for security tokens, captchas, etc.
public clear ( ) : Form
return Form
Ejemplo n.º 1
0
<?php

require_once '../../bootstrap.php';
use Pop\Form\Form;
use Pop\Validator;
try {
    $fields = array('username' => array('type' => 'text', 'label' => 'Username:'******'required' => true, 'attributes' => array('size' => 40), 'validators' => new Validator\AlphaNumeric()), 'password' => array('type' => 'password', 'label' => 'Password:'******'required' => true, 'attributes' => array('size' => 40)), 'my_captcha' => array('type' => 'captcha', 'label' => 'Please Solve: ', 'attributes' => array('size' => 10), 'expire' => 120), 'submit' => array('type' => 'submit', 'value' => 'SUBMIT'));
    $form = new Form($_SERVER['PHP_SELF'], 'post', $fields, '    ');
    if ($_POST) {
        $form->setFieldValues($_POST, array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8')));
        if (!$form->isValid()) {
            $form->render();
        } else {
            // Option to clear out and reset security token
            $form->clear();
            echo 'Form is valid.<br />' . PHP_EOL;
            print_r($form->getFields());
        }
    } else {
        $form->render();
    }
    echo PHP_EOL . PHP_EOL;
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
Ejemplo n.º 2
0
 /**
  * Save user
  *
  * @param  \Pop\Form\Form $form
  * @param  \Pop\Config    $config
  * @return void
  */
 public function save(\Pop\Form\Form $form, $config)
 {
     $encOptions = $config->encryptionOptions->asArray();
     $fields = $form->getFields();
     $type = Table\UserTypes::findById($fields['type_id']);
     $password = isset($fields['password1']) ? self::encryptPassword($fields['password1'], $type->password_encryption, $encOptions) : '';
     // Set the username according to user type
     $username = isset($fields['username']) ? $fields['username'] : $fields['email1'];
     // Set the role according to user type
     if (isset($fields['role_id'])) {
         $fields['role_id'] = $fields['role_id'] == 0 ? null : $fields['role_id'];
     } else {
         $fields['role_id'] = $type->approval ? null : $type->default_role_id;
     }
     // Set verified or not
     if (!isset($fields['verified'])) {
         $fields['verified'] = $type->verification ? 0 : 1;
     }
     if (isset($fields['site_ids'])) {
         $siteIds = $fields['site_ids'];
     } else {
         $site = Table\Sites::getSite();
         $siteIds = array($site->id);
     }
     // Save the new user
     $user = new Table\Users(array('type_id' => $fields['type_id'], 'role_id' => $fields['role_id'], 'username' => $username, 'password' => $password, 'email' => $fields['email1'], 'verified' => $fields['verified'], 'logins' => null, 'failed_attempts' => 0, 'site_ids' => serialize($siteIds), 'created' => date('Y-m-d H:i:s')));
     $user->save();
     $this->data['id'] = $user->id;
     $sess = Session::getInstance();
     $sess->last_user_id = $user->id;
     FieldValue::save($fields, $user->id);
     // Send verification if needed
     if ($type->verification && !$user->verified) {
         $this->sendVerification($user, $type);
     }
     // Send registration notification to system admin
     if ($type->registration_notification) {
         $this->sendNotification($user, $type);
     }
     $form->clear();
 }