1. Is it possible to have a spinner instead of displaying " Please wait. You are being redirected." and also avoid having the page reload?
It's possible to use one of the CRED form options "keep displaying this form" or "display a message instead of this form" along with "AJAX submission" to prevent a page reload after submit. However, there's no spinner graphic implemented, so that would require custom code on your part. Also, "keep displaying this form" will not be ideal in your case because the button text would not update correctly all the time. There's not a JavaScript API for CRED, which you would need in order to update the text appropriately after the form is submitted.
2. What would I insert into the view to show a "remove from Favorites" button?
Inside the Loop Output, you would insert the same CRED form that's shown on the Motorcycle post.
1. It wants to reload with any option, even with AJAX active. I can't use the display a message option, because then it takes away the "remove from Favorites" button. Any other suggestions?
2. Screenshot: enlace oculto
When the item is in the Favorite List View it displays a button that read "Add to Favorites". It should be displaying "Remove from Favorites" as it's already Favorited.
Thanks,
Chuck
1. It wants to reload with any option, even with AJAX active. I can't use the display a message option, because then it takes away the "remove from Favorites" button. Any other suggestions?
Even with AJAX active, if you tell CRED to "show the post" after submission, it will reload the page. I think beyond these options you would need to consider custom code. It's not currently possible to show a CRED form in the success message (so you can't swap one form out for another) and there's not a good way to trigger a JavaScript event when the form is submitted successfully (so you can't modify the contents of the form after submission). I'm not aware of another good option here.
2. When the item is in the Favorite List View it displays a button that read "Add to Favorites". It should be displaying "Remove from Favorites" as it's already Favorited.
Okay a small tweak to the submit button selector should fix this to work in both locations. I made that change and tested it out - seems to display correctly now.
jQuery(window).bind("load", function() {
jQuery( "form[id^='cred_form_1876']").find("input[type='submit']").val(jQuery( "input[name='remove-favorite']").length ? "Remove from Favorites" : "Add to Favorites");
});
1. Would a toggle work as a solution, instead of a button? Something like this: enlace oculto
2. When I click Remove from Favorites for the favorites view it removes the post, but it directs me to the post page. Anyway to avoid that and stay on the account page?
Thanks,
Chuck
1. Would a toggle work as a solution, instead of a button? Something like this: enlace oculto
It might work with some custom code, but that falls outside the scope of the support we could provide here since this type of custom control is not part of the CRED feature set. You would need to be able to submit the CRED form whenever the toggle changes, and add or remove the hidden field as necessary.
2. When I click Remove from Favorites for the favorites view it removes the post, but it directs me to the post page. Anyway to avoid that and stay on the account page?
If you want to modify the redirect that is specified in the form settings, you can use the cred_success_redirect API:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
However, since you are using the same form in two different places this might present some challenges if you want the redirect to behave differently in different locations. Another option is to duplicate the CRED form and set different redirect options in their settings, then apply different CRED forms in different locations.
1. I'm ok with the reload for now and will leave this to rest.
2. I still need to find an adequate remove from favorites option. Is it possible to add a checkbox and them remove button to the view or setup a separate view/content template to control this feature? Just like WordPress uses for mass selections of posts and pages. Screenshot: enlace oculto
Thanks,
Chuck
CRED doesn't offer a bulk selection or bulk edit feature like the WordPress dashboard. I think you'll need to use the redirect API to modify the redirection option, or create multiple forms that use different redirect settings and use conditional HTML to show the correct form in different locations on your site.
Going back to reply #581174
Can I setup a conditional for "display a message instead of this form" that would display a message when "Add to Favorites" is clicked and a different message for when "Remove from Favorites" is clicked? Right now I'm running into a problem where I have this for the message displayed for Add to Favorites:
Added to Favorites.
<a href="<em><u>enlace oculto</u></em>"><u>View Favorites</u></a>
But that message doesn't make sense to display if someone clicks "Remove from Favorites"
Thanks,
Chuck
You can use shortcodes in the message area, including conditionals. It sounds like you need to be able to determine whether or not the edited post is a favorite, and use that in a conditional. Something like a shortcode that returns 1 if it's a favorite or 0 if it's not a favorite. Then you can use that shortcode in a conditional to determine which should be shown.
add_shortcode( 'toolset_is_favorite', 'toolset_is_favorite_func');
function toolset_is_favorite_func($atts)
{
global $wpdb;
$post_id = $atts['id'];
$user_id = get_current_user_id();
$favorites = $wpdb->get_results( "SELECT * FROM wp_postmeta WHERE meta_key = 'wpcf-favorites' AND post_id = $post_id AND meta_value = $user_id LIMIT 1");
return sizeof($favorites) ? 1 : 0;
}
And then the conditional:
[wpv-conditional if="( [toolset_is_favorite id='[wpv-post-id]'] eq '1' )"]it's a favorite[/wpv-conditional]
I added your code, but now the Favorites button disappears when clicked:
Button before clicked: enlace oculto
button after clicked: enlace oculto
Not sure why it's disappearing instead of displaying a message. This is the message I am using:
[wpv-conditional if="( [toolset_is_favorite id='[wpv-post-id]'] eq '1' )"]Added to Favorites.<a href="<em><u>enlace oculto</u></em>"><u>View Favorites</u></a>[/wpv-conditional]
Thanks,
Chuck
Did you register this new shortcode in third party shortcode arguments? If not, go to Toolset > Settings > Front-end content tab and type "toolset_is_favorite" in the Third-party shortcode arguments input field, then press Return or Enter. This should allow you to use this shortcode in a conditional effectively. If that doesn't help, please place the shortcode outside the conditional to see if it's returning a 0 or 1 correctly. If not, double-check the field slug for accuracy, and check to see if wpv-post-id returns the expected ID here.
I was able to get the message to display buy using "0", but I'm running into another problem when there are multiple items added to the favorites view.
Screenshot showing multiple items in Favorites View: enlace oculto
Screenshot showing result after one item removed: enlace oculto
It should be showing the "Remove from Favorites" button.
Message after form is submitted:
<div class="mam">[wpv-conditional if="( [toolset_is_favorite id='[wpv-post-id]'] eq '0' )"]Added to Favorites.<a href="<em><u>enlace oculto</u></em>"> <u>View Favorites</u></a>[/wpv-conditional]</div>
Thanks,
Chuck
[wpv-conditional if="( [toolset_is_favorite id='[wpv-post-id]'] eq '0' )"]Added to favorites.[/wpv-conditional]
This should not work, because "0" would indicate the item is NOT a favorite, and "Added to favorites" indicates that the item IS a favorite. So something else is going on here. Let's try to figure out where the issue is. In the message shown after the form is submitted, place the following code:
wpv-post-id: [wpv-post-id]
toolset_is_favorite: [toolset_is_favorite id='[wpv-post-id]']
conditional: [wpv-conditional if="( [toolset_is_favorite id='[wpv-post-id]'] eq '1' )"]It is a favorite[/wpv-conditional]
I input this code as the message to be displayed after form is submitted:
[wpv-conditional if="( [toolset_is_favorite id='[wpv-post-id]'] eq '1' )"]It is a favorite[/wpv-conditional]
I get a warning and no message is displayed when clicked:
"Warning: Creating default object from empty value in /home/artillio/public_html/motorfieds.com/wp-content/plugins/cred-frontend-editor/application/models/form/data.php on line 56"
Screenshot: enlace oculto
I have no idea why that would be.
Thanks,
Chuck
I see, this is a separate issue that was introduced with the latest WP security update. Our developers pushed a fix earlier today. Please update to Types 2.2.18 and CRED 1.9.2.1 to resolve this problem.