Hello Christian, i'm trying to follow this old thread and failing.
https://toolset.com/forums/topic/favorites-view-conditional-button-on-post-add-to-remove-from-favorite-list/
Specifically:
- Create a form that edits the listing post type
- Remove all the inputs from this form except the submit button
The site is a business listing membership site. The post type I'm trying to add the favorite post feature to is "listings" which is already created with a form that has required fields. So when I create another form I cannot remove all fields.
I'm sure I'm confused somewhere here...
So when I create another form I cannot remove all fields.
Hi, in the new Form builder you will have to switch to expert mode. Then you can manually edit the code to remove everything except the main Form shortcode, the Form messages shortcode, and the submit button shortcode. It will look something like this:
[credform]
[cred_field field='form_messages' class='alert alert-warning']
[cred_field field='form_submit' output='bootstrap' value='Submit' class='btn btn-primary btn-lg']
[/credform]
Then you should be able to save the modifications to the Form.
Thanks Christian. Another related (and possibly stupid) question. How would I target the button to style it in this format?
Note that when creating a filter I had no problem finding the selector for the button. I generally get it, but can't seem to do so with this form for favorites.
Skip that last question. Instead, could you help me with the php required to implement the cred_save_data hook to add the User's ID to the repeating field when the form is submitted? I've been unable to find an example in the documentation or previous questions.
Thank You!
Sure, I can help. Here's an example showing how you would add the current User's ID to a custom field:
add_action('cred_save_data_12345', 'add_user_favorite_cred',10,2);
function add_user_favorite_cred($post_id, $form_data)
{
add_post_meta($post_id, 'wpcf-fieldslug', get_current_user_id(), false);
}
https://toolset.com/forums/topic/favorites-view/#post-579587