Stripe Cancellation Form autoFocus

Ugh! Sorry for the annoyance, not sure what was up with that. I just made it public. Thanks again for looking!

I took a look at the code and it looks like it is jumping to the form because it is evaluating whether the user is logged in or not AND if the user is not logged in it is displaying the “You must log in to cancel your account”. So the display of the error message is triggering the autoscroll.

To get around this try the following (should work but no promises…it’s an educated guess):

wrapper the s2member shortcode with [s2if]…e.g.

[s2If is_user_logged_in()]
    ...your form...
[/s2If]
1 Like

Thank you so much, that information is very helpful. Unfortunately, that solution didn’t fix it, but it’s good to know what’s causing it. I will look further into that, thank you!

Hmmm…it should have worked. I may be wrong as to the cause. It could be the captcha.

Can you put the nested form up on your test site so I can take a look at it.

[s2If is_user_logged_in()]
    ...your form...
[/s2If]

I realized it was because I was logged in! So it did work, thank you so much!

Which solves it for many cases, but then it’s still weird if they navigate to that page and they are logged in but not looking to unsubscribe. Do you know if there’s a way to make it so that alert doesn’t autoscroll?

Thanks again for all your help!

Glad it worked :slight_smile:

If the user is logged in then there is no message. No message, no auto-scroll.

If the user is not logged in then there is no form since the [s2If is_user_logged_in()] [/s2If] wrapper hides it.

When the user is not logged in, yes it works perfectly.

If they are logged in, but not as a paid user, it gives an alert saying “Nothing to cancel. You’re NOT a paid Member.” (sg attached)

If they are logged in as a paid member, but they have already cancelled, the alert says “Nothing to cancel. You have NO recurring fees.” (sg attached)

The thought just occurred to me that I could use the s2member conditional logic to weed out those logged in users not in an s2member role (mainly Customer role), so the only time the alert would get served then is if they were a sub who already unsubscribed. That would be a pretty small amount of cases, but I’m still hoping to avoid that happening if possible. Do you have any thoughts on how to avoid or work around that case?

Thanks again for all your help!

The only way to make it foolproof would be to create a separate page for the unsubscribe form and put a link to it on this page. So the process becomes a two-keypress process (press link on this page + press button on next page). Given that it happens infrequently this would be considered acceptable UX.

1 Like

Actually…the following should work:

[s2If is_user_logged_in()]

[_s2If current_user_can(access_s2member_level1)]
    ...your form...
[/_s2If]

[/s2If]

NOTE: Notice the ‘_’ character in the inner shortcode. This is required.
NOTE2: you can use [_s2If current_user_can(access_s2member_level0)] if your model supports a free user level.

1 Like

I actually did get something similar to that work, I just used [s2If current_user_can(access_s2member_level1)], and that works great for that case.

I’m wondering if I can somehow use s2member_auto_eot_time to determine if the user already has an EOT and then don’t run the form if they do?

Something like, and I know this isn’t correct (it actually crashed my site haha) but:
[s2If current_user_can(access_s2member_level1) AND s2member_auto_eot_time(!= ’ ')]

I’ve been looking at this post Display content based on time until EOT, and I think I can use something similar to do what I want. From what I understand from this post, it seems like maybe I can’t do what I want with s2 conditionals and need to use PHP instead. But I don’t understand where in the template I would put the conditional.

Something like:
<?php
$eot_time = get_user_field(‘s2member_auto_eot_time’);
if (empty($eot_time)) {
}
?>

Does that even make sense?!

Do you have any thoughts on if I can use the EOT to achieve this either with the s2 conditionals or PHP?

I’m honestly about to give up and just put it on a separate page like you said, but I thought it was worth trying this one last thing.

Thanks again for all your help!

The double-nested one should work. Here are the cases:

  1. logged-in subscribed
  2. logged-in unsubscribed
  3. logged-out subscribed
  4. logged-out unsubscribed

The outer [s2If is_user_logged_in()] catches the first condition and the inner [_s2If current_user_can(access_s2member_level0)] catches the second condition.

So only combo #1 will display the form and with no warning message displayed so no auto-scroll.

Unfortunately, it still gives the alert if the user is logged in, has unsubscribed, but has not reached their EOT.

The alert says “Nothing to cancel. You have NO recurring fees.” (like the second sg above)

But you know what, I think it’s time for me to just give up and put it on a separate page.

Thank you again so much for all your help!

No worries. Interesting problem. The second page option is definitely the safest :slight_smile:

1 Like

I ended up just commenting out the alert in the template and it worked! Loads at the top of the page now. I realized that we were essentially trying to use conditionals to make the alert never appear, so I was like why not just get rid of the alert entirely.

Out of curiosity…what file are you referring to as “the template”?

stripe-cancellation-form.php

You’ll need to remember to re-patch your client site on every future s2member plugin update of course :slight_smile:

even though it’s in the child?

You are correct that, if you have the php file in your child theme, then it will survive s2member plugin updates as per https://s2member.com/kb-article/s2member-pro-forms/#toc-40ec91be.

BUT…you will still need to monitor every plugin update so that changes can be propagated to your copy.

Having said that…on reviewing the sourcecode in that file…the likelihood that anything will change in that file is very low.

So you should be 99.999% ok :slight_smile:

Ok cool, good to know. Thanks for the tip!