Appnitro Software Forums » MachForm 2

Checkboxes - php disable


  1. tobyp
    Member

    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-5pm

    The 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 8 months ago #
  2. redityo

    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 8 months ago #
  3. Juan
    Member

    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 5 months ago #
  4. Juan
    Member

    any idea?
    thx

    Posted 5 months ago #

RSS feed for this topic

Reply