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
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.
Just an idea based on something that I did that was similar.
There’s a recipe in my CMSB Cookbook www.thecmsbcookbook.com called CREATE A HIT COUNTER USING THE BUILT IN INCREMENTCOUNTERFIELD FUNCTION that you could use to count the number of registrations that have been made for a particular golf event. (the counter was incremented on loading this detail page)
Then you might be able to use an if statement in the foreach loop to not show the particular button for the golf signup if the predetermined registration amount was exceeded.
Not exactly the same, but here’s the detail page code I used for a special event sign up to put folks on a wait list if the registration was exceeded.
<?php incrementCounterField('registration', 'current_registration', $registrationRecord['num']); ?>
<?php if ($registrationRecord['wait_list_allowed'] =='1' && number_format($registrationRecord['current_registration'] > $registrationRecord['maximum_registration'])): ?>
<span class="body-text-bold">You are on the wait list for <?php if ($registrationRecord['type']=='Course'): ?>course<?PHP else: ?>event<?php endif; ?> ID number: <?php echo $registrationRecord['id_number'] ?>. You will be notified at the e-mail you provided as soon as there is an opening.</span><span class="body-text"> <?php echo $registrationRecord['wait_list_rules'] ?></span><br/><br />
<?php else :?>
Sorry, the course is full, please choose another section.
<?php endif ?>
Hope it sparks some ideas.
Jerry Kornbluth
The first CMS Builder reference book is now available on-line!
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [zick] Disable one radion button list options from many.
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
PHP Programmer - interactivetools.com
Re: [greg] Disable one radion button list options from many.
By Mikey - October 10, 2012
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.
Thanks
PHP Programmer - interactivetools.com
Re: [greg] Disable one radion button list options from many.
By Mikey - October 10, 2012
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