This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 2
Checkboxes - php disable
Started 13 years ago by tobyp | 7 posts |
-
Hi
I'm using Machforms to create a booking system for a one day event with three sessions and a limited amount of places available for each session submitted from one form using a checkbox
Checkbox1 - session1 - 9-12pm
Checkbox2 - session2 - 12-1pm
Checkbox2 - session3 - 1-5pmThe client wants the checkboxes to be disabled as and when each individual session is booked out.
Not being a programmer I've achieved it by using this db query on the php page that i have my embed code for the form .
Then I've used a Javascript function to disable it and change the class on the label. This works ok but it's not ideal as it's clientside, is there anyway to do this with PHP?
Thanks for your help.
$query = "SELECT COUNT(element_5_1) AS element_5_11 FROM ap_form_2
WHERE element_5_1='1' ";
$result = do_query($query);
$row = do_fetch_result($result);
if ($row[0] >= 10) {
echo 'there are equal or more than 10 entries in 9am-12pm';
echo '<script type="text/javascript">disableCbx1()</script>';
}
Posted 13 years ago # -
I think you're on the correct path, You can use java script code to disable the check box option. However, you can try the method from me :
1. Edit "includes/view-functions.php" file and go to line 1831, you will see this text .
//If you would like ......
then put these code above that line
if ($form_id == 11) { $query = "select sum(element_1_1) sum_1, sum(element_1_2) sum_2, sum(element_1_3) sum_3 from ap_form_{$form_id}"; $result = do_query($query); while($row = do_fetch_result($result)){ if ($row['sum_1'] > 2) { $disable_checkbox_1 = ' $("input#element_1_1").attr("disabled", true); '; } if ($row['sum_2'] > 2) { $disable_checkbox_2 = ' $("input#element_1_2").attr("disabled", true); '; } if ($row['sum_3'] > 2) { $disable_checkbox_3 = ' $("input#element_1_3").attr("disabled", true); '; } } $custom_js =<<<EOT <script type="text/javascript" src="js/jquery/jquery-core.js"></script> <script type="text/javascript"> $(document).ready(function() { {$disable_checkbox_1} {$disable_checkbox_2} {$disable_checkbox_3} }); </script> EOT; }
2. Go to line 1871 for this code
{$calendar_js}
and change it to
{$custom_js} {$calendar_js}
That would disable check box options, if it's selected more than 2. In there I assume your form id is 11 and the check box option is 1 (element_1_1,element_1_2,element_1_3).
You need to change those id with yours.
MachForm Support
Posted 13 years ago # -
This is great. thx
How could i set a message that be displayed when client try to click on a checkbox with the maximum number of entries allowed? I mean when ($row['sum_1'] > 2 then disable checkbox and alert to user "top number of entries has been reached!"
Thank you very much and sorry for my english .... ;o)Posted 13 years ago # -
any idea?
thxPosted 13 years ago # -
Would this same concept apply for version 3.3? I need to disable an option once it reaches 16 users. I have a workshop sign up form, it lists a dozen workshops, but each can only host 16 participants.
Posted 11 years ago # -
Does anyone have a fix for this that works with 3.5?
Posted 11 years ago # -
I have the same problem, but my radiobuttons stand in relationship with different dates.
You choose a date from calender and in cooparation with different relationship rules machform shows different radiobuttons.
You can check this here:
a
http://www.klinikumdo.de/machform/view.php?id=5901a
for dates after 1th january 2014.I need a limit of 15 for each combination - is it possible? I Machform Version 3.4 Thanks a lot
Posted 11 years ago #
Reply
You must log in to post.