Need help using forminator
-
A trying to use the Forminator_API::update_form_entry( $form_id, $entry_id, $entry_meta ). the result is returning true but no changes are made
// Handle edit action if requested – SIMPLIFIED VERSION
if (isset($_POST[‘forminator_edit_entry’]) && isset($_POST[‘entry_id’]) && isset($_POST[‘nonce’])) {
$entry_id = intval($_POST[‘entry_id’]);// Verify nonce if (wp_verify_nonce($_POST['nonce'], 'forminator_edit_entry')) { $form_id = intval($atts['form_id']); if (class_exists('Forminator_API')) { // Prepare the updated meta data in the correct Forminator format $entry_meta = array(); // Map POST field names to Forminator field IDs $field_mapping = array( 'select-8' => 'select-8', 'name-1' => 'name-1', 'name-2' => 'name-2', 'select-3' => 'select-3', 'text-4' => 'text-4', 'select-2' => 'select-2', 'text-5' => 'text-5', 'text-3' => 'text-3', 'phone-1' => 'phone-1', 'phone-4' => 'phone-4', 'email-1' => 'email-1', 'address-1' => 'address-1', 'address-4' => 'address-4', 'select-9' => 'select-9', 'text-7' => 'text-7', 'text-8' => 'text-8', 'text-6' => 'text-6', 'text-1' => 'text-1', 'text-12' => 'text-12', 'text-13' => 'text-13', 'text-23' => 'text-23', 'text-24' => 'text-24', 'text-21' => 'text-21', 'text-22' => 'text-22', 'select-5' => 'select-5', 'currency-1' => 'currency-1', 'currency-2' => 'currency-2', 'name-3' => 'name-3', 'phone-2' => 'phone-2', 'address-3' => 'address-3', 'radio-1' => 'radio-1', 'address-2' => 'address-2', 'text-9' => 'text-9', 'text-10' => 'text-10', 'text-11' => 'text-11', 'text-17' => 'text-17', 'text-18' => 'text-18', 'text-19' => 'text-19', 'text-20' => 'text-20', 'select-6' => 'select-6', 'name-4' => 'name-4', 'text-14' => 'text-14', 'text-15' => 'text-15', 'hidden-1' => 'hidden-1' ); foreach ($field_mapping as $field_key => $post_key) { if (isset($_POST[$post_key])) { $new_value = sanitize_text_field($_POST[$post_key]); // Handle address fields specially if (in_array($field_key, ['address-1', 'address-2', 'address-3', 'address-4'])) { $entry_meta[] = array( 'name' => $field_key, 'value' => array( 'street_address' => $new_value, 'city' => '', 'state' => '', 'zip' => '', 'country' => '' ) ); } else { // Regular fields $entry_meta[] = array( 'name' => $field_key, 'value' => $new_value ); } } } // Update the entry try { $result = Forminator_API::update_form_entry($form_id, $entry_id, $entry_meta); if ($result && !is_wp_error($result)) { // Clear Forminator cache if (function_exists('forminator_maybe_clear_cache')) { forminator_maybe_clear_cache($form_id); } echo '<script> alert("Entry updated successfully."); window.location.href = "' . remove_query_arg(array('forminator_edit_entry', 'entry_id', 'nonce')) . '"; </script>'; exit; } else { echo '<script>alert("Failed to update entry.");</script>'; } } catch (Exception $e) { echo '<script>alert("Error updating entry: ' . esc_js($e->getMessage()) . '");</script>'; } } } else { echo '<script>alert("Security verification failed.");</script>'; }}
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Need help using forminator’ is closed to new replies.