Replies: 1
add_action( 'forminator_custom_form_after_save_entry', 'wpmudev_custom_hidden_field_value' );
function wpmudev_custom_hidden_field_value( $form_id, $response ) {
if ( $form_id == 1520 && $response['success']) { // Replace 1520 with your actual form ID
// Retrieve the latest entry by form ID
$entry = Forminator_Form_Entry_Model::get_latest_entry_by_form_id( $form_id );
if ( is_wp_error( $entry ) || empty( $entry ) ) {
return $response; // Exit if there's an error or no entry data
}
$entry_data = $entry->meta_data; // Get the entry meta data
// Sanitize and extract the submitted data
$post_title = sanitize_text_field( $entry_data['text-1']['value'] ?? '' );
$post_content = wp_kses_post( $entry_data['textarea-1']['value'] ?? '' );
$rating = sanitize_text_field( $entry_data['rating-1']['value'] ?? '' );
$date = sanitize_text_field( $entry_data['date-1']['value'] ?? '' );
$name = sanitize_text_field( $entry_data['name-1']['value'] ?? '' );
$email = sanitize_email( $entry_data['email-1']['value'] ?? '' );
$phone = sanitize_text_field( $entry_data['phone-1']['value'] ?? '' );
$image = esc_url_raw( $entry_data['upload-1']['value']['file']['file_url'] ?? '' );
// Only insert post if title or content is not empty
if ( ! empty( $post_title ) || ! empty( $post_content ) ) {
// Insert a new post with the data
$post_id = wp_insert_post( array(
'post_title' => $post_title, // Use the dynamic title
'post_content' => $post_content, // Use the dynamic content
'post_type' => 'review', // Replace with your custom post type
'post_status' => 'draft' // Set the post status to 'draft'
) );
// Update the ACF fields with the form data
if ( $post_id ) {
if ( ! empty( $date ) ) {
update_field( 'date', $date, $post_id );
}
if ( ! empty( $rating ) ) {
update_field( 'rating', $rating, $post_id );
}
if ( ! empty( $name ) ) {
update_field( 'name', $name, $post_id );
}
if ( ! empty( $email ) ) {
update_field( 'email', $email, $post_id );
}
if ( ! empty( $phone ) ) {
update_field( 'phone', $phone, $post_id );
}
if ( ! empty( $image ) ) {
update_field( 'image', $image, $post_id );
}
}
}
}
return $response;
}
this is my code, can you fix my code?
when i submit the form then not save the data. action hook not working.
i am using free version of forminator