Disable one radion button list options from many.

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

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

By gkornbluth - October 9, 2012

Hi Zick,
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.

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