Use this shortcode to insert a link which allows user to update a single field with one click. When using this shortcode, a link will be inserted that can be clicked to change a specific field in an entry to a value that you define. For example, you could add a "Mark as Complete" link that will change a field to "Complete" when clicked.
Usage
This shortcode adds an Update link that changes the value of a single field in a specific entry via Ajax. If the current value of that field is the same as the value parameter in your shortcode, the link will not be visible. This shortcode does not currently support fields set as post fields.
[frm-entry-update-field id=x field_id=y value="new value"]
'x' = ID of the entry to update. Make the entry ID dynamic in a View by replacing 'x' with [id].
'y' = ID of the field to change.
'new value' = the field value will be updated to match this value.
Parameters
Required
- id - ID of the entry to change. Use id=[id] in a View.
- field_id - ID or key of the field to update.
- value - The field value will be updated to match this value when the link is clicked. To pass the value of a specific field, replace "new value" with "[100]".
Usage: [frm-entry-update-field id=x field_id=y value="[100]"]
Replace 100 with the ID of the field that will be used as the new value.
Optional
- label - The label for the update link. If not specified, this defaults to "Update". Usage: [frm-entry-update-field id=x field_id=y value="new value" label="Update"]
- class - Add any HTML classes to the link here. Usage: [frm-entry-update-field id=x field_id=y value="new value" class="my_class"]
- message - The text seen after the field value is changed. Usage: [frm-entry-update-field id=x field_id=y value="new value" message="The field has been updated"]
- title - The title attribute for the update link. If not specified, the label parameter will be used for title. Usage: [frm-entry-update-field id=x field_id=y value="new value" title="Click to update"]
Examples
Send an Email After Field is Updated
If you would like to automatically send an email notification after a field has been updated with this shortcode, add the following code to the "Code Snippets" plugin or a child theme's functions.php file.
add_action('frm_after_update_field', 'frm_trigger_entry_update'); function frm_trigger_entry_update($atts){ $entry = FrmEntry::getOne( $atts['entry_id'], true ); $form = FrmForm::getOne( $entry->form_id ); FrmFormActionsController::trigger_actions('update', $form, $entry, 'email' ); // Remove ", 'email'" if you want to trigger all form actions }
Reload Page After Field is Updated
If you would like to allow an AJAX refresh after a field has been updated with this shortcode, you can follow the steps below:
- Add a custom class to your shortcode using the class parameter.
[frm-entry-update-field id=x field_id=y value="new value" class="reload_page"]
- Add the following Javascript code to your theme's footer section. If the link is in a View, add the code to the After Content. You can also use a plugin like Simple Custom CSS and JS.
<script> jQuery(document).ready(function(){ jQuery('.reload_page').click(function(){ //replace reload_page with the name of the class specified in your shortcode setTimeout(function() { window.location.reload(); }, 3000); // change 3000 to number of seconds in milliseconds }) }) </script>
PHP Alternative
FrmProEntriesController::entry_update_field(array('id' => x, 'field_id' => 'y', 'label' => 'Update', 'class' => '', 'value' => 'new value', 'message' => 'Successfully Updated'));
'x' = ID of the entry.
'y' = ID of the field to change.