Disable one radion button list options from many.

6 posts by 3 authors in: Forums > CMS Builder
Last Post: October 10, 2012   (RSS)

By Mikey - October 9, 2012

I need some help and haven't a clue how to even begin to make this happen. So here's what's happening... I've got a register for an event form that has a Friday Morning Activity option for various activities that are Radio Button List Options within CMS Builder. But the "Golf" option has been filled to capacity and now I need to disable "Golf" from being an available option, without deleting it from my Radio Button List and database.

So I need to disable the user's ability to see/chose the "Golf" radio button option or make the "Golf" option unavailable, greyed out or something. Below is the code used to power this radio button... anyone have some suggestions on how to disable the "Golf" option on the front-end where the user registers for the event?

Friday Morning Activity Radio Button Options Are:
• Golf
• Tennis
• Boating
• Fishing


// load record from 'accounts'
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'where' => '', // load first record
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$accountsRecord = @$accountsRecords[0]; // get first record
if (!$accountsRecord) { dieWith404("Record not found!"); } // show error message if no record found




<?php $fieldname = 'friday_morning_activity'; ?>
<?php $idCounter = 0; ?>
<?php foreach (getListOptions('accounts', $fieldname) as $value => $label): ?>
<?php $id = "$fieldname." . ++$idCounter; ?>
<span class="paragraph"><input type="radio" name="<?php echo $fieldname ?>" id="<?php echo $id ?>"
value="<?php echo htmlspecialchars($value) ?>" <?php checkedIf(@$_REQUEST[$fieldname], $value) ?> />
<label for="<?php echo $id ?>"><?php echo htmlspecialchars($value) ?></label><br/> </span>
<?php endforeach ?>



Many thanks to anyone who can help me out with this one...
Zick

Re: [zick] Disable one radion button list options from many.

By gregThomas - October 10, 2012

Hi,

If I wanted to disable just one field I would use an in if statement to add disabled="disabled" to the Golf input box.

Something like this should work:

<?php $fieldname = 'friday_morning_activity'; ?>
<?php $idCounter = 0; ?>
<?php foreach (getListOptions('accounts', $fieldname) as $value => $label): ?>
<?php $id = "$fieldname." . ++$idCounter; ?>
<span class="paragraph"><input type="radio" name="<?php echo $fieldname ?>" <?php echo ($value=='Golf')? 'disabled="disabled"' :''; ?> id="<?php echo $id ?>"
value="<?php echo htmlspecialchars($value) ?>" <?php checkedIf(@$_REQUEST[$fieldname], $value) ?> />
<label for="<?php echo $id ?>"><?php echo htmlspecialchars($value) ?></label><br/> </span>
<?php endforeach ?>


I'm assuming that the $value variable contains the title of the activity. So you might have to change it a bit to get it to work.

Cheers
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Disable one radion button list options from many.

By Mikey - October 10, 2012

Hey Greg,
the Value is Golf as seen below when you view the HTML source code produced by the site page. I applied your solution, but the Golf radio button still appears and is selectable. Any other suggestions, or is it possible there's a little something missing from your solution to get this to function? ... and thanks for the help!!!!
Zick

HTML source code produced by PHP page:
<span class="paragraph"><input type="radio" name="friday_morning_activity" id="friday_morning_activity.1"
value="Golf" />
<label for="friday_morning_activity.1">Golf</label><br/> </span>



Hi,

If I wanted to disable just one field I would use an in if statement to add disabled="disabled" to the Golf input box.

Something like this should work:

<?php $fieldname = 'friday_morning_activity'; ?>
<?php $idCounter = 0; ?>
<?php foreach (getListOptions('accounts', $fieldname) as $value => $label): ?>
<?php $id = "$fieldname." . ++$idCounter; ?>
<span class="paragraph"><input type="radio" name="<?php echo $fieldname ?>" <?php echo ($value=='Golf')? 'disabled="disabled"' :''; ?> id="<?php echo $id ?>"
value="<?php echo htmlspecialchars($value) ?>" <?php checkedIf(@$_REQUEST[$fieldname], $value) ?> />
<label for="<?php echo $id ?>"><?php echo htmlspecialchars($value) ?></label><br/> </span>
<?php endforeach ?>


I'm assuming that the $value variable contains the title of the activity. So you might have to change it a bit to get it to work.

Cheers

Re: [zick] Disable one radion button list options from many.

By gregThomas - October 10, 2012

I've just done some local testing and this should work as far as I can tell. The radio button should still be visible, but greyed out so that you cannot select it. You could try wrapping the $value in the if statement I added with the htmlspecialchars function. Would it be possible to send me a link to the page that this form is being displayed on?

Thanks
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Disable one radion button list options from many.

By Mikey - October 10, 2012

Odd - now it's working perfectly, just as you instructed in the original suggestion. I guess it may have been a server thing. But here's what I did, I applied your suggestion, then deleted the original file on the hosting server. Refreshed my page to produce an error page not found, uploaded the file with your solution, refreshed the page again and the record is now greyed out and inactive as an option.

Thanks for the suggestion, simple and effective solution and excellent support on this Greg!!!!
Zick

I've just done some local testing and this should work as far as I can tell. The radio button should still be visible, but greyed out so that you cannot select it. You could try wrapping the $value in the if statement I added with the htmlspecialchars function. Would it be possible to send me a link to the page that this form is being displayed on?

Thanks