We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Check a radio button if it's selected.

How Do I?

deswork's avatar
deswork
93 posts
about 9 years ago
deswork's avatar deswork

Hi,

I have the following code to create a list of radio buttons.

What I want is when a particular radio button is selected and a form is submitted I would like the users selected choice to be rememberd.

{exp:channel:categories category_group="7" show="not 54"}
                        <input type="radio" name="categories[]" value="{category_id}" {checked}> {category_name}
                    {/exp:channel:categories}

I can’t seem to find out how to acheive this. Could someone please point me in the right direction.

Thanks

Wayne.

       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
about 9 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

Hi there! Try the following:

{exp:channel:categories category_group="7" show="not 54"}
<input type="radio" name="categories[]" value="{category_id}" {if active}checked{/if}> {category_name}
{/exp:channel:categories}
       
deswork's avatar
deswork
93 posts
about 9 years ago
deswork's avatar deswork

Hi, Thanks for suggestion, I’ve tried it and it’s not keeping the radio button check after submitting the form.

I have managed to get what I need by enabling PHP in the tempate and using the code below.

if(isset($_POST['submit'])){
                $selected_val = $_POST['categories'];  // Storing Selected Value In Variable
            }else{
                $selected_val = "46";

 <input type="radio" name="categories" value="{category_id}"<?php if($selected_val == {category_id}) echo" checked" ?>> {category_name}

            }

Am I missing something or should this be possible natively?

Thanks

       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
about 9 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

For that purpose, if you want to avoid PHP in the template you may want to check out Mo’ Variables

       
deswork's avatar
deswork
93 posts
about 9 years ago
deswork's avatar deswork

Thanks for that, looks like it will do what I need.

Regards

Wayne.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.