function validate($errors, $field) { if ($field->type == 'user_id') { // make sure we have a user ID if (!is_numeric($_POST['item_meta'][$field->id])) { $_POST['item_meta'][$field->id] = FrmProAppHelper::get_user_id_param($_POST['item_meta'][$field->id]); } //add user id to post variables to be saved with entry $_POST['frm_user_id'] = $_POST['item_meta'][$field->id]; } else { if ($field->type == 'time' and is_array($_POST['item_meta'][$field->id])) { $_POST['item_meta'][$field->id] = $value = $_POST['item_meta'][$field->id]['H'] . ':' . $_POST['item_meta'][$field->id]['m'] . (isset($_POST['item_meta'][$field->id]['A']) ? ' ' . $_POST['item_meta'][$field->id]['A'] : ''); } } // don't validate if going backwards if (FrmProFormsHelper::going_to_prev($field->form_id)) { return array(); } // clear any existing errors if draft if (FrmProFormsHelper::saving_draft($field->form_id) && isset($errors['field' . $field->id])) { unset($errors['field' . $field->id]); } //if the field is a file upload, check for a file if ($field->type == 'file' && isset($_FILES['file' . $field->id]) && !empty($_FILES['file' . $field->id]['name'])) { $filled = true; if (is_array($_FILES['file' . $field->id]['name'])) { $filled = false; foreach ($_FILES['file' . $field->id]['name'] as $n) { if (!empty($n)) { $filled = true; } } } if ($filled) { if (isset($errors['field' . $field->id])) { unset($errors['field' . $field->id]); } if (isset($field->field_options['restrict']) && $field->field_options['restrict'] && isset($field->field_options['ftypes']) && !empty($field->field_options['ftypes'])) { $mimes = $field->field_options['ftypes']; } else { $mimes = null; } //check allowed mime types for this field if (is_array($_FILES['file' . $field->id]['name'])) { foreach ($_FILES['file' . $field->id]['name'] as $name) { if (empty($name)) { continue; } $file_type = wp_check_filetype($name, $mimes); unset($name); if (!$file_type['ext']) { break; } } } else { $file_type = wp_check_filetype($_FILES['file' . $field->id]['name'], $mimes); } if (isset($file_type) && !$file_type['ext']) { $errors['field' . $field->id] = $field->field_options['invalid'] == __('This field is invalid', 'formidable') || $field->field_options['invalid'] == '' || $field->field_options['invalid'] == $field->name . ' ' . __('is invalid', 'formidable') ? __('Sorry, this file type is not permitted for security reasons.', 'formidable') : $field->field_options['invalid']; } unset($file_type); } unset($filled); } // if saving draft, only check file type since it won't be checked later if (FrmProFormsHelper::saving_draft($field->form_id)) { return $errors; } if (in_array($field->type, array('break', 'html', 'divider'))) { $hidden = FrmProFieldsHelper::is_field_hidden($field, stripslashes_deep($_POST)); global $frm_hidden_break, $frm_hidden_divider; if ($field->type == 'break') { $frm_hidden_break = array('field_order' => $field->field_order, 'hidden' => $hidden); } else { if ($field->type == 'divider') { $frm_hidden_divider = array('field_order' => $field->field_order, 'hidden' => $hidden); } } if (isset($errors['field' . $field->id])) { unset($errors['field' . $field->id]); } } $value = $_POST['item_meta'][$field->id]; if (($field->type != 'tag' and $value == 0 or $field->type == 'tag' and $value == '') and isset($field->field_options['post_field']) and $field->field_options['post_field'] == 'post_category' and $field->required == '1') { global $frm_settings; $errors['field' . $field->id] = (!isset($field->field_options['blank']) or $field->field_options['blank'] == '' or $field->field_options['blank'] == 'Untitled cannot be blank') ? $frm_settings->blank_msg : $field->field_options['blank']; } //Don't require fields hidden with shortcode fields="25,26,27" global $frm_vars; if (isset($frm_vars['show_fields']) and !empty($frm_vars['show_fields']) and is_array($frm_vars['show_fields']) and $field->required == '1' and isset($errors['field' . $field->id]) and !in_array($field->id, $frm_vars['show_fields']) and !in_array($field->field_key, $frm_vars['show_fields'])) { unset($errors['field' . $field->id]); $_POST['item_meta'][$field->id] = $value = ''; } //Don't require a conditionally hidden field if (isset($field->field_options['hide_field']) and !empty($field->field_options['hide_field'])) { if (FrmProFieldsHelper::is_field_hidden($field, stripslashes_deep($_POST))) { if (isset($errors['field' . $field->id])) { unset($errors['field' . $field->id]); } $_POST['item_meta'][$field->id] = $value = ''; } } //Don't require a field hidden in a conditional page or section heading if (isset($errors['field' . $field->id]) or $_POST['item_meta'][$field->id] != '') { global $frm_hidden_break, $frm_hidden_divider; if ($frm_hidden_break and $frm_hidden_break['hidden'] or $frm_hidden_divider and $frm_hidden_divider['hidden'] and (!$frm_hidden_break or $frm_hidden_break['field_order'] < $frm_hidden_divider['field_order'])) { if (isset($errors['field' . $field->id])) { unset($errors['field' . $field->id]); } $_POST['item_meta'][$field->id] = $value = ''; } } //make sure the [auto_id] is still unique if (!empty($field->default_value) and !is_array($field->default_value) and !empty($value) and is_numeric($value) and strpos($field->default_value, '[auto_id') !== false) { //make sure we are not editing if (isset($_POST) and !isset($_POST['id']) or !is_numeric($_POST['id'])) { $_POST['item_meta'][$field->id] = $value = FrmProFieldsHelper::get_default_value($field->default_value, $field); } } //check uniqueness if ($value and !empty($value) and isset($field->field_options['unique']) and $field->field_options['unique']) { $entry_id = (isset($_POST) and isset($_POST['id'])) ? $_POST['id'] : false; if ($field->type == 'time') { //TODO: add server-side validation for unique date-time } else { if ($field->type == 'date') { global $frmpro_settings; $old_value = $value; if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', trim($value))) { $value = FrmProAppHelper::convert_date($value, $frmpro_settings->date_format, 'Y-m-d'); } if (FrmProEntryMetaHelper::value_exists($field->id, $value, $entry_id)) { $errors['field' . $field->id] = FrmProFieldsHelper::get_error_msg($field, 'unique_msg'); } $value = $old_value; } else { if (FrmProEntryMetaHelper::value_exists($field->id, $value, $entry_id)) { $errors['field' . $field->id] = FrmProFieldsHelper::get_error_msg($field, 'unique_msg'); } } } unset($entry_id); } // validate number settings if ('number' == $field->type && $value != '') { global $frm_settings; // only check if options are available in settings if ($frm_settings->use_html && isset($field->field_options['minnum']) && isset($field->field_options['maxnum'])) { //minnum maxnum if ((double) $value < $field->field_options['minnum']) { $errors['field' . $field->id] = __('Please select a higher number', 'formidable'); } else { if ((double) $value > $field->field_options['maxnum']) { $errors['field' . $field->id] = __('Please select a lower number', 'formidable'); } } } } if (!empty($value) and ($field->type == 'website' or $field->type == 'url' or $field->type == 'image')) { if (trim($value) == 'http://') { $_POST['item_meta'][$field->id] = $value = ''; } else { $value = esc_url_raw($value); $_POST['item_meta'][$field->id] = $value = preg_match('/^(https?|ftps?|mailto|news|feed|telnet):/is', $value) ? $value : 'http://' . $value; } } $errors = FrmProEntryMetaHelper::set_post_fields($field, $value, $errors); if (!FrmProFieldsHelper::is_field_visible_to_user($field)) { //don't validate admin only fields that can't be seen unset($errors['field' . $field->id]); return $errors; } if (false and isset($field->field_options['use_calc']) and !empty($field->field_options['use_calc']) and !empty($field->field_options['calc'])) { $field->field_options['calc'] = trim($field->field_options['calc']); preg_match_all("/\\[(.*?)\\]/s", $field->field_options['calc'], $calc_matches, PREG_PATTERN_ORDER); if (isset($calc_matches[1])) { foreach ($calc_matches[1] as $c) { if (is_numeric($c)) { $c_id = $c; } else { global $frm_field; $c_field = $frm_field->getOne($c); if (!$c_field) { $field->field_options['calc'] = str_replace('[' . $c . ']', 0, $field->field_options['calc']); continue; } $c_id = $c_field->id; unset($c_field); } $c_val = trim($_POST['item_meta'][$c_id]); if (!is_numeric($c_val)) { preg_match_all('/[0-9,]*\\.?[0-9]+/', $c_val, $c_matches); $c_val = $c_matches ? end($c_matches[0]) : 0; unset($c_matches); } if ($c_val == '') { $c_val = 0; } $field->field_options['calc'] = str_replace('[' . $c . ']', $c_val, $field->field_options['calc']); unset($c); unset($c_id); } include FrmAppHelper::plugin_path() . '/pro/classes/helpers/FrmProMathHelper.php'; $m = new EvalMath(); if (strpos($field->field_options['calc'], ').toFixed(')) { $field->field_options['calc'] = str_replace(').toFixed(2', '', $field->field_options['calc']); $round = 2; } $result = $m->evaluate(str_replace('Math.', '', '(' . $field->field_options['calc'] . ')')); if (isset($round) and $round) { $result = sprintf('%.' . $round . 'f', $result); } unset($m); $_POST['item_meta'][$field->id] = $value = $result; unset($result); } unset($calc_matches); } //Don't validate the format if field is blank if ($value == '' or is_array($value)) { return $errors; } $value = trim($value); //validate the format if ($field->type == 'number' and !is_numeric($value) or $field->type == 'email' and !is_email($value) or ($field->type == 'website' or $field->type == 'url' or $field->type == 'image') and !preg_match('/^http(s)?:\\/\\/([\\da-z\\.-]+)\\.([\\da-z\\.-]+)/i', $value)) { $errors['field' . $field->id] = FrmProFieldsHelper::get_error_msg($field, 'invalid'); } if ($field->type == 'phone') { $pattern = (isset($field->field_options['format']) and !empty($field->field_options['format'])) ? $field->field_options['format'] : '^((\\+\\d{1,3}(-|.| )?\\(?\\d\\)?(-| |.)?\\d{1,5})|(\\(?\\d{2,6}\\)?))(-|.| )?(\\d{3,4})(-|.| )?(\\d{4})(( x| ext)\\d{1,5}){0,1}$'; $pattern = apply_filters('frm_phone_pattern', $pattern, $field); //check if format is already a regular expression if (strpos($pattern, '^') !== 0) { //if not, create a regular expression $pattern = preg_replace('/\\d/', '\\d', preg_quote($pattern)); $pattern = '/^' . $pattern . '$/'; } else { $pattern = '/' . $pattern . '/'; } if (!preg_match($pattern, $value)) { $errors['field' . $field->id] = FrmProFieldsHelper::get_error_msg($field, 'invalid'); } unset($pattern); } if ($field->type == 'date') { if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $value)) { global $frmpro_settings; $formated_date = FrmProAppHelper::convert_date($value, $frmpro_settings->date_format, 'Y-m-d'); //check format before converting if ($value != date($frmpro_settings->date_format, strtotime($formated_date))) { $errors['field' . $field->id] = FrmProFieldsHelper::get_error_msg($field, 'invalid'); } $value = $formated_date; unset($formated_date); } $date = explode('-', $value); if (count($date) != 3 or !checkdate((int) $date[1], (int) $date[2], (int) $date[0])) { $errors['field' . $field->id] = FrmProFieldsHelper::get_error_msg($field, 'invalid'); } } return $errors; }
function is_field_hidden($field, $values) { _deprecated_function(__FUNCTION__, '1.07.05', 'FrmProFieldsHelper::is_field_hidden'); return FrmProFieldsHelper::is_field_hidden($field, $values); }
/** * Don't require a conditionally hidden field */ public static function validate_conditional_field(&$errors, $field, &$value) { if (FrmField::is_option_empty($field, 'hide_field')) { return; } if (FrmProFieldsHelper::is_field_hidden($field, stripslashes_deep($_POST))) { if (isset($errors['field' . $field->temp_id])) { unset($errors['field' . $field->temp_id]); } $value = ''; } }
public static function show_entry($atts) { extract(shortcode_atts(array('id' => false, 'fields' => false, 'plain_text' => false, 'user_info' => false, 'include_blank' => false, 'show_html' => false, 'conditional' => true, 'form_id' => false, 'hidden' => false, 'type' => false), $atts)); global $frmpro_settings, $frm_entry; if (!$id) { return; } $entry = $frm_entry->getOne($id, true); $post['item_meta'] = $entry->metas; if (!$entry) { return; } $form_id = $entry->form_id; $id = $entry->id; if (!$fields or !is_array($fields)) { global $frm_field; $fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order'); } $content = $type == 'return' ? array() : ''; $odd = true; if (!$plain_text && $type === false) { $content .= "<table cellspacing='0'><tbody>\r\n"; } if ($type == 'array') { $array['form_title'] = $entry->form_name; $array['form_id'] = $entry->form_id; $array['lead_id'] = $entry->id; $date_created = $entry->created_at; $date_created_timestamp = strtotime($date_created); $array['date_created'] = date('d/m/Y', $date_created_timestamp); $array['date_created_usa'] = date('m/d/Y', $date_created_timestamp); $array['misc']['created_at'] = $entry->created_at; $array['misc']['updated_at'] = $entry->updated_at; $array['misc']['updated_by'] = $entry->updated_by; $array['misc']['user_id'] = $entry->user_id; $array['misc']['post_id'] = $entry->post_id; $array['misc']['description'] = maybe_unserialize($entry->description); $array['misc']['ip'] = $entry->ip; $array['misc']['parent_item_id'] = $entry->parent_item_id; } foreach ($fields as $f) { /* * Don't include any fields with the class of 'exclude' if the $type isn't 'array' */ if ($type != 'array' && stripos($f->field_options['classes'], 'exclude') !== false) { continue; /* skip this field */ } /* * Exclude any fields who are conditionally hidden */ if ($conditional === true && $type != 'array' && FrmProFieldsHelper::is_field_hidden($f, $post)) { continue; } $fname = $f->name; if ($hidden === true && $f->type == 'html') { continue; } elseif ($f->type == 'html' && $show_html == true) { if ($plain_text) { $content .= '<div class="html-field">' . $f->description . '</div><br /><br />'; } elseif ($type === false) { $content .= "<tr class='" . ($odd ? 'odd' : 'even') . "'><td colspan='2'>{$f->description}</td></tr>"; $odd = $odd ? false : true; unset($f); continue; } elseif ($type == 'block') { $content .= "<div class='container " . ($odd ? 'odd' : 'even') . "'>{$f->description}</div>"; $odd = $odd ? false : true; unset($f); continue; } elseif ($type == 'array') { $array[$f->field_key] = $f->description; continue; } elseif ($type == 'return') { $content[] = $f->description; } } if ($f->type == 'divider') { if ($plain_text) { $content .= '<div class="section-field"><h2>' . $f->name . '</h2></div><br /><br />'; } elseif ($type === false) { $content .= "<tr class='" . ($odd ? 'odd' : 'even') . " section-field'><td colspan='2'><h2>{$f->name}</h2></td></tr>"; $odd = $odd ? false : true; unset($f); continue; } elseif ($type == 'block') { $content .= "<div class='container section-field " . ($odd ? 'odd' : 'even') . "'><h2>{$f->name}</h2></div>"; $odd = $odd ? false : true; unset($f); continue; } elseif ($type == 'array') { $array[$f->field_key] = $f->name; continue; } elseif ($type == 'return') { $content[] = "<div class='container section-field " . ($odd ? 'odd' : 'even') . "'><h2>{$f->name}</h2></div>"; $odd = $odd ? false : true; unset($f); continue; } } if (in_array($f->type, array('captcha', 'break'))) { continue; } if (!isset($entry->metas[$f->id])) { if (!$include_blank && $type != 'array') { continue; } $entry->metas[$f->id] = ''; } $prev_val = maybe_unserialize($entry->metas[$f->id]); $meta = array('item_id' => $id, 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type); if ($f->type != 'signature' && $f->type != 'table') { $val = self::email_value($prev_val, (object) $meta, $entry); } if ($f->type == 'signature') { /* * Don't run signature block if signature field not found */ if (class_exists('FrmSigAppController')) { if (isset($prev_val['typed']) && strlen($prev_val['typed']) > 0) { $val = $type == 'array' ? $prev_val['typed'] : '<span class="typed_signature">' . $prev_val['typed'] . '</span>'; } else { $val = FrmSigAppController::display_signature($prev_val, $f, array('entry_id' => $id)); if ($type == 'array') { if (preg_match('/<img src="(.*?)" alt="(.*?)" \\/>/i', $val, $matches)) { $array['signature'][$f->field_key]['img'] = $val; $array['signature'][$f->field_key]['url'] = $matches[1]; $array['signature'][$f->field_key]['path'] = str_replace(home_url() . '/', ABSPATH, $matches[1]); } continue; } else { /* add class to image so we can resize appropriately */ $val = str_replace('/>', 'class="signature" />', $val); } } } } if ($f->type == 'checkbox' || $f->type == 'select' || $f->type == 'radio') { /* * Maybe convert the values to options */ $new_val = self::convert_values_to_name($val, $f->options); if ($type == 'array') { $fname = $f->name; $array['field'][$f->field_key] = array('title' => $fname, 'value' => $val, 'label' => $new_val, 'string' => implode(', ', $new_val), 'options' => $f->options, 'type' => $f->type); $array['field'][$f->field_key . '.' . $fname] = array('title' => $fname, 'value' => $val, 'label' => $new_val, 'string' => implode(', ', $new_val), 'options' => $f->options, 'type' => $f->type); } else { /* * $val is an array so implode it into a string */ $val = implode('<br />', $new_val); } } if ($f->type == 'table' && method_exists('FrmPlusEntryMetaHelper', 'frmplus_display_value_custom')) { /* grab the HTML */ if (!self::$frmplus_action_added) { add_action('frmplus_field_value_checkbox', 'FPPDF_Entry::convert_checkboxes_to_image'); add_action('frmplus_field_value_radio', 'FPPDF_Entry::convert_checkboxes_to_image'); add_action('frmplus_field_value_radioline', 'FPPDF_Entry::convert_checkboxes_to_image'); self::$frmplus_action_added = true; } $table_html = FrmPlusEntryMetaHelper::frmplus_display_value_custom($prev_val, $f, array()); if ($type == 'array') { $array['field'][$f->field_key] = self::get_table_data($f, $table_html, $prev_val); $array['field'][$f->field_key . '.' . $fname] = $array['field'][$f->field_key]; } else { $val = $table_html; } } $val = !is_array($val) ? stripslashes($val) : $val; if ($f->type == 'image' || $f->type == 'url' || $f->type == 'file') { if ($type == 'array') { $array['field'][$f->field_key . '.' . $fname] = $val; $array['field'][$f->field_key] = $val; } elseif (is_array($val)) { /* * $val is an array so implode it into a string */ $val = '<a href="' . $val['url'] . '">' . $val['name'] . '</a>'; } } if ($f->type == 'tag') { $val = str_replace(',', ', ', $val); } if ($f->type == 'textarea') { $val = str_replace(array("\r\n", "\r", "\n"), ' <br/>', $val); } if (is_array($val)) { $val = implode(', ', $val); } if ($plain_text) { $content .= $fname . ': ' . $val . "<br /><br />"; } elseif ($type === false) { if ($f->type == 'table') { $content .= "<tr class='" . ($odd ? 'odd' : 'even') . "'><th colspan='2'>" . $fname . "</th></tr>"; $content .= "<tr class='" . ($odd ? 'odd' : 'even') . "'><td class='table-cell' colspan='2'>{$val}</td></tr>"; } else { $content .= "<tr class='" . ($odd ? 'odd' : 'even') . "'><th>" . $fname . "</th><td>{$val}</td></tr>"; } $odd = $odd ? false : true; } elseif ($type == 'block') { $content .= "<div class='container " . ($odd ? 'odd' : 'even') . "'><div class='title'>" . $fname . "</div><div class='value'>{$val}</div></div>"; $odd = $odd ? false : true; } elseif ($type == 'array' && $f->type != 'checkbox' && $f->type != 'select' && $f->type != 'radio' && $f->type != 'table' && $f->type != 'image' && $f->type != 'url' && $f->type != 'file') { $array['field'][$f->field_key . '.' . $fname] = array('title' => $fname, 'value' => $val, 'type' => $f->type); $array['field'][$f->field_key] = array('title' => $fname, 'value' => $val, 'type' => $f->type); } elseif ($type == 'return') { $content[] = "<div class='container " . ($odd ? 'odd' : 'even') . "'><div class='title'>" . $fname . "</div><div class='value'>{$val}</div></div>"; $odd = $odd ? false : true; } unset($fname); unset($f); } if ($user_info) { $data = maybe_unserialize($entry->description); if ($plain_text) { $content .= "<br /><br />" . __('User Information', 'formidable') . "<br />"; $content .= __('IP Address', 'formidable') . ": " . $entry->ip . "<br />"; $content .= __('User-Agent (Browser/OS)', 'formidable') . ": " . $data['browser'] . "<br />"; $content .= __('Referrer', 'formidable') . ": " . $data['referrer'] . "<br />"; } elseif ($type === false) { $content .= "<tr class='" . ($odd ? 'odd' : 'even') . "'><th>" . __('IP Address', 'formidable') . "</th><td>" . $entry->ip . "</td></tr>"; $odd = $odd ? false : true; $content .= "<tr class='" . ($odd ? 'odd' : 'even') . "'><th>" . __('User-Agent (Browser/OS)', 'formidable') . "</th><td>" . $data['browser'] . "</td></tr>"; $odd = $odd ? false : true; $content .= "<tr class='" . ($odd ? 'odd' : 'even') . "'><th>" . __('Referrer', 'formidable') . "</th><td>" . str_replace("\r\n", '<br/>', $data['referrer']) . "</td></tr>"; } elseif ($type == 'block') { $content .= "<div class='container " . ($odd ? 'odd' : 'even') . "'><div class='title'>" . $fname . "</div><div class='value'>{$val}</div></div>"; $content .= "<div class='container " . ($odd ? 'odd' : 'even') . "'><div class='title'>" . __('IP Address', 'formidable') . "</div><div class='value'>" . $entry->ip . "</div></div>"; $odd = $odd ? false : true; $content .= "<div class='container " . ($odd ? 'odd' : 'even') . "'><div class='title'>" . __('User-Agent (Browser/OS)', 'formidable') . "</th><td>" . $data['browser'] . "</div></div>"; $odd = $odd ? false : true; $content .= "<div class='container " . ($odd ? 'odd' : 'even') . "'><div class='title'>" . __('Referrer', 'formidable') . "</th><td>" . str_replace("\r\n", '<br/>', $data['referrer']) . "</div></div>"; } elseif ($type == 'array') { $array['user_info']['ip'] = $entry->ip; $array['user_info']['user_agent'] = $data['browser']; $array['user_info']['referrer'] = str_replace("\r\n", '<br/>', $data['referrer']); } else { if ($type == 'return') { $content[] = "<div class='container " . ($odd ? 'odd' : 'even') . "'><div class='title'>" . $fname . "</div><div class='value'>{$val}</div></div>"; $content[] = "<div class='container " . ($odd ? 'odd' : 'even') . "'><div class='title'>" . __('IP Address', 'formidable') . "</div><div class='value'>" . $entry->ip . "</div></div>"; $odd = $odd ? false : true; $content[] = "<div class='container " . ($odd ? 'odd' : 'even') . "'><div class='title'>" . __('User-Agent (Browser/OS)', 'formidable') . "</th><td>" . $data['browser'] . "</div></div>"; $odd = $odd ? false : true; $content[] = "<div class='container " . ($odd ? 'odd' : 'even') . "'><div class='title'>" . __('Referrer', 'formidable') . "</th><td>" . str_replace("\r\n", '<br/>', $data['referrer']) . "</div></div>"; } } } if (!$plain_text && $type === false) { $content .= "</tbody></table>"; } elseif ($type == 'array') { return $array; } return $content; }