Read value from a field before submittion

By: Ibrar Ahmad | Asked: 03/13/2024
ForumsCategory: Code HelpRead value from a field before submittion
Ibrar Ahmad asked 1 month ago
Hi,

I want to read the value from a field before submission and do validation. I can read it after submission but how can I read it before submission?

I wrote this PHP snippet

<code>
// Hook to update KrExists field after form entry creation
add_action('frm_after_create_entry', 'update_kr_exists_field', 10, 2);
add_action('frm_after_update_entry', 'update_kr_exists_field', 10, 2); // Function to update KrExists field based on Kreditor Nr validation
function update_kr_exists_field($entry_id, $form_id) {
// Check if the form is Test_Kreditor (form ID 8)
if ($form_id == 8) {
// Get the Kreditor Nr value from the form entry
$kreditor_nr = FrmProEntriesController::get_field_value_shortcode(array('field_id' => 72, 'entry' => $entry_id)); // Check if Kreditor Nr exists in the Google Sheet
$is_kreditor_nr_exists = check_if_kreditor_nr_exists($kreditor_nr); // Update the KrExists field value in the form entry
FrmProEntriesController::update_entry_meta($entry_id, 73, $is_kreditor_nr_exists ? 'Yes' : 'No');
}
} // Function to check if Kreditor Nr exists in the Google Sheet
function check_if_kreditor_nr_exists($kreditor_nr) {
// Implement the logic to check if Kreditor Nr exists in the Google Sheet
// You may use Google Sheets API or other methods to check the existence // For demonstration purposes, you can use a simple example
// Replace the following line with your actual validation logic
$sample_kreditor_nrs = array('123', '456', '789');
return in_array($kreditor_nr, $sample_kreditor_nrs);
}
</code>
1 Answers
Victor Font answered 1 month ago
There are a few filters you can use before submission. See https://formidableforms.com/knowledgebase/frm_validate_field_entry/, https://formidableforms.com/knowledgebase/frm_validate_field_entry/ or https://formidableforms.com/knowledgebase/frm_pre_create_entry/.
Ibrar Ahmad replied 1 month ago

Thanks for your response. frm_validate_field_entry only triggers after the user clicks the submit button. I want to do it before clicking the submit button.

Victor Font replied 1 month ago

Then you have no choice, you have to do it in the browser with jQuery.

Ibrar Ahmad replied 1 month ago

Is there any knowledge base for it?

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right