示例#1
0
 public function getFieldsFromFormEntryConf()
 {
     $this->loadFormConfig();
     $form_config = $this->form_config;
     if (!\AppLibrary\Obj::iterable($form_config)) {
         return array();
     }
     if (!strlen($form_config->get('fields'))) {
         return array();
     }
     $fields = unserialize(unserialize($form_config->get('fields')));
     if (!\AppLibrary\Arr::iterable($fields)) {
         return array();
     }
     return $fields;
 }
示例#2
0
 /**
  * validate the form
  * @return boolean
  */
 public static function validate($source_fields, $form_config)
 {
     if (array_key_exists('form_config', $source_fields)) {
         unset($source_fields['form_config']);
     }
     $invalid_array = [];
     $fields = unserialize(unserialize($form_config->get('fields')));
     if ($form_config->get('use_honeypot') && array_key_exists($form_config->get('honeypot_field_name'), $_POST)) {
         $fields['honeypot'] = [];
         $source_fields['honeypot'] = $_POST[$form_config->get('honeypot_field_name')];
     }
     if ($form_config->get('use_recaptcha') && array_key_exists('g-recaptcha-response', $_POST)) {
         $fields['recaptcha'] = array('type' => 'hidden');
         $source_fields['recaptcha'] = $_POST['g-recaptcha-response'];
     }
     foreach ($fields as $k => $v) {
         $validation_types = [];
         if (array_key_exists($k, $source_fields)) {
             $source_value = $source_fields[$k];
         } else {
             $source_value = null;
         }
         // $validation_types[string] where string is the method name
         // of the trait method in FormValidators.php
         if (array_key_exists('required', $v)) {
             $validation_types['checkRequired'] = true;
         }
         if (array_key_exists('type', $v) && $v['type'] === 'email') {
             $validation_types['checkEmail'] = 1;
         }
         if (array_key_exists('type', $v) && $v['type'] === 'url') {
             $validation_types['checkURL'] = 1;
         }
         if (array_key_exists('maxlength', $v)) {
             $validation_types['checkMaxLength'] = $v['maxlength'];
         }
         if ($form_config->get('use_honeypot') && $k === 'honeypot') {
             $validation_types['checkHoneyPot'] = 1;
         }
         if ($form_config->get('use_recaptcha') && $k == 'recaptcha') {
             $validation_types['isGCaptchaFieldInValid'] = $form_config->get('google_recaptcha_secret_key');
         }
         if (\AppLibrary\Arr::iterable($validation_types)) {
             list($invalid, $errors) = self::validateFieldRequirements($validation_types, $source_value, $k);
             if ($invalid) {
                 $invalid_array[] = true;
             }
             self::pushErrors($k, join(', ', $errors));
             // field key, $errors
             unset($errors);
             unset($validation_types);
         }
     }
     if (in_array(true, $invalid_array)) {
         self::setValuesIfErrorsExist($source_fields);
         self::setInvalid();
         return false;
     }
     self::setSuccess();
     return true;
 }
        return array($k, $tax_name);
    }, $taxonomies);
}
$fields = $helper->getFields();
if (!array_key_exists('created_for_testing', $fields)) {
    echo '<b>Error:</b> A field named "created_for_testing"' . 'must be added to the getFields method for this post type\'s class.';
    exit;
}
unset($helper);
// based on the number in $_GET, create and iterate
for ($i = 0; $i < $n; $i++) {
    $faker = Faker\Factory::create();
    $faker->addProvider(new Faker\Provider\Resource($faker));
    $instance = new $post_type();
    // assign random terms
    if (\AppLibrary\Arr::iterable($taxonomies)) {
        foreach ($taxonomies_terms as $tax_name => $terms) {
            if (preg_match('/type/', $tax_name)) {
                $amount = 1;
            } else {
                $amount = rand(1, count($terms));
            }
            $terms_rand_keys = (array) array_rand($terms, rand(1, $amount));
            $terms_rand_values = array_map(function ($i) use($terms) {
                return $terms[$i];
            }, $terms_rand_keys);
            $instance->setTerms($terms_rand_values, $tax_name);
        }
    }
    $bool_for_checkbox = array(null, '1');
    // assign values to fields
?>
  </div>
  <div class="small-12 medium-6 columns">
    <?php 
echo $resources_search->renderGroup('taxonomy', 1);
?>
  </div>
</div>
<?php 
echo $resources_search->renderSearchFormFooter();
?>


<?php 
$results = $resources_search->getSearchresults();
if (\AppLibrary\Arr::iterable($results)) {
    ?>
  <?php 
    $result_posts = \Taco\Post\Factory::createMultiple($results);
    ?>
  <?php 
    foreach ($result_posts as $r) {
        ?>
    <div class="row">
      <div class="small-12 columns">
        <hr>
        <?php 
        echo $r->getTheTitle();
        ?>
        <?php 
        echo $r->getTheContent();