I want to record some day-specific information in a user's entry so that when I display their entry using a view, I can display this information. My plan was:
I cannot find the function in the help docs to actually set a value. I have found the ones to get a value, but I need to set it.
This is the function ultimately being called from the user having added and entry, and it works as expected. Just need the code to actually change a value, or understand what would be an alternative way of approaching this.
This help documentation https://formidableforms.com/knowledgebase/set-values-to-be-used-in-custom-displays-or-default-values/ doesn't show any usable PHP, only shortcodes.
function tw_add_day_data_to_entry($entry_id, $form_id ){ $entry = FrmEntry::getOne($entry_id); $user_id = $entry->user_id;
if ( ! $user_id ) { return; //don't continue if no user } // $day = tw_return_status(); $url = tw_home_page()."/day-".$day; echo "Day= ".$day; echo "URL= ".$url; // at this point they return a value $dayURL = FrmProEntriesController::get_field_value_shortcode(array('field_id' ='IDn8jec', 'entry' => $entry_id)); echo $dayURL; $day = FrmProEntriesController::get_field_value_shortcode(array('field_id' ='9q904', 'entry' => $entry_id)); echo $day; }
Think I've sorted this. Was using the key instead of the id (although key would be better)
Found the code to set a value
Would be great to have that on the documentation.
FrmEntryMeta::update_entry_meta( $entry_id, $dayFieldID, null, $day );
Note: that update_entry_meta will only work if there's a value already in there for that field. Most of the time it's best to run the update and if false is returned then run FrmEntryMeta::add_entry_meta
The code that was commented out will do it (it was in the notification email for this post but you apparently edited it out of the post).
FrmEntryMeta::add_entry_meta( $entry_id, 1819, "", $key) (obviously replacing the 2nd and 4th params with your own). You can also always use straight SQL commands.
Additionally, those echo commands might cause you a problem somewhere along the way. If you're doing it for debugging purposes it's better to turn on WP debugging and use error_log.
Thanks, any idea how I can use the key instead of ID as this would make it so much more versatile for moving the code into prodcution.
Agreed, you should always use keys. I feel strongly that you should always (re)name your keys to know what they are when you're looking at them in code, i.e.., [form_key]_somethingdescriptive, e.g., myformkey_user_first_name. That being said, what you want to do is make use of the key->id and id->key functions that Formidable offers. https://formidableforms.com/knowledgebase/php-examples/#kb-fields
Please login or Register to submit your answer