public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br)
 {
     $use_value = $modifier == 'value';
     $use_price = in_array($modifier, array('price', 'currency'));
     $format_currency = $modifier == 'currency';
     if (is_array($raw_value) && (string) intval($input_id) != $input_id) {
         $items = array($input_id => $value);
         //float input Ids. (i.e. 4.1 ). Used when targeting specific checkbox items
     } elseif (is_array($raw_value)) {
         $items = $raw_value;
     } else {
         $items = array($input_id => $raw_value);
     }
     $ary = array();
     foreach ($items as $input_id => $item) {
         if ($use_value) {
             list($val, $price) = rgexplode('|', $item, 2);
         } elseif ($use_price) {
             list($name, $val) = rgexplode('|', $item, 2);
             if ($format_currency) {
                 $val = GFCommon::to_money($val, rgar($entry, 'currency'));
             }
         } elseif ($this->type == 'post_category') {
             $use_id = strtolower($modifier) == 'id';
             $item_value = GFCommon::format_post_category($item, $use_id);
             $val = RGFormsModel::is_field_hidden($form, $this, array(), $entry) ? '' : $item_value;
         } else {
             $val = RGFormsModel::is_field_hidden($form, $this, array(), $entry) ? '' : RGFormsModel::get_choice_text($this, $raw_value, $input_id);
         }
         $ary[] = GFCommon::format_variable_value($val, $url_encode, $esc_html, $format);
     }
     return GFCommon::implode_non_blank(', ', $ary);
 }
 /**
  * Check if the iDEAL condition is true
  *
  * @param mixed $form
  * @param mixed $feed
  */
 public static function is_condition_true($form, $feed)
 {
     if (!$feed->condition_enabled) {
         return true;
     }
     $field = RGFormsModel::get_field($form, $feed->condition_field_id);
     // Unknown field
     if (empty($field)) {
         return true;
     }
     $is_hidden = RGFormsModel::is_field_hidden($form, $field, array());
     // Ignore condition if the field is hidden
     if ($is_hidden) {
         return false;
     }
     $value = RGFormsModel::get_field_value($field, array());
     $is_match = RGFormsModel::is_value_match($value, $feed->condition_value);
     switch ($feed->condition_operator) {
         case Pronamic_WP_Pay_Extensions_GravityForms_GravityForms::OPERATOR_IS:
             $result = $is_match;
             break;
         case Pronamic_WP_Pay_Extensions_GravityForms_GravityForms::OPERATOR_IS_NOT:
             $result = !$is_match;
             break;
         default:
             $result = true;
     }
     return $result;
 }
 function is_applicable_field($field, $form)
 {
     if ($field['pageNumber'] != GFFormDisplay::get_source_page($form['id'])) {
         return false;
     }
     if ($field['type'] != 'list' || RGFormsModel::is_field_hidden($form, $field, array())) {
         return false;
     }
     // if the field has already failed validation, we don't need to fail it again
     if (!$field['isRequired'] || $field['failed_validation']) {
         return false;
     }
     if (empty($this->field_ids)) {
         return true;
     }
     return in_array($field['id'], $this->field_ids);
 }
Beispiel #4
0
function validate_captcha($validation_result)
{
    // 2 - Get the form object from the validation result
    $form = $validation_result["form"];
    // 3 - Get the current page being validated
    $current_page = rgpost('gform_source_page_number_' . $form['id']) ? rgpost('gform_source_page_number_' . $form['id']) : 1;
    //print_r($validation_result); exit;
    // 4 - Loop through the form fields
    foreach ($form['fields'] as &$field) {
        // 5 - If the field does not have our designated CSS class, skip it
        if (strpos($field['cssClass'], 'validate-anti-spam') === false) {
            continue;
        }
        // 6 - Get the field's page number
        $field_page = $field['pageNumber'];
        // 7 - Check if the field is hidden by GF conditional logic
        $is_hidden = RGFormsModel::is_field_hidden($form, $field, array());
        // 8 - If the field is not on the current page OR if the field is hidden, skip it
        if ($field_page != $current_page || $is_hidden) {
            continue;
        }
        // 9 - Get the submitted value from the $_POST
        $field_value = rgpost("input_{$field['id']}");
        // 10 - Make a call to your validation function to validate the value
        $is_valid = is_valid_captcha($field_value);
        // 11 - If the field is valid we don't need to do anything, skip it
        if ($is_valid) {
            continue;
        }
        // 12 - The field failed validation, so first we'll need to fail the validation for the entire form
        $validation_result['is_valid'] = false;
        // 13 - Next we'll mark the specific field that failed and add a custom validation message
        $field['failed_validation'] = true;
        $field['validation_message'] = 'Vul het antwoord op de vraag in, het antwoord is het getal nul (0).';
    }
    // 14 - Assign our modified $form object back to the validation result
    $validation_result['form'] = $form;
    // 15 - Return the validation result
    return $validation_result;
}
Beispiel #5
0
 /**
  * Check if the iDEAL condition is true
  *
  * @param mixed $form
  * @param mixed $feed
  */
 public static function is_condition_true($form, $feed)
 {
     $result = true;
     if ($feed->condition_enabled) {
         $field = RGFormsModel::get_field($form, $feed->condition_field_id);
         if (empty($field)) {
             // unknown field
             $result = true;
         } else {
             $is_hidden = RGFormsModel::is_field_hidden($form, $field, array());
             if ($is_hidden) {
                 // if conditional is enabled, but the field is hidden, ignore conditional
                 $result = false;
             } else {
                 $value = RGFormsModel::get_field_value($field, array());
                 $is_match = RGFormsModel::is_value_match($value, $feed->condition_value);
                 switch ($feed->condition_operator) {
                     case Pronamic_WP_Pay_Extensions_GravityForms_GravityForms::OPERATOR_IS:
                         $result = $is_match;
                         break;
                     case Pronamic_WP_Pay_Extensions_GravityForms_GravityForms::OPERATOR_IS_NOT:
                         $result = !$is_match;
                         break;
                     default:
                         // unknown operator
                         $result = true;
                         break;
                 }
             }
         }
     } else {
         // condition is disabled, result is true
         $result = true;
     }
     return $result;
 }
 /**
  * Prepare the value before saving it to the lead.
  *
  * @param mixed $form
  * @param mixed $field
  * @param mixed $value
  * @param mixed $input_name
  * @param mixed $lead_id the current lead ID, used for fields that are processed after other fields have been saved (ie Total, Calculations)
  * @param mixed $lead passed by the RGFormsModel::create_lead() method, lead ID is not available for leads created by this function
  */
 public static function prepare_value($form, $field, $value, $input_name, $lead_id, $lead = array())
 {
     $form_id = $form["id"];
     $input_type = self::get_input_type($field);
     switch ($input_type) {
         case "total":
             $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
             $value = GFCommon::get_order_total($form, $lead);
             break;
         case "calculation":
             // ignore submitted value and recalculate price in backend
             list(, , $input_id) = rgexplode("_", $input_name, 3);
             if ($input_id == 2) {
                 require_once GFCommon::get_base_path() . '/currency.php';
                 $currency = new RGCurrency(GFCommon::get_currency());
                 $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
                 $value = $currency->to_money(GFCommon::calculate($field, $form, $lead));
             }
             break;
         case "phone":
             if ($field["phoneFormat"] == "standard" && preg_match('/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/', $value, $matches)) {
                 $value = sprintf("(%s)%s-%s", $matches[1], $matches[2], $matches[3]);
             }
             break;
         case "time":
             if (!is_array($value) && !empty($value)) {
                 preg_match('/^(\\d*):(\\d*) ?(.*)$/', $value, $matches);
                 $value = array();
                 $value[0] = $matches[1];
                 $value[1] = $matches[2];
                 $value[2] = rgar($matches, 3);
             }
             $hour = empty($value[0]) ? "0" : strip_tags($value[0]);
             $minute = empty($value[1]) ? "0" : strip_tags($value[1]);
             $ampm = strip_tags(rgar($value, 2));
             if (!empty($ampm)) {
                 $ampm = " {$ampm}";
             }
             if (!(empty($hour) && empty($minute))) {
                 $value = sprintf("%02d:%02d%s", $hour, $minute, $ampm);
             } else {
                 $value = "";
             }
             break;
         case "date":
             $value = self::prepare_date(rgar($field, 'dateFormat'), $value);
             break;
         case "post_image":
             $url = self::get_fileupload_value($form_id, $input_name);
             $image_title = isset($_POST["{$input_name}_1"]) ? strip_tags($_POST["{$input_name}_1"]) : "";
             $image_caption = isset($_POST["{$input_name}_4"]) ? strip_tags($_POST["{$input_name}_4"]) : "";
             $image_description = isset($_POST["{$input_name}_7"]) ? strip_tags($_POST["{$input_name}_7"]) : "";
             $value = !empty($url) ? $url . "|:|" . $image_title . "|:|" . $image_caption . "|:|" . $image_description : "";
             break;
         case "fileupload":
             if (rgar($field, "multipleFiles")) {
                 global $_gf_uploaded_files;
                 if (isset($_gf_uploaded_files[$input_name])) {
                     $value = $_gf_uploaded_files[$input_name];
                 } else {
                     if (isset(GFFormsModel::$uploaded_files[$form_id][$input_name])) {
                         $uploaded_temp_files = GFFormsModel::$uploaded_files[$form_id][$input_name];
                         $uploaded_files = array();
                         foreach ($uploaded_temp_files as $i => $file_info) {
                             $temp_filepath = self::get_upload_path($form_id) . '/tmp/' . $file_info['temp_filename'];
                             if ($file_info && file_exists($temp_filepath)) {
                                 $uploaded_files[$i] = self::move_temp_file($form_id, $file_info);
                             }
                         }
                         if (!empty($value)) {
                             // merge with existing files (admin edit entry)
                             $value = json_decode($value, true);
                             $value = array_merge($value, $uploaded_files);
                             $value = json_encode($value);
                         } else {
                             $value = json_encode($uploaded_files);
                         }
                     } else {
                         $value = '';
                     }
                     $_gf_uploaded_files[$input_name] = $value;
                 }
             } else {
                 $value = self::get_fileupload_value($form_id, $input_name);
             }
             break;
         case "number":
             $value = GFCommon::maybe_add_leading_zero($value);
             $is_hidden = RGFormsModel::is_field_hidden($form, $field, array());
             $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
             $value = GFCommon::has_field_calculation($field) ? GFCommon::round_number(GFCommon::calculate($field, $form, $lead), rgar($field, "calculationRounding")) : GFCommon::clean_number($value, rgar($field, "numberFormat"));
             //return the value as a string when it is zero and a calc so that the "==" comparison done when checking if the field has changed isn't treated as false
             if (GFCommon::has_field_calculation($field) && $value == 0) {
                 $value = "0";
             }
             break;
         case "website":
             if ($value == "http://") {
                 $value = "";
             }
             break;
         case "list":
             if (rgar($field, "adminOnly") && rgar($field, "allowsPrepopulate")) {
                 $value = json_decode($value);
             }
             if (GFCommon::is_empty_array($value)) {
                 $value = "";
             } else {
                 foreach ($value as &$val) {
                     $val = self::sanitize_entry_value($field, $val, $input_type, $form_id);
                 }
                 $value = self::create_list_array($field, $value);
                 $value = serialize($value);
             }
             break;
         case "radio":
             if (rgar($field, 'enableOtherChoice') && $value == 'gf_other_choice') {
                 $value = rgpost("input_{$field['id']}_other");
             }
             $value = self::sanitize_entry_value($field, $value, $input_type, $form_id);
             break;
         case "multiselect":
             $value = empty($value) ? "" : is_array($value) ? implode(",", $value) : $value;
             $value = self::sanitize_entry_value($field, $value, $input_type, $form_id);
             break;
         case "creditcard":
             //saving last 4 digits of credit card
             list($input_token, $field_id_token, $input_id) = rgexplode("_", $input_name, 3);
             if ($input_id == "1") {
                 $value = str_replace(" ", "", $value);
                 $card_number_length = strlen($value);
                 $value = substr($value, -4, 4);
                 $value = str_pad($value, $card_number_length, "X", STR_PAD_LEFT);
             } else {
                 if ($input_id == '4') {
                     $value = rgpost("input_{$field_id_token}_4");
                     if (!$value) {
                         $card_number = rgpost("input_{$field_id_token}_1");
                         $card_type = GFCommon::get_card_type($card_number);
                         $value = $card_type ? $card_type['name'] : '';
                     }
                 } else {
                     $value = "";
                 }
             }
             break;
         case 'password':
             $encrypt_password = apply_filters('gform_encrypt_password', false, $field, $form);
             if ($encrypt_password) {
                 $value = GFCommon::encrypt($value);
                 self::set_encrypted_fields($lead_id, $field['id']);
             }
             break;
         default:
             // only filter HTML on non-array based values
             if (!is_array($value)) {
                 $value = self::sanitize_entry_value($field, $value, $input_type, $form_id);
             }
             break;
     }
     // special format for Post Category fields
     if ($field['type'] == 'post_category') {
         $full_values = array();
         if (!is_array($value)) {
             $value = explode(',', $value);
         }
         foreach ($value as $cat_id) {
             $cat = get_term($cat_id, 'category');
             $full_values[] = !is_wp_error($cat) && is_object($cat) ? $cat->name . ":" . $cat_id : "";
         }
         $value = implode(',', $full_values);
     }
     //do not save price fields with blank price
     if (rgar($field, "enablePrice")) {
         $ary = explode("|", $value);
         $label = count($ary) > 0 ? $ary[0] : "";
         $price = count($ary) > 1 ? $ary[1] : "";
         $is_empty = strlen(trim($price)) <= 0;
         if ($is_empty) {
             $value = "";
         }
     }
     return $value;
 }
Beispiel #7
0
 public static function is_optin($form, $settings, $entry)
 {
     $config = $settings["meta"];
     $field = RGFormsModel::get_field($form, $config["optin_field_id"]);
     if (empty($field) || !$config["optin_enabled"]) {
         return true;
     }
     $operator = $config["optin_operator"];
     $field_value = RGFormsModel::get_lead_field_value($entry, $field);
     $is_value_match = RGFormsModel::is_value_match($field_value, $config["optin_value"]);
     $is_visible = !RGFormsModel::is_field_hidden($form, $field, array(), $entry);
     $is_match = $is_value_match && $is_visible;
     $is_optin = $operator == "is" && $is_match || $operator == "isnot" && !$is_match;
     return $is_optin;
 }
 /**
  * Adapted from forms_model.php, RGFormsModel::save_lead($Form, $lead)
  * @param  array $form Form object.
  * @param  array $lead Lead object
  * @return void
  */
 public static function save_lead($form, &$lead)
 {
     global $wpdb;
     if (IS_ADMIN && !GFCommon::current_user_can_any("gravityforms_edit_entries")) {
         die(__("You don't have adequate permission to edit entries.", "gravityforms"));
     }
     $lead_detail_table = RGFormsModel::get_lead_details_table_name();
     //Inserting lead if null
     if ($lead == null) {
         global $current_user;
         $user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL';
         $lead_table = RGFormsModel::get_lead_table_name();
         $user_agent = RGFormsModel::truncate($_SERVER["HTTP_USER_AGENT"], 250);
         $currency = GFCommon::get_currency();
         $source_url = RGFormsModel::truncate(RGFormsModel::get_current_page_url(), 200);
         $wpdb->query($wpdb->prepare("INSERT INTO {$lead_table}(form_id, ip, source_url, date_created, user_agent, currency, created_by) VALUES(%d, %s, %s, utc_timestamp(), %s, %s, {$user_id})", $form["id"], RGFormsModel::get_ip(), $source_url, $user_agent, $currency));
         //reading newly created lead id
         $lead_id = $wpdb->insert_id;
         $lead = array("id" => $lead_id);
     }
     $current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $lead["id"]));
     $original_post_id = rgget("post_id", $lead);
     $total_fields = array();
     $calculation_fields = array();
     $recalculate_total = false;
     foreach ($form["fields"] as $field) {
         //Ignore fields that are marked as display only
         if (rgget("displayOnly", $field) && $field["type"] != "password") {
             continue;
         }
         //ignore pricing fields in the entry detail
         if (RG_CURRENT_VIEW == "entry" && GFCommon::is_pricing_field($field["type"])) {
             continue;
         }
         //process total field after all fields have been saved
         if ($field["type"] == "total") {
             $total_fields[] = $field;
             continue;
         }
         //only save fields that are not hidden (except on entry screen)
         if (RG_CURRENT_VIEW == "entry" || !RGFormsModel::is_field_hidden($form, $field, array(), $lead)) {
             // process calculation fields after all fields have been saved (moved after the is hidden check)
             if (GFCommon::has_field_calculation($field)) {
                 $calculation_fields[] = $field;
                 continue;
             }
             if ($field['type'] == 'post_category') {
                 $field = GFCommon::add_categories_as_choices($field, '');
             }
             if (isset($field["inputs"]) && is_array($field["inputs"])) {
                 foreach ($field["inputs"] as $input) {
                     RGFormsModel::save_input($form, $field, $lead, $current_fields, $input["id"]);
                 }
             } else {
                 RGFormsModel::save_input($form, $field, $lead, $current_fields, $field["id"]);
             }
         }
         //Refresh lead to support conditionals (not optimal but...)
         $lead = RGFormsModel::get_lead($lead['id']);
     }
     if (!empty($calculation_fields)) {
         foreach ($calculation_fields as $calculation_field) {
             if (isset($calculation_field["inputs"]) && is_array($calculation_field["inputs"])) {
                 foreach ($calculation_field["inputs"] as $input) {
                     RGFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $input["id"]);
                     RGFormsModel::refresh_lead_field_value($lead["id"], $input["id"]);
                 }
             } else {
                 RGFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field["id"]);
                 RGFormsModel::refresh_lead_field_value($lead["id"], $calculation_field["id"]);
             }
         }
         RGFormsModel::refresh_product_cache($form, $lead = RGFormsModel::get_lead($lead['id']));
     }
     //saving total field as the last field of the form.
     if (!empty($total_fields)) {
         foreach ($total_fields as $total_field) {
             GFCommon::log_debug("Saving total field.");
             RGFormsModel::save_input($form, $total_field, $lead, $current_fields, $total_field["id"]);
         }
     }
 }
Beispiel #9
0
 public static function create_lead($form)
 {
     global $current_user;
     $total_fields = array();
     $calculation_fields = array();
     $lead = array();
     $lead['id'] = null;
     $lead['post_id'] = null;
     $lead['date_created'] = null;
     $lead['form_id'] = $form['id'];
     $lead['ip'] = self::get_ip();
     $source_url = self::truncate(self::get_current_page_url(), 200);
     $lead['source_url'] = esc_url_raw($source_url);
     $user_agent = strlen($_SERVER['HTTP_USER_AGENT']) > 250 ? substr($_SERVER['HTTP_USER_AGENT'], 0, 250) : $_SERVER['HTTP_USER_AGENT'];
     $lead['user_agent'] = sanitize_text_field($user_agent);
     $lead['created_by'] = $current_user && $current_user->ID ? $current_user->ID : 'NULL';
     /**
      * Allow the currency code to be overridden.
      *
      * @param string $currency The three character ISO currency code to be stored in the entry. Default is value returned by GFCommon::get_currency()
      * @param array $form The form currently being processed.
      *
      */
     $lead['currency'] = gf_apply_filters('gform_currency_pre_save_entry', $form['id'], GFCommon::get_currency(), $form);
     foreach ($form['fields'] as $field) {
         /* @var $field GF_Field */
         // ignore fields that are marked as display only
         if ($field->displayOnly && $field->type != 'password') {
             continue;
         }
         // process total field after all fields have been saved
         if ($field->type == 'total') {
             $total_fields[] = $field;
             continue;
         }
         // process calculation fields after all fields have been saved
         if ($field->has_calculation()) {
             $calculation_fields[] = $field;
             continue;
         }
         // only save fields that are not hidden
         if (!RGFormsModel::is_field_hidden($form, $field, array())) {
             if ($field->type == 'post_category') {
                 $field = GFCommon::add_categories_as_choices($field, '');
             }
             $inputs = $field->get_entry_inputs();
             if (is_array($inputs)) {
                 foreach ($inputs as $input) {
                     $lead[(string) $input['id']] = self::get_prepared_input_value($form, $field, $lead, $input['id']);
                 }
             } else {
                 $lead[$field->id] = self::get_prepared_input_value($form, $field, $lead, $field->id);
             }
         }
     }
     if (!empty($calculation_fields)) {
         foreach ($calculation_fields as $field) {
             /* @var $field GF_Field */
             // only save fields that are not hidden
             if (RGFormsModel::is_field_hidden($form, $field, array())) {
                 continue;
             }
             $inputs = $field->get_entry_inputs();
             if (is_array($inputs)) {
                 foreach ($inputs as $input) {
                     $lead[(string) $input['id']] = self::get_prepared_input_value($form, $field, $lead, $input['id']);
                 }
             } else {
                 $lead[$field->id] = self::get_prepared_input_value($form, $field, $lead, $field->id);
             }
         }
         self::refresh_product_cache($form, $lead);
     }
     // saving total field as the last field of the form.
     if (!empty($total_fields)) {
         foreach ($total_fields as $total_field) {
             $lead[$total_field->id] = self::get_prepared_input_value($form, $total_field, $lead, $total_field->id);
         }
     }
     return $lead;
 }
Beispiel #10
0
 public static function user_registration_validation($validation_result)
 {
     $form = $validation_result['form'];
     $entry = self::convert_post_to_entry();
     $config = self::get_active_config($form, $entry);
     $is_update_feed = rgars($config, 'meta/feed_type') == 'update';
     $pagenum = rgpost("gform_source_page_number_{$form['id']}");
     // if there is no registration feed or the registration condition is not met or feed is inactive, abandon ship
     if (!$config || !self::registration_condition_met($form, $config, $entry) || !$config['is_active']) {
         return $validation_result;
     }
     $username_field = RGFormsModel::get_field($form, $config['meta']['username']);
     $email_field = RGFormsModel::get_field($form, $config['meta']['email']);
     $password_field = RGFormsModel::get_field($form, $config['meta']['password']);
     $is_username_hidden = RGFormsModel::is_field_hidden($form, $username_field, array());
     $is_email_hidden = RGFormsModel::is_field_hidden($form, $email_field, array());
     $is_password_hidden = RGFormsModel::is_field_hidden($form, $password_field, array());
     $user_name = apply_filters("gform_username_{$form['id']}", apply_filters('gform_username', self::get_meta_value('username', $config, $form, $entry), $config, $form, $entry), $config, $form, $entry);
     $user_email = self::get_prepared_value($email_field, $config['meta']['email'], $entry);
     $user_pass = rgpost('input_' . $config['meta']['password']);
     //$user_pass = stripslashes( $user_pass );
     if (!function_exists('username_exists')) {
         require_once ABSPATH . WPINC . "/registration.php";
     }
     // if password field is not hidden and is on the current page we are validating, validate it
     if (!$is_password_hidden && $password_field['pageNumber'] == $pagenum) {
         if (strpos($user_pass, "\\") !== false) {
             $form = self::add_validation_failure($config['meta']['password'], $form, __('Passwords may not contain the character "\\"', 'gravityformsuserregistration'));
         }
     }
     if (is_multisite()) {
         // if multisite is defined and true, lowercase name for validation
         $user_name = strtolower($user_name);
         $_POST['input_' . str_replace('.', '_', $config['meta']['username'])] = $user_name;
         $result = wpmu_validate_user_signup($user_name, $user_email);
         $errors = $result['errors']->errors;
         // special validation overrides for update feeds
         if ($is_update_feed) {
             // do not validate username on update feeds
             if (isset($errors['user_name'])) {
                 unset($errors['user_name']);
             }
             // do not validate if email belongs to user
             if (isset($errors['user_email'])) {
                 for ($i = count($errors['user_email']) - 1; $i >= 0; $i--) {
                     $error_message = $errors['user_email'][$i];
                     // if user is re-submitting their own email address, don't give already used error
                     if ($error_message == __('Sorry, that email address is already used!') && self::is_users_email($user_email)) {
                         unset($errors['user_email'][$i]);
                     } elseif ($error_message == __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.') && self::is_users_email($user_email)) {
                         unset($errors['user_email'][$i]);
                     }
                 }
                 // if no other user email errors remain, unset
                 if (count($errors['user_email']) <= 0) {
                     unset($errors['user_email']);
                 }
             }
         }
         if (!empty($errors)) {
             foreach ($errors as $type => $error_msgs) {
                 foreach ($error_msgs as $error_msg) {
                     switch ($type) {
                         case 'user_name':
                             if (!$is_username_hidden && $username_field['pageNumber'] == $pagenum) {
                                 $form = self::add_validation_failure($config['meta']['username'], $form, $error_msg);
                             }
                             break;
                         case 'user_email':
                             if (!$is_email_hidden && $email_field['pageNumber'] == $pagenum) {
                                 $form = self::add_validation_failure($config['meta']['email'], $form, $error_msg);
                             }
                             break;
                     }
                 }
             }
         }
     } else {
         if (!$is_email_hidden && $email_field['pageNumber'] == $pagenum) {
             $email_valid = true;
             $email_exists = email_exists($user_email);
             if (!$user_email) {
                 $email_valid = false;
                 $form = self::add_validation_failure($config['meta']['email'], $form, __('The email address can not be empty', 'gravityformsuserregistration'));
             }
             if ($email_valid && self::pending_activation_exists('user_email', $user_email)) {
                 $email_valid = false;
                 $form = self::add_validation_failure($config['meta']['email'], $form, __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.'));
             }
             if ($email_valid && !$is_update_feed && $email_exists) {
                 $form = self::add_validation_failure($config['meta']['email'], $form, __('This email address is already registered', 'gravityformsuserregistration'));
             } elseif ($email_valid && $is_update_feed && $email_exists && !self::is_users_email($user_email)) {
                 $form = self::add_validation_failure($config['meta']['email'], $form, __('This email address is already registered', 'gravityformsuserregistration'));
             }
         }
         // do not validate the user name if this is an update feed, if the user name field is hidden or if we are not on the correct page
         if (!$is_update_feed && !$is_username_hidden && $username_field['pageNumber'] == $pagenum) {
             $username_valid = true;
             if (empty($user_name)) {
                 $username_valid = false;
                 $form = self::add_validation_failure($config['meta']['username'], $form, __('The username can not be empty', 'gravityformsuserregistration'));
             }
             if ($username_valid && !validate_username($user_name)) {
                 $username_valid = false;
                 $form = self::add_validation_failure($config['meta']['username'], $form, __('The username can only contain alphanumeric characters (A-Z, 0-9), underscores, dashes and spaces', 'gravityformsuserregistration'));
             }
             if ($username_valid && self::is_bp_active() && strpos($user_name, " ") !== false) {
                 $username_valid = false;
                 $form = self::add_validation_failure($config['meta']['username'], $form, __('The username can only contain alphanumeric characters (A-Z, 0-9), underscores and dashes', 'gravityformsuserregistration'));
             }
             if ($username_valid && username_exists($user_name)) {
                 $username_valid = false;
                 $form = self::add_validation_failure($config['meta']['username'], $form, __('This username is already registered', 'gravityformsuserregistration'));
             }
             if ($username_valid && self::pending_activation_exists('user_login', $user_name)) {
                 $form = self::add_validation_failure($config['meta']['username'], $form, __('That username is currently reserved but may be available in a couple of days'));
             }
         }
     }
     $form = apply_filters('gform_user_registration_validation', $form, $config, $pagenum);
     $validation_result["is_valid"] = self::is_form_valid($form);
     $validation_result["form"] = $form;
     return $validation_result;
 }
Beispiel #11
0
 public function get_issuer_id()
 {
     $issuer_id = null;
     $issuer_field = null;
     $issuer_fields = GFCommon::get_fields_by_type($this->form, array(Pronamic_WP_Pay_Extensions_GravityForms_IssuerDropDown::TYPE));
     foreach ($issuer_fields as $field) {
         if (!RGFormsModel::is_field_hidden($this->form, $field, array())) {
             $issuer_field = $field;
             break;
         }
     }
     if (null !== $issuer_field) {
         $issuer_id = RGFormsModel::get_field_value($issuer_field);
     }
     return $issuer_id;
 }
 public function authorize($feed, $submission_data, $form, $entry)
 {
     // public function process_feed($feed, $entry, $form){
     $data = array();
     foreach ($form["fields"] as $field) {
         if ($field['type'] == 'creditcard' && !RGFormsModel::is_field_hidden($form, $field, array())) {
             $ccnumber = rgpost('input_' . $field['id'] . '_1');
             $ccdate_array = rgpost('input_' . $field['id'] . '_2');
             $ccdate_month = $ccdate_array[0];
             if (strlen($ccdate_month) < 2) {
                 $ccdate_month = '0' . $ccdate_month;
             }
             $ccdate_year = $ccdate_array[1];
             if (strlen($ccdate_year) > 2) {
                 $ccdate_year = substr($ccdate_year, -2);
             }
             // Only want last 2 digits
             $ccv = rgpost('input_' . $field['id'] . '_3');
             $ccname = rgpost('input_' . $field['id'] . '_5');
             $is_creditcard = true;
             $data["customer"]["payment_source"]["card_name"] = $ccname;
             $data["customer"]["payment_source"]["card_number"] = $ccnumber;
             $data["customer"]["payment_source"]["expire_month"] = $ccdate_month;
             $data["customer"]["payment_source"]["expire_year"] = $ccdate_year;
             $data["customer"]["payment_source"]["card_ccv"] = $ccv;
         }
     }
     $payment_type = $entry[$feed["meta"]["pd_payment_mapped_details_pd_payment_type"]];
     if ($payment_type == "bsb") {
         $data["customer"]["payment_source"]["type"] = "bsb";
         $data["customer"]["payment_source"]["account_name"] = $entry[$feed["meta"]["pd_payment_mapped_details_pd_account_name"]];
         $data["customer"]["payment_source"]["account_bsb"] = $entry[$feed["meta"]["pd_payment_mapped_details_pd_account_bsb"]];
         $data["customer"]["payment_source"]["account_number"] = $entry[$feed["meta"]["pd_payment_mapped_details_pd_account_number"]];
     }
     $data["customer"]["payment_source"]["gateway_id"] = $feed["meta"]["pd_select_gateway"];
     $data["customer"]["first_name"] = $entry[$feed["meta"]["pd_personal_mapped_details_pd_first_name"]];
     $data["customer"]["last_name"] = $entry[$feed["meta"]["pd_personal_mapped_details_pd_last_name"]];
     $data["customer"]["email"] = $entry[$feed["meta"]["pd_personal_mapped_details_pd_email"]];
     $data["reference"] = $entry[$feed["meta"]["pd_payment_mapped_details_pd_transaction_reference"]];
     $data["amount"] = $entry[$feed["meta"]["pd_payment_mapped_details_pd_total_payable"]];
     $data["currency"] = !empty($currency) ? $currency : GFCommon::get_currency();
     $pd_options = get_option('gravityformsaddon_gravityformspaydock_settings');
     $api_key = $pd_options['paydock_api_key'];
     $api_url = $pd_options['paydock_api_uri'] . 'charges/';
     $data_string = json_encode($data);
     $envoyrecharge_key = $api_key;
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $api_url);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-user-token:' . $envoyrecharge_key, 'Content-Type: application/json', 'Content-Length: ' . strlen($data_string)));
     $result = curl_exec($ch);
     curl_close($ch);
     $response = json_decode($result);
     if ($response->status > "250") {
         // set the form validation to false
         $auth = array('is_authorized' => false, 'transaction_id' => $response->resource->data->_id, 'error_message' => "There was an error with your transaction please try again.");
         foreach ($form['fields'] as &$field) {
             if ($field->id == '9') {
                 $field->failed_validation = true;
                 $field->validation_message = 'There was a problem processing your payment, please try again or contact us.';
                 break;
             }
         }
     } else {
         $auth = array('is_authorized' => true, 'transaction_id' => $response->resource->data->_id);
     }
     return $auth;
     // $feedName = $feed["meta"]["feedName"];
     // $mytextbox = $feed["meta"]["mytextbox"];
     // $checkbox = $feed["meta"]["mycheckbox"];
     // $mapped_email = $feed["meta"]["mappedFields_email"];
     // $mapped_name = $feed["meta"]["mappedFields_name"];
     // $email = $entry[$mapped_email];
     // $name = $entry[$mapped_name];
 }
Beispiel #13
0
 public static function get_product_fields($form, $lead, $use_choice_text = false, $use_admin_label = false)
 {
     $products = array();
     $product_info = null;
     // retrieve static copy of product info (only for "real" entries)
     if (!rgempty("id", $lead)) {
         $product_info = gform_get_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}");
     }
     // if no static copy, generate from form/lead info
     if (!$product_info) {
         foreach ($form["fields"] as $field) {
             $id = $field["id"];
             $lead_value = RGFormsModel::get_lead_field_value($lead, $field);
             $quantity_field = self::get_product_fields_by_type($form, array("quantity"), $id);
             $quantity = sizeof($quantity_field) > 0 && !RGFormsModel::is_field_hidden($form, $quantity_field[0], array(), $lead) ? RGFormsModel::get_lead_field_value($lead, $quantity_field[0]) : 1;
             switch ($field["type"]) {
                 case "product":
                     //ignore products that have been hidden by conditional logic
                     $is_hidden = RGFormsModel::is_field_hidden($form, $field, array(), $lead);
                     if ($is_hidden) {
                         continue;
                     }
                     //if single product, get values from the multiple inputs
                     if (is_array($lead_value)) {
                         $product_quantity = sizeof($quantity_field) == 0 && !rgar($field, "disableQuantity") ? rgget($id . ".3", $lead_value) : $quantity;
                         if (empty($product_quantity)) {
                             continue;
                         }
                         if (!rgget($id, $products)) {
                             $products[$id] = array();
                         }
                         $products[$id]["name"] = $use_admin_label && !rgempty("adminLabel", $field) ? $field["adminLabel"] : $lead_value[$id . ".1"];
                         $products[$id]["price"] = $lead_value[$id . ".2"];
                         $products[$id]["quantity"] = $product_quantity;
                     } else {
                         if (!empty($lead_value)) {
                             if (empty($quantity)) {
                                 continue;
                             }
                             if (!rgar($products, $id)) {
                                 $products[$id] = array();
                             }
                             if ($field["inputType"] == "price") {
                                 $name = $field["label"];
                                 $price = $lead_value;
                             } else {
                                 list($name, $price) = explode("|", $lead_value);
                             }
                             $products[$id]["name"] = !$use_choice_text ? $name : RGFormsModel::get_choice_text($field, $name);
                             $products[$id]["price"] = $price;
                             $products[$id]["quantity"] = $quantity;
                             $products[$id]["options"] = array();
                         }
                     }
                     if (isset($products[$id])) {
                         $options = self::get_product_fields_by_type($form, array("option"), $id);
                         foreach ($options as $option) {
                             $option_value = RGFormsModel::get_lead_field_value($lead, $option);
                             $option_label = empty($option["adminLabel"]) ? $option["label"] : $option["adminLabel"];
                             if (is_array($option_value)) {
                                 foreach ($option_value as $value) {
                                     $option_info = self::get_option_info($value, $option, $use_choice_text);
                                     if (!empty($option_info)) {
                                         $products[$id]["options"][] = array("field_label" => rgar($option, "label"), "option_name" => rgar($option_info, "name"), "option_label" => $option_label . ": " . rgar($option_info, "name"), "price" => rgar($option_info, "price"));
                                     }
                                 }
                             } else {
                                 if (!empty($option_value)) {
                                     $option_info = self::get_option_info($option_value, $option, $use_choice_text);
                                     $products[$id]["options"][] = array("field_label" => rgar($option, "label"), "option_name" => rgar($option_info, "name"), "option_label" => $option_label . ": " . rgar($option_info, "name"), "price" => rgar($option_info, "price"));
                                 }
                             }
                         }
                     }
                     break;
             }
         }
         $shipping_field = self::get_fields_by_type($form, array("shipping"));
         $shipping_price = $shipping_name = "";
         if (!empty($shipping_field) && !RGFormsModel::is_field_hidden($form, $shipping_field[0], array(), $lead)) {
             $shipping_price = RGFormsModel::get_lead_field_value($lead, $shipping_field[0]);
             $shipping_name = $shipping_field[0]["label"];
             if ($shipping_field[0]["inputType"] != "singleshipping") {
                 list($shipping_method, $shipping_price) = explode("|", $shipping_price);
                 $shipping_name = $shipping_field[0]["label"] . " ({$shipping_method})";
             }
         }
         $shipping_price = self::to_number($shipping_price);
         $product_info = array("products" => $products, "shipping" => array("name" => $shipping_name, "price" => $shipping_price));
         $product_info = apply_filters("gform_product_info_{$form["id"]}", apply_filters("gform_product_info", $product_info, $form, $lead), $form, $lead);
         // save static copy of product info (only for "real" entries)
         if (!rgempty("id", $lead) && !empty($product_info["products"])) {
             gform_update_meta($lead['id'], "gform_product_info_{$use_choice_text}_{$use_admin_label}", $product_info);
         }
     }
     return $product_info;
 }
 /**
  * Validates the solution to the math captcha question.
  *
  * @since    1.0.0
  */
 public function math_captcha_validation($validation_result)
 {
     $form = $validation_result['form'];
     $current_page = rgpost('gform_source_page_number_' . $form['id']) ? rgpost('gform_source_page_number_' . $form['id']) : 1;
     foreach ($form['fields'] as &$field) {
         // Check that we're validating a math captcha field.
         if ($field['type'] != 'math_captcha') {
             continue;
         }
         // Make sure that the field isn't hidden or on a different page of the form.
         $field_page = $field['pageNumber'];
         $is_hidden = RGFormsModel::is_field_hidden($form, $field, array());
         if ($field_page != $current_page || $is_hidden) {
             continue;
         }
         // Get the accepted answers from the hidden input.
         $answers_no_spam = rgpost("math_captcha_answers_{$field['id']}");
         // Convert the encoded answers from hexidecimal format.
         $answers_unhex = '';
         $answers = preg_replace('/[^A-Za-z0-9]/', '', $answers_no_spam);
         for ($i = 0; $i < strlen($answers) - 1; $i += 2) {
             $answers_unhex .= chr(hexdec($answers[$i] . $answers[$i + 1]));
         }
         // Create an array of the accepted answers.
         $answer_array = explode(',', $answers_unhex);
         // Check $_POST to see if one of the accepted answers was submitted.
         if (!in_array(strtolower(rgpost("input_{$field['id']}")), $answer_array)) {
             $validation_result['is_valid'] = false;
             $field['failed_validation'] = true;
             $field['validation_message'] = __("Sorry, that wasn't the correct answer. Please try again.", $this->plugin_slug);
             break;
         }
     }
     // Assign modified $form object back to the validation result.
     $validation_result['form'] = $form;
     return $validation_result;
 }
 private function validate(&$form, $field_values)
 {
     $form = apply_filters('gform_pre_validation', $form);
     foreach ($form["fields"] as &$field) {
         /*
          * Skip over the following fields as we aren't processing any of them
          */
         $skip_field = false;
         switch (RGFormsModel::get_input_type($field)) {
             case "captcha":
             case "html":
             case "password":
             case "product":
             case "coupon":
             case "quantity":
             case "shipping":
             case "donation":
             case "total":
             case "singleproduct":
             case "hiddenproduct":
             case "singleshipping":
             case "creditcard":
             case "page":
             case "post_image":
             case "fileupload":
                 //ignore certain fields
                 $skip_field = true;
                 break;
         }
         if (isset($field['productField']) && (int) $field['productField'] > 0 || $field['type'] == 'shipping') {
             $skip_field = true;
         }
         /* ignore validation if field is hidden or admin only */
         if (RGFormsModel::is_field_hidden($form, $field, $field_values) || isset($field['adminOnly']) && $field['adminOnly']) {
             $skip_field = true;
         }
         /* ignore user-defined restricted fields or hidden fields */
         if (in_array($field['id'], $this->atts['restricted_fields']) || in_array($field['id'], $this->atts['hidden_fields'])) {
             $skip_field = true;
         }
         if ($skip_field) {
             continue;
         }
         $value = RGFormsModel::get_field_value($field);
         //display error message if field is marked as required and the submitted value is empty
         if ($field["isRequired"] && GFFormDisplay::is_empty($field, $form["id"])) {
             $field["failed_validation"] = true;
             $field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
         } else {
             if ($field["noDuplicates"] && RGFormsModel::is_duplicate($form["id"], $field, $value)) {
                 $field["failed_validation"] = true;
                 $input_type = RGFormsModel::get_input_type($field);
                 switch ($input_type) {
                     case "date":
                         $default_message = __("This date has already been taken. Please select a new date.", "gravityforms");
                         break;
                     default:
                         $default_message = is_array($value) ? __("This field requires a unique entry and the values you entered have been already been used.", "gravityforms") : sprintf(__("This field requires a unique entry and '%s' has already been used", "gravityforms"), $value);
                         break;
                 }
                 $field["validation_message"] = apply_filters("gform_duplicate_message_{$form["id"]}", apply_filters("gform_duplicate_message", $default_message, $form, $field, $value), $form, $field, $value);
             } else {
                 if (GFFormDisplay::failed_state_validation($form["id"], $field, $value)) {
                     $field["failed_validation"] = true;
                     $field["validation_message"] = in_array($field["inputType"], array("singleproduct", "singleshipping", "hiddenproduct")) ? __("Please enter a valid value.", "gravityforms") : __("Invalid selection. Please select one of the available choices.", "gravityforms");
                 } else {
                     switch (RGFormsModel::get_input_type($field)) {
                         case "name":
                             if ($field["isRequired"] && $field["nameFormat"] != "simple") {
                                 $first = $_POST["input_" . $field["id"] . "_3"];
                                 $last = $_POST["input_" . $field["id"] . "_6"];
                                 if (empty($first) || empty($last)) {
                                     $field["failed_validation"] = true;
                                     $field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter the first and last name.", "gravityforms") : $field["errorMessage"];
                                 }
                             }
                             break;
                         case "address":
                             if ($field["isRequired"]) {
                                 $street = $_POST["input_" . $field["id"] . "_1"];
                                 $city = $_POST["input_" . $field["id"] . "_3"];
                                 $state = $_POST["input_" . $field["id"] . "_4"];
                                 $zip = $_POST["input_" . $field["id"] . "_5"];
                                 $country = $_POST["input_" . $field["id"] . "_6"];
                                 if (empty($street) || empty($city) || empty($zip) || empty($state) && !$field["hideState"] || empty($country) && !$field["hideCountry"]) {
                                     $field["failed_validation"] = true;
                                     $field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter a complete address.", "gravityforms") : $field["errorMessage"];
                                 }
                             }
                             break;
                         case "email":
                             if (!rgblank($value) && !GFCommon::is_valid_email($value)) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid email address.", "gravityforms") : $field["errorMessage"];
                             } else {
                                 if (rgget("emailConfirmEnabled", $field) && !empty($value)) {
                                     $confirm = rgpost("input_" . $field["id"] . "_2");
                                     if ($confirm != $value) {
                                         $field["failed_validation"] = true;
                                         $field["validation_message"] = __("Your emails do not match.", "gravityforms");
                                     }
                                 }
                             }
                             break;
                         case "price":
                             if (!class_exists("RGCurrency")) {
                                 require_once "currency.php";
                             }
                             $donation = GFCommon::to_number($value);
                             if (!rgblank($value) && ($donation === false || $donation < 0)) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid amount.", "gravityforms") : $field["errorMessage"];
                             }
                             break;
                         case "number":
                             // the POST value has already been converted from currency or decimal_comma to decimal_dot and then cleaned in get_field_value()
                             $value = GFCommon::maybe_add_leading_zero($value);
                             $raw_value = $_POST["input_" . $field["id"]];
                             //Raw value will be tested against the is_numeric() function to make sure it is in the right format.
                             $requires_valid_number = !rgblank($raw_value) && !GFCommon::has_field_calculation($field);
                             $is_valid_number = self::validate_range($field, $value) && GFCommon::is_numeric($raw_value, $field["numberFormat"]);
                             if ($requires_valid_number && !$is_valid_number) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? GFCommon::get_range_message($field) : $field["errorMessage"];
                             } else {
                                 if ($field['type'] == 'quantity') {
                                     if (intval($value) != $value) {
                                         $field['failed_validation'] = true;
                                         $field['validation_message'] = empty($field['errorMessage']) ? __('Please enter a valid quantity. Quantity cannot contain decimals.', 'gravityforms') : $field['errorMessage'];
                                     } else {
                                         if (!empty($value) && (!is_numeric($value) || intval($value) != floatval($value) || intval($value) < 0)) {
                                             $field['failed_validation'] = true;
                                             $field['validation_message'] = empty($field['errorMessage']) ? __('Please enter a valid quantity', 'gravityforms') : $field['errorMessage'];
                                         }
                                     }
                                 }
                             }
                             break;
                         case "phone":
                             $regex = '/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/';
                             if ($field["phoneFormat"] == "standard" && $value !== "" && $value !== 0 && !preg_match($regex, $value)) {
                                 $field["failed_validation"] = true;
                                 if (!empty($field["errorMessage"])) {
                                     $field["validation_message"] = $field["errorMessage"];
                                 }
                             }
                             break;
                         case "date":
                             if (is_array($value) && rgempty(0, $value) && rgempty(1, $value) && rgempty(2, $value)) {
                                 $value = null;
                             }
                             if (!empty($value)) {
                                 $format = empty($field["dateFormat"]) ? "mdy" : $field["dateFormat"];
                                 $date = GFCommon::parse_date($value, $format);
                                 if (empty($date) || !GFFormDisplay::checkdate($date["month"], $date["day"], $date["year"])) {
                                     $field["failed_validation"] = true;
                                     $format_name = "";
                                     switch ($format) {
                                         case "mdy":
                                             $format_name = "mm/dd/yyyy";
                                             break;
                                         case "dmy":
                                             $format_name = "dd/mm/yyyy";
                                             break;
                                         case "dmy_dash":
                                             $format_name = "dd-mm-yyyy";
                                             break;
                                         case "dmy_dot":
                                             $format_name = "dd.mm.yyyy";
                                             break;
                                         case "ymd_slash":
                                             $format_name = "yyyy/mm/dd";
                                             break;
                                         case "ymd_dash":
                                             $format_name = "yyyy-mm-dd";
                                             break;
                                         case "ymd_dot":
                                             $format_name = "yyyy.mm.dd";
                                             break;
                                     }
                                     $message = $field["dateType"] == "datepicker" ? sprintf(__("Please enter a valid date in the format (%s).", "gravityforms"), $format_name) : __("Please enter a valid date.", "gravityforms");
                                     $field["validation_message"] = empty($field["errorMessage"]) ? $message : $field["errorMessage"];
                                 }
                             }
                             break;
                         case "time":
                             //create variable values if time came in one field
                             if (!is_array($value) && !empty($value)) {
                                 preg_match('/^(\\d*):(\\d*) ?(.*)$/', $value, $matches);
                                 $value = array();
                                 $value[0] = $matches[1];
                                 $value[1] = $matches[2];
                             }
                             $hour = $value[0];
                             $minute = $value[1];
                             if (empty($hour) && empty($minute)) {
                                 break;
                             }
                             $is_valid_format = is_numeric($hour) && is_numeric($minute);
                             $min_hour = rgar($field, "timeFormat") == "24" ? 0 : 1;
                             $max_hour = rgar($field, "timeFormat") == "24" ? 23 : 12;
                             if (!$is_valid_format || $hour < $min_hour || $hour > $max_hour || $minute < 0 || $minute >= 60) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid time.", "gravityforms") : $field["errorMessage"];
                             }
                             break;
                         case "website":
                             if (empty($value) || $value == "http://") {
                                 $value = "";
                                 if ($field["isRequired"]) {
                                     $field["failed_validation"] = true;
                                     $field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
                                 }
                             }
                             if (!empty($value) && !GFCommon::is_valid_url($value)) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid Website URL (i.e. http://www.gravityforms.com).", "gravityforms") : $field["errorMessage"];
                             }
                             break;
                         case "calculation":
                             $quantity_id = $field["id"] . ".3";
                             $quantity = rgget($quantity_id, $value);
                             if ($field["isRequired"] && rgblank($quantity) && !rgar($field, "disableQuantity")) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = rgempty("errorMessage", $field) ? __("This field is required.", "gravityforms") : rgar($field, "errorMessage");
                             } else {
                                 if (!empty($quantity) && (!is_numeric($quantity) || intval($quantity) != floatval($quantity) || intval($quantity) < 0)) {
                                     $field["failed_validation"] = true;
                                     $field["validation_message"] = __("Please enter a valid quantity", "gravityforms");
                                 }
                             }
                             break;
                         case "radio":
                             if (rgar($field, 'enableOtherChoice') && $value == 'gf_other_choice') {
                                 $value = rgpost("input_{$field['id']}_other");
                             }
                             if ($field["isRequired"] && rgar($field, 'enableOtherChoice') && $value == GFCommon::get_other_choice_value()) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
                             }
                             break;
                     }
                 }
             }
         }
         $custom_validation_result = apply_filters("gform_field_validation", array("is_valid" => rgar($field, "failed_validation") ? false : true, "message" => rgar($field, "validation_message")), $value, $form, $field);
         $custom_validation_result = apply_filters("gform_field_validation_{$form["id"]}", $custom_validation_result, $value, $form, $field);
         $custom_validation_result = apply_filters("gform_field_validation_{$form["id"]}_{$field["id"]}", $custom_validation_result, $value, $form, $field);
         $field["failed_validation"] = rgar($custom_validation_result, "is_valid") ? false : true;
         $field["validation_message"] = rgar($custom_validation_result, "message");
     }
     $is_valid = true;
     foreach ($form["fields"] as $f) {
         if (rgar($f, "failed_validation")) {
             $is_valid = false;
             break;
         }
     }
     $validation_result = apply_filters("gform_validation_{$form["id"]}", apply_filters("gform_validation", array("is_valid" => $is_valid, "form" => $form)));
     $is_valid = $validation_result["is_valid"];
     $form = $validation_result["form"];
     return $is_valid;
 }
Beispiel #16
0
 public static function user_registration_validation($validation_result)
 {
     $form = $validation_result['form'];
     $config = self::get_config($form['id']);
     $pagenum = RGForms::post('gform_source_page_number_' . $form['id']);
     $entry = self::convert_post_to_entry();
     // if there is no registration feed or the registration condition is not met or feed is inactive, abandon ship
     if (!$config || !self::registration_condition_met($form, $config, $entry) || !$config['is_active']) {
         return $validation_result;
     }
     $entry = self::convert_post_to_entry();
     $username_field = RGFormsModel::get_field($form, $config['meta']['username']);
     $useremail_field = RGFormsModel::get_field($form, $config['meta']['email']);
     $username_hidden = RGFormsModel::is_field_hidden($form, $username_field, array());
     $useremail_hidden = RGFormsModel::is_field_hidden($form, $useremail_field, array());
     $user_name = apply_filters("gform_username_{$form['id']}", apply_filters('gform_username', self::get_meta_value('username', $config, $form, $entry), $config, $form, $entry), $config, $form, $entry);
     $user_email = self::get_prepared_value($useremail_field, $config['meta']['email'], $entry);
     $user_pass = RGForms::post('input_' . $config['meta']['password']);
     if (!function_exists('username_exists')) {
         require_once ABSPATH . WPINC . "/registration.php";
     }
     $username_exists = username_exists($user_name);
     // check sanitized username
     $email_exists = email_exists($user_email);
     // if multisite is defined and true, lowercase name for validation
     if (is_multisite()) {
         $user_name = strtolower($user_name);
         $_POST['input_' . str_replace('.', '_', $config['meta']['username'])] = $user_name;
     }
     // if user name is not hidden and is on the current page we are validating, validate it
     if (!$username_hidden && $username_field['pageNumber'] == $pagenum) {
         if ($username_exists) {
             $form = self::add_validation_failure($config['meta']['username'], $form, __('This username is already registered', 'gravityformsuserregistration'));
         }
         if (!validate_username($user_name)) {
             $form = self::add_validation_failure($config['meta']['username'], $form, __('The username can only contain alphanumeric characters (A-Z, 0-9), underscores, dashes and spaces', 'gravityformsuserregistration'));
         }
         if (self::is_bp_active() && strpos($user_name, " ") !== false) {
             $form = self::add_validation_failure($config['meta']['username'], $form, __('The username can only contain alphanumeric characters (A-Z, 0-9), underscores and dashes', 'gravityformsuserregistration'));
         }
         if (!$user_name) {
             $form = self::add_validation_failure($config['meta']['username'], $form, __('The username can not be empty', 'gravityformsuserregistration'));
         }
     }
     // if user email is not hidden and is on the current page we are validating, validate it
     if (!$useremail_hidden && $useremail_field['pageNumber'] == $pagenum) {
         if ($email_exists) {
             $form = self::add_validation_failure($config['meta']['email'], $form, __('This email address is already registered', 'gravityformsuserregistration'));
         }
         if (!$user_email) {
             $form = self::add_validation_failure($config['meta']['email'], $form, __('The email address can not be empty', 'gravityformsuserregistration'));
         }
     }
     if (strpos($user_pass, "\\") !== false) {
         $form = self::add_validation_failure($config['meta']['password'], $form, __('Passwords may not contain the character "\\"', 'gravityformsuserregistration'));
     }
     $form = apply_filters('gform_user_registration_validation', $form, $config, $pagenum);
     $validation_result["is_valid"] = self::is_form_valid($form);
     $validation_result["form"] = $form;
     return $validation_result;
 }
 public static function get_submitted_fields($form, $lead, $display_empty = false, $use_text = false, $format = "html", $use_admin_label = false, $merge_tag = "", $options = "")
 {
     $field_data = "";
     if ($format == "html") {
         $field_data = '<table width="99%" border="0" cellpadding="1" cellpsacing="0" bgcolor="#EAEAEA"><tr><td>
                         <table width="100%" border="0" cellpadding="5" cellpsacing="0" bgcolor="#FFFFFF">';
     }
     $options_array = explode(",", $options);
     $no_admin = in_array("noadmin", $options_array);
     $no_hidden = in_array("nohidden", $options_array);
     $has_product_fields = false;
     foreach ($form["fields"] as $field) {
         $field_label = $use_admin_label && !rgempty("adminLabel", $field) ? rgar($field, "adminLabel") : esc_html(GFCommon::get_label($field));
         switch ($field["type"]) {
             case "captcha":
                 break;
             case "section":
                 if (!GFCommon::is_section_empty($field, $form, $lead) || $display_empty) {
                     switch ($format) {
                         case "text":
                             $field_data .= "--------------------------------\n{$field_label}\n\n";
                             break;
                         default:
                             $field_data .= sprintf('<tr>
                                                         <td colspan="2" style="font-size:14px; font-weight:bold; background-color:#EEE; border-bottom:1px solid #DFDFDF; padding:7px 7px">%s</td>
                                                    </tr>', $field_label);
                             break;
                     }
                 }
                 break;
             case "password":
                 //ignore password fields
                 break;
             default:
                 //ignore product fields as they will be grouped together at the end of the grid
                 if (self::is_product_field($field["type"])) {
                     $has_product_fields = true;
                     continue;
                 } else {
                     if (RGFormsModel::is_field_hidden($form, $field, array(), $lead)) {
                         //ignore fields hidden by conditional logic
                         continue;
                     }
                 }
                 $field_value = RGFormsModel::get_lead_field_value($lead, $field);
                 $field_value = GFCommon::get_lead_field_display($field, $field_value, $lead["currency"], $use_text, $format, "email");
                 $display_field = true;
                 //depending on parameters, don't display adminOnly or hidden fields
                 if ($no_admin && rgar($field, "adminOnly")) {
                     $display_field = false;
                 } else {
                     if ($no_hidden && RGFormsModel::get_input_type($field) == "hidden") {
                         $display_field = false;
                     }
                 }
                 //if field is not supposed to be displayed, pass false to filter. otherwise, pass field's value
                 if (!$display_field) {
                     $field_value = false;
                 }
                 $field_value = apply_filters("gform_merge_tag_filter", $field_value, $merge_tag, $options, $field);
                 if ($field_value === false) {
                     continue;
                 }
                 if (!empty($field_value) || strlen($field_value) > 0 || $display_empty) {
                     switch ($format) {
                         case "text":
                             $field_data .= "{$field_label}: {$field_value}\n\n";
                             break;
                         default:
                             $field_data .= sprintf('<tr bgcolor="#EAF2FA">
                                                         <td colspan="2">
                                                             <font style="font-family: sans-serif; font-size:12px;"><strong>%s</strong></font>
                                                         </td>
                                                    </tr>
                                                    <tr bgcolor="#FFFFFF">
                                                         <td width="20">&nbsp;</td>
                                                         <td>
                                                             <font style="font-family: sans-serif; font-size:12px;">%s</font>
                                                         </td>
                                                    </tr>', $field_label, empty($field_value) && strlen($field_value) == 0 ? "&nbsp;" : $field_value);
                             break;
                     }
                 }
         }
     }
     if ($has_product_fields) {
         $field_data .= self::get_submitted_pricing_fields($form, $lead, $format, $use_text, $use_admin_label);
     }
     if ($format == "html") {
         $field_data .= '</table>
                     </td>
                </tr>
            </table>';
     }
     return $field_data;
 }
Beispiel #18
0
 public function validation($validation_result)
 {
     $form = $validation_result['form'];
     $survey_fields = GFCommon::get_fields_by_type($form, array('survey'));
     if (empty($survey_fields)) {
         return $validation_result;
     }
     foreach ($form['fields'] as &$field) {
         $input_type = GFFormsModel::get_input_type($field);
         if ('likert' == $input_type && rgar($field, 'gsurveyLikertEnableMultipleRows') && rgar($field, 'isRequired')) {
             $is_hidden = RGFormsModel::is_field_hidden($form, $field, array());
             $field_page = $field['pageNumber'];
             $current_page = rgpost('gform_source_page_number_' . $form['id']) ? rgpost('gform_source_page_number_' . $form['id']) : 1;
             if ($field_page != $current_page || $is_hidden) {
                 continue;
             }
             // loop through responses to make sure all rows have values
             $incomplete = false;
             $rows = rgar($field, 'gsurveyLikertRows');
             $i = 1;
             foreach ($rows as $row) {
                 if ($i % 10 == 0) {
                     $i++;
                     // skip numbers ending in 0. so that 5.1 doesn't conflict with 5.10
                 }
                 $field_id = $field['id'] . '_' . (string) (int) $i++;
                 $field_value = rgpost("input_{$field_id}");
                 if (empty($field_value)) {
                     $incomplete = true;
                     break;
                 }
             }
             if ($incomplete) {
                 $field['failed_validation'] = true;
                 $field['validation_message'] = rgar($field, 'errorMessage') ? rgar($field, 'errorMessage') : __('This field is required');
                 $validation_result['is_valid'] = false;
             }
             continue;
         }
     }
     //Assign modified $form object back to the validation result
     $validation_result['form'] = $form;
     return $validation_result;
 }
Beispiel #19
0
 public static function create_lead_object($form)
 {
     $lead = array();
     $lead['id'] = -1;
     $lead['form_id'] = $form['id'];
     foreach ($form["fields"] as $field) {
         //Ignore fields that are marked as display only
         if (gwget('displayOnly', $field) && $field['type'] != 'password') {
             continue;
         }
         //only save fields that are not hidden (except on entry screen)
         if (!RGFormsModel::is_field_hidden($form, $field, array())) {
             if (isset($field['inputs']) && is_array($field['inputs'])) {
                 foreach ($field['inputs'] as $input) {
                     $lead[(string) $input['id']] = self::get_input_value($form, $field, $lead, $input['id']);
                 }
             } else {
                 $lead[$field['id']] = self::get_input_value($form, $field, $lead, $field['id']);
             }
         }
     }
     return $lead;
 }
 private static function has_visible_products($form)
 {
     foreach ($form["fields"] as $field) {
         if ($field["type"] == "product" && !RGFormsModel::is_field_hidden($form, $field, "")) {
             return true;
         }
     }
     return false;
 }
 /**
  * Prepare the value before saving it to the lead.
  *
  * @param mixed $form
  * @param mixed $field
  * @param mixed $value
  * @param mixed $input_name
  * @param mixed $lead_id the current lead ID, used for fields that are processed after other fields have been saved (ie Total, Calculations)
  * @param mixed $lead passed by the RGFormsModel::create_lead() method, lead ID is not available for leads created by this function
  */
 public static function prepare_value($form, $field, $value, $input_name, $lead_id, $lead = array())
 {
     $form_id = $form["id"];
     $input_type = self::get_input_type($field);
     switch ($input_type) {
         case "total":
             $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
             $value = GFCommon::get_order_total($form, $lead);
             break;
         case "calculation":
             // ignore submitted value and recalculate price in backend
             list(, , $input_id) = rgexplode("_", $input_name, 3);
             if ($input_id == 2) {
                 require_once GFCommon::get_base_path() . '/currency.php';
                 $currency = new RGCurrency(GFCommon::get_currency());
                 $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
                 $value = $currency->to_money(GFCommon::calculate($field, $form, $lead));
             }
             break;
         case "phone":
             if ($field["phoneFormat"] == "standard" && preg_match('/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/', $value, $matches)) {
                 $value = sprintf("(%s)%s-%s", $matches[1], $matches[2], $matches[3]);
             }
             break;
         case "time":
             if (!is_array($value) && !empty($value)) {
                 preg_match('/^(\\d*):(\\d*) ?(.*)$/', $value, $matches);
                 $value = array();
                 $value[0] = $matches[1];
                 $value[1] = $matches[2];
                 $value[2] = rgar($matches, 3);
             }
             $hour = empty($value[0]) ? "0" : strip_tags($value[0]);
             $minute = empty($value[1]) ? "0" : strip_tags($value[1]);
             $ampm = strip_tags(rgar($value, 2));
             if (!empty($ampm)) {
                 $ampm = " {$ampm}";
             }
             if (!(empty($hour) && empty($minute))) {
                 $value = sprintf("%02d:%02d%s", $hour, $minute, $ampm);
             } else {
                 $value = "";
             }
             break;
         case "date":
             $value = self::prepare_date($field["dateFormat"], $value);
             break;
         case "post_image":
             $url = self::get_fileupload_value($form_id, $input_name);
             $image_title = isset($_POST["{$input_name}_1"]) ? strip_tags($_POST["{$input_name}_1"]) : "";
             $image_caption = isset($_POST["{$input_name}_4"]) ? strip_tags($_POST["{$input_name}_4"]) : "";
             $image_description = isset($_POST["{$input_name}_7"]) ? strip_tags($_POST["{$input_name}_7"]) : "";
             $value = !empty($url) ? $url . "|:|" . $image_title . "|:|" . $image_caption . "|:|" . $image_description : "";
             break;
         case "fileupload":
             $value = self::get_fileupload_value($form_id, $input_name);
             break;
         case "number":
             $is_hidden = RGFormsModel::is_field_hidden($form, $field, array());
             $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
             $value = GFCommon::has_field_calculation($field) ? GFCommon::round_number(GFCommon::calculate($field, $form, $lead), rgar($field, "calculationRounding")) : GFCommon::clean_number($value, rgar($field, "numberFormat"));
             //return the value as a string when it is zero and a calc so that the "==" comparison done when checking if the field has changed isn't treated as false
             if (GFCommon::has_field_calculation($field) && $value == 0) {
                 $value = "0";
             }
             break;
         case "website":
             if ($value == "http://") {
                 $value = "";
             }
             break;
         case "list":
             if (GFCommon::is_empty_array($value)) {
                 $value = "";
             } else {
                 $value = self::create_list_array($field, $value);
                 $value = serialize($value);
             }
             break;
         case "radio":
             if (rgar($field, 'enableOtherChoice') && $value == 'gf_other_choice') {
                 $value = rgpost("input_{$field['id']}_other");
             }
             break;
         case "multiselect":
             $value = empty($value) ? "" : implode(",", $value);
             break;
         case "creditcard":
             //saving last 4 digits of credit card
             list($input_token, $field_id_token, $input_id) = rgexplode("_", $input_name, 3);
             if ($input_id == "1") {
                 $value = str_replace(" ", "", $value);
                 $card_number_length = strlen($value);
                 $value = substr($value, -4, 4);
                 $value = str_pad($value, $card_number_length, "X", STR_PAD_LEFT);
             } else {
                 if ($input_id == "4") {
                     $card_number = rgpost("input_{$field_id_token}_1");
                     $card_type = GFCommon::get_card_type($card_number);
                     $value = $card_type ? $card_type["name"] : "";
                 } else {
                     $value = "";
                 }
             }
             break;
         default:
             //allow HTML for certain field types
             $allow_html = in_array($field["type"], array("post_custom_field", "post_title", "post_content", "post_excerpt", "post_tags")) || in_array($input_type, array("checkbox", "radio")) ? true : false;
             $allowable_tags = apply_filters("gform_allowable_tags_{$form_id}", apply_filters("gform_allowable_tags", $allow_html, $field, $form_id), $field, $form_id);
             if ($allowable_tags !== true) {
                 $value = strip_tags($value, $allowable_tags);
             }
             break;
     }
     // special format for Post Category fields
     if ($field['type'] == 'post_category') {
         $full_values = array();
         if (!is_array($value)) {
             $value = explode(',', $value);
         }
         foreach ($value as $cat_id) {
             $cat = get_term($cat_id, 'category');
             $full_values[] = !is_wp_error($cat) && is_object($cat) ? $cat->name . ":" . $cat_id : "";
         }
         $value = implode(',', $full_values);
     }
     //do not save price fields with blank price
     if (rgar($field, "enablePrice")) {
         $ary = explode("|", $value);
         $label = count($ary) > 0 ? $ary[0] : "";
         $price = count($ary) > 1 ? $ary[1] : "";
         $is_empty = strlen(trim($price)) <= 0;
         if ($is_empty) {
             $value = "";
         }
     }
     return $value;
 }
Beispiel #22
0
 public static function validate(&$form, $field_values, $page_number = 0, &$failed_validation_page = 0)
 {
     $form = gf_apply_filters(array('gform_pre_validation', $form['id']), $form);
     // validate form schedule
     if (self::validate_form_schedule($form)) {
         return false;
     }
     // validate entry limit
     if (self::validate_entry_limit($form)) {
         return false;
     }
     // Prevent tampering with the submitted form
     if (empty($_POST['is_submit_' . $form['id']])) {
         return false;
     }
     $is_valid = true;
     foreach ($form['fields'] as &$field) {
         /* @var GF_Field $field */
         //If a page number is specified, only validates fields that are on current page
         $field_in_other_page = $page_number > 0 && $field->pageNumber != $page_number;
         //validate fields with 'no duplicate' functionality when they are present on pages before the current page.
         $validate_duplicate_feature = $field->noDuplicates && $page_number > 0 && $field->pageNumber <= $page_number;
         if ($field_in_other_page && !$validate_duplicate_feature) {
             continue;
         }
         // don't validate adminOnly fields.
         if ($field->adminOnly) {
             continue;
         }
         //ignore validation if field is hidden
         if (RGFormsModel::is_field_hidden($form, $field, $field_values)) {
             $field->is_field_hidden = true;
             continue;
         }
         $value = RGFormsModel::get_field_value($field);
         $input_type = RGFormsModel::get_input_type($field);
         //display error message if field is marked as required and the submitted value is empty
         if ($field->isRequired && self::is_empty($field, $form['id'])) {
             $field->failed_validation = true;
             $field->validation_message = empty($field->errorMessage) ? __('This field is required.', 'gravityforms') : $field->errorMessage;
         } else {
             if ($field->noDuplicates && RGFormsModel::is_duplicate($form['id'], $field, $value)) {
                 $field->failed_validation = true;
                 //set page number so the failed field displays if on multi-page form
                 $failed_validation_page = $field->pageNumber;
                 switch ($input_type) {
                     case 'date':
                         $default_message = __('This date has already been taken. Please select a new date.', 'gravityforms');
                         break;
                     default:
                         $default_message = is_array($value) ? __('This field requires a unique entry and the values you entered have been already been used.', 'gravityforms') : sprintf(__("This field requires a unique entry and '%s' has already been used", 'gravityforms'), $value);
                         break;
                 }
                 $field->validation_message = gf_apply_filters(array('gform_duplicate_message', $form['id']), $default_message, $form, $field, $value);
             } else {
                 if (self::failed_state_validation($form['id'], $field, $value)) {
                     $field->failed_validation = true;
                     $field->validation_message = in_array($field->inputType, array('singleproduct', 'singleshipping', 'hiddenproduct')) ? __('Please enter a valid value.', 'gravityforms') : __('Invalid selection. Please select one of the available choices.', 'gravityforms');
                 } else {
                     $field->validate($value, $form);
                 }
             }
         }
         $custom_validation_result = gf_apply_filters(array('gform_field_validation', $form['id'], $field->id), array('is_valid' => $field->failed_validation ? false : true, 'message' => $field->validation_message), $value, $form, $field);
         $field->failed_validation = rgar($custom_validation_result, 'is_valid') ? false : true;
         $field->validation_message = rgar($custom_validation_result, 'message');
         if ($field->failed_validation) {
             $is_valid = false;
         }
     }
     $is_last_page = self::get_target_page($form, $page_number, $field_values) == '0';
     if ($is_valid && $is_last_page && self::is_form_empty($form)) {
         foreach ($form['fields'] as &$field) {
             $field->failed_validation = true;
             $field->validation_message = esc_html__('At least one field must be filled out', 'gravityforms');
             $is_valid = false;
             unset($field->is_field_hidden);
         }
     }
     $validation_result = gf_apply_filters(array('gform_validation', $form['id']), array('is_valid' => $is_valid, 'form' => $form, 'failed_validation_page' => $failed_validation_page));
     $is_valid = $validation_result['is_valid'];
     $form = $validation_result['form'];
     $failed_validation_page = $validation_result['failed_validation_page'];
     return $is_valid;
 }
 function should_field_be_validated($form, $field)
 {
     if ($field['pageNumber'] != GFFormDisplay::get_source_page($form['id'])) {
         return false;
     }
     // if no limits provided for this field
     if (!$this->get_field_limits($field['id'])) {
         return false;
     }
     // or if this field is not a checkbox
     if (RGFormsModel::get_input_type($field) != 'checkbox') {
         return false;
     }
     // or if this field is hidden
     if (RGFormsModel::is_field_hidden($form, $field, array())) {
         return false;
     }
     return true;
 }
 public static function create_lead($form)
 {
     global $current_user;
     $total_fields = array();
     $calculation_fields = array();
     $lead = array();
     $lead['id'] = null;
     $lead['post_id'] = null;
     $lead['date_created'] = null;
     $lead['form_id'] = $form['id'];
     $lead['ip'] = self::get_ip();
     $lead['source_url'] = self::truncate(self::get_current_page_url(), 200);
     $lead['user_agent'] = strlen($_SERVER['HTTP_USER_AGENT']) > 250 ? substr($_SERVER['HTTP_USER_AGENT'], 0, 250) : $_SERVER['HTTP_USER_AGENT'];
     $lead['currency'] = GFCommon::get_currency();
     $lead['created_by'] = $current_user && $current_user->ID ? $current_user->ID : 'NULL';
     foreach ($form['fields'] as $field) {
         /* @var $field GF_Field */
         // ignore fields that are marked as display only
         if ($field->displayOnly && $field->type != 'password') {
             continue;
         }
         // process total field after all fields have been saved
         if ($field->type == 'total') {
             $total_fields[] = $field;
             continue;
         }
         // process calculation fields after all fields have been saved
         if ($field->has_calculation()) {
             $calculation_fields[] = $field;
             continue;
         }
         // only save fields that are not hidden
         if (!RGFormsModel::is_field_hidden($form, $field, array())) {
             if ($field->type == 'post_category') {
                 $field = GFCommon::add_categories_as_choices($field, '');
             }
             $inputs = $field->get_entry_inputs();
             if (is_array($inputs)) {
                 foreach ($inputs as $input) {
                     $lead[(string) $input['id']] = self::get_prepared_input_value($form, $field, $lead, $input['id']);
                 }
             } else {
                 $lead[$field->id] = self::get_prepared_input_value($form, $field, $lead, $field->id);
             }
         }
     }
     if (!empty($calculation_fields)) {
         foreach ($calculation_fields as $field) {
             /* @var $field GF_Field */
             // only save fields that are not hidden
             if (RGFormsModel::is_field_hidden($form, $field, array())) {
                 continue;
             }
             $inputs = $field->get_entry_inputs();
             if (is_array($inputs)) {
                 foreach ($inputs as $input) {
                     $lead[(string) $input['id']] = self::get_prepared_input_value($form, $field, $lead, $input['id']);
                 }
             } else {
                 $lead[$field->id] = self::get_prepared_input_value($form, $field, $lead, $field->id);
             }
         }
         self::refresh_product_cache($form, $lead);
     }
     // saving total field as the last field of the form.
     if (!empty($total_fields)) {
         foreach ($total_fields as $total_field) {
             $lead[$total_field->id] = self::get_prepared_input_value($form, $total_field, $lead, $total_field->id);
         }
     }
     return $lead;
 }
Beispiel #25
0
 public static function has_paypal_condition($form, $config)
 {
     $config = $config["meta"];
     $operator = isset($config["paypal_conditional_operator"]) ? $config["paypal_conditional_operator"] : "";
     $field = RGFormsModel::get_field($form, $config["paypal_conditional_field_id"]);
     if (empty($field) || !$config["paypal_conditional_enabled"]) {
         return true;
     }
     // if conditional is enabled, but the field is hidden, ignore conditional
     $is_visible = !RGFormsModel::is_field_hidden($form, $field, array());
     $field_value = RGFormsModel::get_field_value($field, array());
     $is_value_match = RGFormsModel::is_value_match($field_value, $config["paypal_conditional_value"], $operator);
     $go_to_paypal = $is_value_match && $is_visible;
     return $go_to_paypal;
 }
Beispiel #26
0
 public static function save_lead($form, &$lead)
 {
     global $wpdb;
     if (IS_ADMIN && !GFCommon::current_user_can_any("gravityforms_edit_entries")) {
         die(__("You don't have adequate permission to edit entries.", "gravityforms"));
     }
     $lead_detail_table = self::get_lead_details_table_name();
     //Inserting lead if null
     if ($lead == null) {
         global $current_user;
         $user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL';
         $lead_table = RGFormsModel::get_lead_table_name();
         $user_agent = strlen($_SERVER["HTTP_USER_AGENT"]) > 250 ? substr($_SERVER["HTTP_USER_AGENT"], 0, 250) : $_SERVER["HTTP_USER_AGENT"];
         $currency = GFCommon::get_currency();
         $wpdb->query($wpdb->prepare("INSERT INTO {$lead_table}(form_id, ip, source_url, date_created, user_agent, currency, created_by) VALUES(%d, %s, %s, utc_timestamp(), %s, %s, {$user_id})", $form["id"], self::get_ip(), self::get_current_page_url(), $user_agent, $currency));
         //reading newly created lead id
         $lead_id = $wpdb->insert_id;
         $lead = array("id" => $lead_id);
     }
     $current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $lead["id"]));
     $original_post_id = $lead["post_id"];
     foreach ($form["fields"] as $field) {
         //Ignore fields that are marked as display only
         if ($field["displayOnly"] && $field["type"] != "password") {
             continue;
         }
         //ignore pricing fields in the entry detail
         if (RG_CURRENT_VIEW == "entry" && GFCommon::is_pricing_field($field["type"])) {
             continue;
         }
         //only save fields that are not hidden (except on entry screen)
         if (RG_CURRENT_VIEW == "entry" || !RGFormsModel::is_field_hidden($form, $field, array())) {
             if (is_array($field["inputs"])) {
                 foreach ($field["inputs"] as $input) {
                     self::save_input($form, $field, $lead, $current_fields, $input["id"]);
                 }
             } else {
                 self::save_input($form, $field, $lead, $current_fields, $field["id"]);
             }
         }
     }
 }
 public static function get_field($field, $value = "", $force_frontend_label = false, $form = null, $field_values = null)
 {
     $custom_class = IS_ADMIN ? "" : rgget("cssClass", $field);
     if ($field["type"] == "page") {
         if (IS_ADMIN && RG_CURRENT_VIEW == "entry") {
             return;
             //ignore page breaks in the entry detail page
         } else {
             if (!IS_ADMIN) {
                 $next_button = self::get_form_button($form["id"], "gform_next_button_{$form["id"]}_{$field["id"]}", $field["nextButton"], __("Next", "gravityforms"), "button gform_next_button", __("Next Page", "gravityforms"), $field["pageNumber"]);
                 $previous_button = $field["pageNumber"] == 2 ? "" : self::get_form_button($form["id"], "gform_previous_button_{$form["id"]}_{$field["id"]}", $field["previousButton"], __("Previous", "gravityforms"), "button gform_previous_button", __("Previous Page", "gravityforms"), $field["pageNumber"] - 2);
                 $style = self::is_page_active($form["id"], $field["pageNumber"]) ? "" : "style='display:none;'";
                 $custom_class = !empty($custom_class) ? " {$custom_class}" : "";
                 $html = "</ul>\n                    </div>\n                    <div class='gform_page_footer'>\n                        {$previous_button} {$next_button}\n                    </div>\n                </div>\n                <div id='gform_page_{$form["id"]}_{$field["pageNumber"]}' class='gform_page{$custom_class}' {$style}>\n                    <div class='gform_page_fields'>\n                        <ul class='gform_fields {$form['labelPlacement']}'>";
                 return $html;
             }
         }
     }
     if ($field["type"] == "post_category") {
     }
     if (!IS_ADMIN && rgar($field, "adminOnly")) {
         if ($field["allowsPrepopulate"]) {
             $field["inputType"] = "adminonly_hidden";
         } else {
             return;
         }
     }
     $id = $field["id"];
     $type = $field["type"];
     $input_type = RGFormsModel::get_input_type($field);
     $error_class = rgget("failed_validation", $field) ? "gfield_error" : "";
     $admin_only_class = rgget("adminOnly", $field) ? "field_admin_only" : "";
     $selectable_class = IS_ADMIN ? "selectable" : "";
     $hidden_class = in_array($input_type, array("hidden", "hiddenproduct")) ? "gform_hidden" : "";
     $section_class = $field["type"] == "section" ? "gsection" : "";
     $page_class = $field["type"] == "page" ? "gpage" : "";
     $html_block_class = $field["type"] == "html" ? "gfield_html" : "";
     $html_formatted_class = $field["type"] == "html" && !IS_ADMIN && !rgget("disableMargins", $field) ? "gfield_html_formatted" : "";
     $html_no_follows_desc_class = $field["type"] == "html" && !IS_ADMIN && !self::prev_field_has_description($form, $field["id"]) ? "gfield_no_follows_desc" : "";
     $calculation_class = RGFormsModel::get_input_type($field) == 'number' && GFCommon::has_field_calculation($field) ? 'gfield_calculation' : '';
     $calculation_class = RGFormsModel::get_input_type($field) == 'calculation' ? 'gfield_calculation' : '';
     $product_suffix = "_{$form["id"]}_" . rgget("productField", $field);
     $option_class = $field["type"] == "option" ? "gfield_price gfield_price{$product_suffix} gfield_option{$product_suffix}" : "";
     $quantity_class = $field["type"] == "quantity" ? "gfield_price gfield_price{$product_suffix} gfield_quantity{$product_suffix}" : "";
     $shipping_class = $field["type"] == "shipping" ? "gfield_price gfield_shipping gfield_shipping_{$form["id"]}" : "";
     $product_class = $field["type"] == "product" ? "gfield_price gfield_price_{$form["id"]}_{$field["id"]} gfield_product_{$form["id"]}_{$field["id"]}" : "";
     $hidden_product_class = $input_type == "hiddenproduct" ? "gfield_hidden_product" : "";
     $donation_class = $field["type"] == "donation" ? "gfield_price gfield_price_{$form["id"]}_{$field["id"]} gfield_donation_{$form["id"]}_{$field["id"]}" : "";
     $required_class = rgar($field, "isRequired") ? "gfield_contains_required" : "";
     $creditcard_warning_class = $input_type == "creditcard" && !GFCommon::is_ssl() ? "gfield_creditcard_warning" : "";
     $css_class = "{$selectable_class} gfield {$error_class} {$section_class} {$admin_only_class} {$custom_class} {$hidden_class} {$html_block_class} {$html_formatted_class} {$html_no_follows_desc_class} {$option_class} {$quantity_class} {$product_class} {$donation_class} {$shipping_class} {$page_class} {$required_class} {$hidden_product_class} {$creditcard_warning_class} {$calculation_class}";
     $css_class = apply_filters("gform_field_css_class_{$form["id"]}", apply_filters("gform_field_css_class", trim($css_class), $field, $form), $field, $form);
     $style = !empty($form) && !IS_ADMIN && RGFormsModel::is_field_hidden($form, $field, $field_values) ? "style='display:none;'" : "";
     $field_id = IS_ADMIN || empty($form) ? "field_{$id}" : "field_" . $form["id"] . "_{$id}";
     return "<li id='{$field_id}' class='{$css_class}' {$style}>" . self::get_field_content($field, $value, $force_frontend_label, $form == null ? 0 : $form["id"]) . "</li>";
 }
 public static function get_product_fields($form, $lead, $use_choice_text = false, $use_admin_label = false)
 {
     $products = array();
     $product_info = null;
     // retrieve static copy of product info (only for 'real' entries)
     if (!rgempty('id', $lead)) {
         $product_info = gform_get_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}");
     }
     // if no static copy, generate from form/lead info
     if (!$product_info) {
         foreach ($form['fields'] as $field) {
             $id = $field->id;
             $lead_value = RGFormsModel::get_lead_field_value($lead, $field);
             $quantity_field = self::get_product_fields_by_type($form, array('quantity'), $id);
             $quantity = sizeof($quantity_field) > 0 && !RGFormsModel::is_field_hidden($form, $quantity_field[0], array(), $lead) ? RGFormsModel::get_lead_field_value($lead, $quantity_field[0]) : 1;
             switch ($field->type) {
                 case 'product':
                     //ignore products that have been hidden by conditional logic
                     $is_hidden = RGFormsModel::is_field_hidden($form, $field, array(), $lead);
                     if ($is_hidden) {
                         continue;
                     }
                     //if single product, get values from the multiple inputs
                     if (is_array($lead_value)) {
                         $product_quantity = sizeof($quantity_field) == 0 && !$field->disableQuantity ? rgget($id . '.3', $lead_value) : $quantity;
                         if (empty($product_quantity)) {
                             continue;
                         }
                         if (!rgget($id, $products)) {
                             $products[$id] = array();
                         }
                         $products[$id]['name'] = $use_admin_label && !rgempty('adminLabel', $field) ? $field->adminLabel : $lead_value[$id . '.1'];
                         $products[$id]['price'] = rgar($lead_value, $id . '.2');
                         $products[$id]['quantity'] = $product_quantity;
                     } elseif (!empty($lead_value)) {
                         if (empty($quantity)) {
                             continue;
                         }
                         if (!rgar($products, $id)) {
                             $products[$id] = array();
                         }
                         if ($field->inputType == 'price') {
                             $name = $field->label;
                             $price = $lead_value;
                         } else {
                             list($name, $price) = explode('|', $lead_value);
                         }
                         $products[$id]['name'] = !$use_choice_text ? $name : RGFormsModel::get_choice_text($field, $name);
                         $include_field_label = apply_filters('gform_product_info_name_include_field_label', false);
                         if ($field->inputType == ('radio' || 'select') && $include_field_label) {
                             $products[$id]['name'] = $field->label . " ({$products[$id]['name']})";
                         }
                         $products[$id]['price'] = $price;
                         $products[$id]['quantity'] = $quantity;
                         $products[$id]['options'] = array();
                     }
                     if (isset($products[$id])) {
                         $options = self::get_product_fields_by_type($form, array('option'), $id);
                         foreach ($options as $option) {
                             $option_value = RGFormsModel::get_lead_field_value($lead, $option);
                             $option_label = empty($option['adminLabel']) ? $option['label'] : $option['adminLabel'];
                             if (is_array($option_value)) {
                                 foreach ($option_value as $value) {
                                     $option_info = self::get_option_info($value, $option, $use_choice_text);
                                     if (!empty($option_info)) {
                                         $products[$id]['options'][] = array('field_label' => rgar($option, 'label'), 'option_name' => rgar($option_info, 'name'), 'option_label' => $option_label . ': ' . rgar($option_info, 'name'), 'price' => rgar($option_info, 'price'));
                                     }
                                 }
                             } elseif (!empty($option_value)) {
                                 $option_info = self::get_option_info($option_value, $option, $use_choice_text);
                                 $products[$id]['options'][] = array('field_label' => rgar($option, 'label'), 'option_name' => rgar($option_info, 'name'), 'option_label' => $option_label . ': ' . rgar($option_info, 'name'), 'price' => rgar($option_info, 'price'));
                             }
                         }
                     }
                     break;
             }
         }
         $shipping_field = GFAPI::get_fields_by_type($form, array('shipping'));
         $shipping_price = $shipping_name = '';
         $shipping_field_id = '';
         if (!empty($shipping_field) && !RGFormsModel::is_field_hidden($form, $shipping_field[0], array(), $lead)) {
             $shipping_price = RGFormsModel::get_lead_field_value($lead, $shipping_field[0]);
             $shipping_name = $shipping_field[0]['label'];
             $shipping_field_id = $shipping_field[0]['id'];
             if ($shipping_field[0]['inputType'] != 'singleshipping') {
                 list($shipping_method, $shipping_price) = explode('|', $shipping_price);
                 $shipping_name = $shipping_field[0]['label'] . " ({$shipping_method})";
             }
         }
         $shipping_price = self::to_number($shipping_price);
         $product_info = array('products' => $products, 'shipping' => array('id' => $shipping_field_id, 'name' => $shipping_name, 'price' => $shipping_price));
         $product_info = gf_apply_filters('gform_product_info', $form['id'], $product_info, $form, $lead);
         // save static copy of product info (only for 'real' entries)
         if (!rgempty('id', $lead) && !empty($product_info['products'])) {
             gform_update_meta($lead['id'], "gform_product_info_{$use_choice_text}_{$use_admin_label}", $product_info);
         }
     }
     return $product_info;
 }
 /**
  * validate inputs
  * @param array $validation_result an array with elements is_valid (boolean) and form (array of form elements)
  * @param string $value
  * @param array $form
  * @param array $field
  * @return array
  */
 public function gformFieldValidation($validation_result, $value, $form, $field)
 {
     if ($field['type'] == GFEWAY_FIELD_RECURRING) {
         if (!RGFormsModel::is_field_hidden($form, $field, RGForms::post('gform_field_values'))) {
             // get the real values
             $value = self::getPost($field['id']);
             if (!is_array($value)) {
                 $validation_result['is_valid'] = false;
                 $validation_result['message'] = __("This field is required.", "gravityforms");
             } else {
                 $messages = array();
                 if ($value['amountInit'] === false || $value['amountInit'] < 0) {
                     $messages[] = 'Please enter a valid initial amount.';
                 }
                 if (empty($value['dateInit'])) {
                     $messages[] = 'Please enter a valid initial date in the format dd/mm/yyyy.';
                 }
                 if (empty($value['amountRecur']) || $value['amountRecur'] < 0) {
                     $messages[] = 'Please enter a valid recurring amount.';
                 }
                 if (empty($value['dateStart'])) {
                     $messages[] = 'Please enter a valid start date in the format dd/mm/yyyy.';
                 }
                 if (empty($value['dateEnd'])) {
                     $messages[] = 'Please enter a valid end date in the format dd/mm/yyyy.';
                 }
                 if ($value['intervalType'] === -1) {
                     $messages[] = 'Please select a valid interval type.';
                 }
                 if (count($messages) > 0) {
                     $validation_result['is_valid'] = false;
                     $validation_result['message'] = implode("<br />\n", $messages);
                 }
             }
         }
     }
     return $validation_result;
 }
Beispiel #30
0
 public static function get_field($field, $value = "", $force_frontend_label = false, $form = null, $field_values = null)
 {
     if (!IS_ADMIN && $field["adminOnly"]) {
         if ($field["allowsPrepopulate"]) {
             $field["type"] = "adminonly_hidden";
         } else {
             return;
         }
     }
     $id = $field["id"];
     $type = $field["type"];
     $error_class = $field["failed_validation"] ? "gfield_error" : "";
     $custom_class = $field["cssClass"];
     $admin_only_class = $field["adminOnly"] ? "field_admin_only" : "";
     $selectable_class = IS_ADMIN ? "selectable" : "";
     $section_class = $field["type"] == "section" ? "gsection" : "";
     $css_class = "{$selectable_class} gfield {$error_class} {$section_class} {$admin_only_class} {$custom_class}";
     $css_class = trim($css_class);
     $style = !empty($form) && !IS_ADMIN && RGFormsModel::is_field_hidden($form, $field, $field_values) ? "style='display:none;'" : "";
     $field_id = IS_ADMIN || empty($form) ? "field_{$id}" : "field_" . $form["id"] . "_{$id}";
     return "<li id='{$field_id}' class='{$css_class}' {$style}>" . self::get_field_content($field, $value, $force_frontend_label, $form == null ? 0 : $form["id"]) . "</li>";
 }