Filter a view used within a form with form field value.

By: Patrick McDonald | Asked: 11/27/2023
ForumsCategory: General questionsFilter a view used within a form with form field value.
Patrick McDonald asked 5 months ago
I have created a view to show a preview of a form prior to submission.  I am currently using the below code to populate a field within the form with the current entry id.
add_action('frm_after_create_entry', 'frm_add_entry_id_for_drafts', 42, 2);
add_action('frm_after_update_entry', 'frm_add_entry_id_for_drafts', 42, 2); function frm_add_entry_id_for_drafts($entry_id, $form_id) {
if ($form_id == 2) { // Change to the ID of your form
$field_value = FrmEntryMeta::get_entry_meta_by_field($entry_id, 290);

if (empty($field_value)) {
// Act if field 290 is empty
FrmEntryMeta::add_entry_meta($entry_id, 290, "", $entry_id); // Change 290 to the ID of the field where you want to store the entry ID
}
}
}
However, I am having troubling passing this field value within my view shortcode. Here is how I am showing the view right now within an html field:  [display-frm-data id="81" entry="[290]" drafts="1" filter="limited"]; however, this doesn't seem to work. Any feedback is appreciated.
Rob LeVineRob LeVine replied 5 months ago

I'm confused as to what you're trying to do. If you want to show a summary of the form prior to submission, you can add the Summary field to your form. frm_after_create_entry and frm_after_update_entry only work once the entry is saved, so I'm not even sure how you're using that in this scenario. The form entry doesn't have an id until it's saved.

2 Answers
Victor Font answered 5 months ago
I agree with Rob. A view cannot display en entry until the entry is saved via submission. I don't understand what you mean by showing a preview of the form "prior to submission". There is no hook for this. That's the summary field's role.
Patrick McDonald answered 5 months ago
The code to add the entry ID does in fact work prior to final submission.  I am using a view to provide an alternate presentation of the summary rather than just using the summary field.  My question is really: how do I pass a field value within the current form using my view shortcode?  The entry ID does populate to field 290 within the form.
Rob LeVineRob LeVine replied 5 months ago

I'll admit I still don't get it, however, to give a general answer:
1. To pass a param to a view shortcode, you can just add it to the shortcode. e.g., [display-frm-data id=18267] => [display-frm-data id=18267 myparam="myvalue"]
2. If you're in a form, with a field that contains a view shortcode you'll have to use jQuery to fill in the parameter value, because there's no way to set the value into that shortcode using an FF shortcode because of nested shortcodes. The solution is very simple jQuery, though that's easy for me to say.

Here's to hoping Victor says I'm wrong.

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