Keeping focus on radio button & related echo during page reload

Hello, Everyone. Brand new user here. :slight_smile:

I’m working on a WordPress-based site which is based on the S2 Member Pro, BuddyPress and GeoDirectory plugins. I’ve been working with the S2 developers, however, I think I might have surpassed their PHP support. That being said, I’m hoping I might get some insight from you all.

Basically, S2 allows for custom post types. My site has several categories and I’m planning to offer four types of membership levels in each category. I’ve created an S2-based page which allows for multiple forms. I’m trying to pass along a category attribute which the page will “remember” when a member chooses their membership level. Both the category and membership forms are taking place on the same page. Basically, the member will choose which category they wish to post their directory listing to and hit “submit.” Upon submission, the form will keep their category level and the member will then choose which membership level to join. So, a member might choose “category1” and then choose “category1_enhanced” for an enhanced listing within the Category #1 section. Then, when the member pays they are redirected back to their BuddyPress profile page where there will be a dynamic link to allow the member to submit a “category1_enhanced” level listing. This is all working as should be expected, however, except I cannot get the dynamic membership level to pass along to the sign up form.

Here’s my code:

[code]<?php
session_start();
$category = array();
if(isset($_POST[‘buttons’])) {
foreach($_POST as $key => $value) {
$category[$key][$value] = “checked”;
}
} elseif(isset($_SESSION[‘category’])) {
$category = $_SESSION[‘category’];
}

echo ‘<form method=“post” action=’.$_SERVER[‘php_self’].’>
';
echo '<input type=“radio” name=“buttons” value =“Brewery” ‘.$category[‘buttons’][Brewery].’ >Brewery

';
echo '<input type=“radio” name=“buttons” value =“Cidery” ‘.$category[‘buttons’][Cidery].’ >Cidery

';
echo '<input type=“radio” name=“buttons” value =“Winery” ‘.$category[‘buttons’][Winery].’ >Winery


';
echo ’
';
echo ’


';
echo '[s2Member-Pro-Stripe-Form register=“1” level=“0” ccaps="<?php echo esc_attr($category); ?>_free" desc=“Basic <?php echo esc_attr($category); ?> - Free!” custom=“www.cheersva.org” tp=“0” tt=“D” captcha=“clean” /]
';
$_SESSION[‘category’] = $category;
?>[/code]

As you can see, if a member selects “Brewery,” that value should pass along to the ccaps function which sets the listing level at brewery_free and also dynamically prints the “Basic Brewery - Free!” title. When I change the radio buttons and click the button, the page successfully refreshes and keeps the focus on the newly selected radio button, however, the ccaps and title never populate.

I think my issue lies at the echo statement where I’m using esc_attr. I also attempted $_POST and print but to no avail.

If anyone has any insight on what I’m doing wrong, I’d appreciate it.

Thanks much, in advance!

Regards,
Kory

This is one issue,

[php]echo ‘[s2Member-Pro-Stripe-Form register=“1” level=“0” ccaps="<?php echo esc_attr($category); ?>_free" desc=“Basic <?php echo esc_attr($category); ?> - Free!” custom=“www.cheersva.org” tp=“0” tt=“D” captcha=“clean”’;[/php]
You have php tags within a php echo. That is bound to fail.

To make you web page a little more secure I would do the following:

[php]$phpSelf = filter_input(INPUT_SERVER, ‘PHP_SELF’, FILTER_SANITIZE_URL);
$path_parts = pathinfo($phpSelf);
$basename = $path_parts[‘basename’]; // Use this variable for action=’’:
$pageName = ucfirst($path_parts[‘filename’]);[/php]

then in your HTML form ->

[php] echo ';[/php]

Thanks for your replies, Strider64 & astonecipher. I greatly appreciate it.

Strider64, will your suggestion of making my page a bit more secure help with the reload issue or is that additional feature?

astonecipher, I’m not exactly sure what the syntax for the echo should be if I remove the embedded PHP call (I had a feeling that’s part of the issue but am not sure how to resolve it). I tried the following but the echo simply displays raw HTML output and not the dynamic category name I had hoped for:

echo '[s2Member-Pro-Stripe-Form register="1" level="0" ccaps="" desc="Basic {echo esc_attr($category);} - Free!" custom="www.cheersva.org" tp="0" tt="D" captcha="clean" /]

Do you have any other suggestions?

Thanks again.

Regards,
Kory

I have recently learned and verified the best option to submitting to the same page is to leave the form action out altogether.

Could you offer a better way for me to achieve this functionality, Kevin? I’m certainly not married to utilizing the form action, of course. I’m just not sure the best tack to take.

Thanks much.

Regards,
Kory

How about we go the clean easy route?

[php]<?php
if ($_SERVER[“REQUEST_METHOD”] == “POST”)
{
if (!empty($_POST[‘buttons’]))
{
echo “[s2Member-Pro-Stripe-Form register=‘1’ level=‘0’ ccaps=‘esc_attr({$_POST[‘buttons’]})_free’ desc=‘Basic esc_attr({$_POST[‘buttons’]}) - Free!’ custom=‘www.cheersva.org’ tp=‘0’ tt=‘D’ captcha=‘clean’]”;
}
}
?>

>Brewery
>Cidery
>Winery
[/php]

You got me really far, Kevin! Thanks so much! I’m really, really close. Based on some modifications below, I added a multi-form option. So, the user will choose the category which will then populate the related form under the radio buttons. However, when I select a different level within the dynamic dropdown box, the page reverts back to the radio buttons. Can you offer a suggestion on how I may keep the focus on the category, e.g. the radio button if the user selects a different level from the dropdown menu? Here’s my new code thanks to your much appreciated input:

[code]
<input type=“radio” name=“buttons” value =“Brewery” <?= isset($_POST['buttons']) && $_POST['buttons'] == 'Brewery' ? 'checked' : '' ?>>Brewery

<input type=“radio” name=“buttons” value =“Cidery” <?= isset($_POST['buttons']) && $_POST['buttons'] == 'Cidery' ? 'checked' : '' ?>>Cidery

<input type=“radio” name=“buttons” value =“Winery” <?= isset($_POST['buttons']) && $_POST['buttons'] == 'Winery' ? 'checked' : '' ?>>Winery

<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { if (!empty($_POST['buttons'])) { echo <<[/code]

Thanks again!

Regards,
Kory

Are each one of those stripe results tied to a specific button? If so, what goes to what?

You would just do an if on each one if so.

if (button == brewary){
echo brewary stripe code
}

if (button == cidery){
echo cideryy stripe code
}

etc…

Is this for the same site that is shutting down?

I would go a different route than above, but… It works

Well, sort of. Basically, there are going to be different categories, like so:

[ul][li]Breweries[/li]
[li]Cideries[/li]
[li]Wineries[/li]
[li]etc.[/li][/ul]

There are also four different levels:

[ul][li]Basic - Free[/li]
[li]Enhanced[/li]
[li]Enhanced w/ Calendar Submissions[/li]
[li]Featured w/ Calendar submissions[/li][/ul]

That being said, a member might submit a Basic Brewery listing, another member might submit an Enhanced Brewery listing, another member might submit an Enhanced Winery listing, etc.

The Stripe functionality is part of the S2 Member Pro plugin. I’m using Custom Capabilities or CCAP codes to define the membership levels via a blend of the categories and levels. This is because the underlying directory, based on the GeoDirectory plugin, uses Custom Post Types for the Breweries, Cideries, Wineries, etc. So, when a member joins, if they choose to sign up at the Enhanced Winery w/ Calendar Submissions, for example, their CCAP code would be winery_enhanced_events. That, in turn, feeds into their BuddyPress plugin profile page where they’ll be able to add and edit their respective Enhanced Winery w/ Calendar Submission-level GeoDirectory listing. All the GeoDirectory listing submission pages are protected behind the S2 Member Pro plugin, meaning the member account has to have that right attached to be able to access the respective listing submission page. They get that access via this form here we’ve been working on.

A very long-winded answer to your question. In summary, I think I can use your suggested if == syntax with the form but I’m also thinking I might just want to use additional radio buttons for the levels. I’ll keep working with it. I’m pretty close, I think.

Thanks again!

Regards,
Kory

Actually, sort of, astonecipher, but hopefully, not for long. I put the site on a hiatus for about eight months due to work/life obligations that got in the way. It was more or less a hobby site that morphed into a monster, consuming about four to five hours a day without any revenue. At one point, the site had over 1,000 listings in its former directory codebase and was averaging about 1,500 to 2,000 unique visits a day.

I’m completely revamping the backend to make the site more self-servicing while earning a bit of revenue, at a minimum to cover its expenses and, hopefully, then some. That’ll reduce the amount of time I need to devote to it on a day-to-day basis as well. I just haven’t changed the static page you see on it now, although, the WordPress-based site is currently running behind that static page and is accessible after one logs in. That’s where this form resides in its current testing state. Needless to say, all my questions and everyone’s continued input is certainly not wasted; quite the contrary, it’s very much appreciated and will certainly be put to good use, hopefully shortly. :slight_smile:

If you’d like to share the route you would have gone, I’m all ears, of course.

Thanks again!

Regards,
Kory

You are better off with two dropdowns instead of all those radio buttons.

[code]
Category

Breweries Cideries Wineries

Level

Basic - Free
Enhanced
Enhanced w/ Calendar Submissions
Featured w/ Calendar submissions

[/code]

Hi, Kevin. Thanks for your continued suggestions. I worked with your latest suggestion for an hour or so but am having a difficult time wrapping my head around the additional dropdown functionality. I just sent you a PM as well.

Thanks much!

Regards,
Kory

Sponsor our Newsletter | Privacy Policy | Terms of Service