Hello @kizha,
Looking at your request, I feel this is a too custom one and here is what you may need to work that out. You can use this filter forminator_custom_form_submit_errors and from this var $field_data_array you would get the field that contains the ISBN. Then you can run a select query to see if that exists already. If it exists, it would return a new error. If it doesn’t exist it would let it continue. The ISBN should also still be stored in the entries metatables. It would be more valid to search the post meta table though as entries can be deleted but the post still exists.
Here is an example to explain things to you in a better way:
add_filter(
'forminator_custom_form_submit_errors',
function( $submit_errors, $form_id, $field_data_array ) {
$isbn_field = 'text-1';
foreach( $field_data_array as $field ) {
if ( ! isset( $field[ 'name' ] ) || ! isset( $field[ 'value' ] )|| $isbn_field !== $field[ 'name' ] ) {
continue;
}
$value = sanitize_text_field( $field[ 'value' ] );
// Custom Query
$exists = true;
if ( $exists ) {
$submit_errors[][ $field[ 'name' ] ] = __( "The ISBN you entered {$value} exists already" );
}
}
return $submit_errors;
},
20, 3
);
Now, you can replace the field here:
$isbn_field = 'text-1';
and here too:
// Custom Query
$exists = true;
You need to do the custom query to check if ISBN exists and update the $exists variable. If it $exists it will add a new error. The $value above is the actual ISBN sent.
When checked with the SLS team, they advised that this is better than creating post then checking if ISBN exists and then delete the entry and new post.
Here is a sample query for the same:
$query_args = array(
'post_type' => 'THECPT',
'meta_query' => array(
array(
'key' => 'THE_ISBN_meta_key',
'value' => $value,
),
)
);
$query = new WP_Query( $query_args );
Hope this helps.
Thank you,
Prathamesh Palve