Skip Navigation

[Resolved] Favorites view

This support ticket is created 7 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 45 replies, has 3 voices.

Last updated by Christian Cox 7 years ago.

Assisted by: Christian Cox.

Author
Posts
#581174

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.

#581194

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: hidden link
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

#581277

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");
});
#581321

1. Would a toggle work as a solution, instead of a button? Something like this: hidden link

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

#581673

1. Would a toggle work as a solution, instead of a button? Something like this: hidden link
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.

#581787

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: hidden link

Thanks,
Chuck

#581997

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.

#582204

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>hidden link</u></em>"><u>View Favorites</u></a>

But that message doesn't make sense to display if someone clicks "Remove from Favorites"

Thanks,
Chuck

#582473

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]
#583168

I added your code, but now the Favorites button disappears when clicked:
Button before clicked: hidden link
button after clicked: hidden link

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>hidden link</u></em>"><u>View Favorites</u></a>[/wpv-conditional]

Thanks,
Chuck

#583595

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.

#583765

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: hidden link
Screenshot showing result after one item removed: hidden link
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>hidden link</u></em>"> <u>View Favorites</u></a>[/wpv-conditional]</div>

Thanks,
Chuck

#584369
[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] 
#585014

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: hidden link

I have no idea why that would be.

Thanks,
Chuck

#585512

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.