/** * Process validation for a edit entry submission * * Sets the `is_valid` object var * * @return void */ function validate() { // If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry if (class_exists('GFUser')) { remove_filter('gform_validation', array('GFUser', 'user_registration_validation')); } /** * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. * You can enter whatever you want! * We try validating, and customize the results using `self::custom_validation()` */ add_filter('gform_validation_' . $this->form_id, array($this, 'custom_validation'), 10, 4); // Needed by the validate funtion $failed_validation_page = NULL; $field_values = RGForms::post('gform_field_values'); // Prevent entry limit from running when editing an entry, also // prevent form scheduling from preventing editing unset($this->form['limitEntries'], $this->form['scheduleForm']); // Hide fields depending on Edit Entry settings $this->form['fields'] = $this->get_configured_edit_fields($this->form, $this->view_id); $this->is_valid = GFFormDisplay::validate($this->form, $field_values, 1, $failed_validation_page); remove_filter('gform_validation_' . $this->form_id, array($this, 'custom_validation'), 10); }
public static function edit_lead_detail($Form, $lead, $options) { global $current_user, $_gform_directory_approvedcolumn; require_once GFCommon::get_base_path() . "/form_display.php"; if (empty($_gform_directory_approvedcolumn)) { $_gform_directory_approvedcolumn = self::get_approved_column($Form); } // We fetch this again, since it may have had some admin-only columns taken out. #$lead = RGFormsModel::get_lead($lead["id"]); // If you want to allow users to edit their own approval (?) add a filter and return true. if (apply_filters('kws_gf_directory_allow_user_edit_approved', false) === false) { $Form['fields'] = self::remove_approved_column('form', $Form['fields'], $_gform_directory_approvedcolumn); } // If this is not the form that should be edited list($urlformid, $urlleadid) = self::get_form_and_lead_ids(); if (intval($Form['id']) !== intval($urlformid) || intval($lead['id']) !== intval($urlleadid)) { return; } // If either of these two things are false (creator of lead, or admin) if (!((!empty($options['useredit']) && is_user_logged_in() && intval($current_user->ID) === intval($lead['created_by'])) === true || (!empty($options['adminedit']) && self::has_access("gravityforms_directory")) === true)) { // Kick them out. printf(esc_html_e('%sYou do not have permission to edit this form.%s', 'gravity-forms-addons'), '<div class="error">', '</div>'); return; } $validation_message = ''; // If the form is submitted if (RGForms::post("action") === "update") { check_admin_referer('gforms_save_entry', 'gforms_save_entry'); $lead = apply_filters('kws_gf_directory_lead_being_updated', $lead, $Form); // We don't DO passwords. foreach ($Form['fields'] as $key => $field) { if ($field['type'] === 'password') { unset($Form['fields'][$key]); } } $is_valid = GFFormDisplay::validate($Form, $lead); $validation_message = ''; foreach ($Form['fields'] as $field) { if (!GFCommon::is_product_field($field["type"])) { $validation_message .= rgget("failed_validation", $field) && !empty($field["validation_message"]) ? sprintf("<li class='gfield_description validation_message'><strong>%s</strong>: %s</li>", $field["label"], $field["validation_message"]) : ""; } } if (!empty($validation_message)) { $validation_message = '<ul>' . $validation_message . '</ul>'; echo esc_html(apply_filters('kws_gf_directory_lead_error_message', sprintf(__("%sThere were errors with the edit you made.%s%s", 'gravity-forms-addons'), "<div class='error' id='message' style='padding:.5em .75em; background-color:#ffffcc; border:1px solid #ccc;'><p>", "</p>", $validation_message . '</div>'), $lead, $Form)); } // So the form submission always throws an error even though there's no problem. // Product fields can't be edited, so that doesn't really matter. if (!empty($is_valid) || empty($is_valid) && empty($validation_message)) { do_action('kws_gf_directory_pre_update_lead', $lead, $Form); // since @3.6.1 to enable conditional fields' updates. self::save_lead($Form, $lead); $lead = RGFormsModel::get_lead($lead["id"]); do_action('kws_gf_directory_post_update_lead', $lead, $Form); echo apply_filters('kws_gf_directory_lead_updated_message', sprintf(esc_html__("%sThe entry was successfully updated.%s", 'gravity-forms-addons'), "<p class='updated' id='message' style='padding:.5em .75em; background-color:#ffffcc; border:1px solid #ccc;'>", "</p>"), $lead, $Form); return $lead; } } if (isset($_GET['edit']) && wp_verify_nonce($_GET['edit'], 'edit' . $lead['id'] . $Form["id"]) || !empty($validation_message)) { // The ID of the form needs to be `gform_{form_id}` for the pluploader ?> <form method="post" id="gform_<?php echo esc_attr($Form['id']); ?> " enctype="multipart/form-data" action="<?php echo remove_query_arg(array('gf_search', 'sort', 'dir', 'pagenum', 'edit'), add_query_arg(array())); ?> "> <?php wp_nonce_field('gforms_save_entry', 'gforms_save_entry'); ?> <input type="hidden" name="action" id="action" value="update"/> <input type="hidden" name="screen_mode" id="screen_mode" value="edit" /> <?php $form_without_products = $Form; $post_message_shown = false; $product_fields = array(); foreach ($Form['fields'] as $key => $field) { if (GFCommon::is_product_field($field["type"]) || is_numeric($lead["post_id"]) && GFCommon::is_post_field($field)) { if (is_numeric($lead["post_id"]) && GFCommon::is_post_field($field) && !$message_shown) { echo apply_filters('kws_gf_directory_edit_post_details_text', sprintf(esc_html__('You can edit post details from the %1$spost page%2$s.', 'gravity-forms-addons'), '<a href="' . admin_url('post.php?action=edit&post=' . $lead["post_id"]) . '">', '</a>'), $field, $lead, $lead['post_id']); $message_shown = true; } unset($form_without_products['fields'][$key]); $product_fields[] = $field['id']; if (!empty($field['inputs'])) { foreach ($field['inputs'] as $input) { $product_fields[] = $input['id']; } } } } $lead_without_products =& $lead; foreach ($product_fields as $product_field) { $value = RGFormsModel::get_lead_field_value($lead, $field); unset($lead_without_products[$product_field]); } require_once GFCommon::get_base_path() . "/entry_detail.php"; GFEntryDetail::lead_detail_edit(apply_filters('kws_gf_directory_form_being_edited', $form_without_products, $lead), apply_filters('kws_gf_directory_lead_being_edited', $lead_without_products, $form_without_products)); echo '<input class="button-primary" type="submit" tabindex="4" value="' . esc_attr(apply_filters('kws_gf_directory_update_lead_button_text', __('Update Entry', 'gravity-forms-addons'))) . '" name="save" />'; ?> </form> <?php do_action('kws_gf_directory_post_after_edit_lead_form', $lead, $Form); return false; } elseif (isset($_GET['edit']) && !wp_verify_nonce($_GET['edit'], 'edit')) { echo apply_filters('kws_gf_directory_edit_access_error_message', sprintf(esc_html__("%sThe link to edit this entry is not valid; it may have expired.%s", 'gravity-forms-addons'), "<p class='error' id='message' style='padding:.5em .75em; background-color:#ffffcc; border:1px solid #ccc;'>", "</p>"), $lead, $Form); } return $lead; }