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

Require 2 of 5 multiple choice answers


  1. kflynn
    Member

    Hi,

    I've searched throught the forums a bit but can't find any info. I have a 5 choices in a multiple choice entry. I need the use to be able to select any two multiple choice answers

    Is this possible? I know I can use checkboxes but a user can then tick as many as they like.

    Any help greatly appreciated.

    Posted 15 years ago #
  2. redityo

    Hi,

    Multiple selection in "multiple choice" field it not possible, however you can use a "check box fiald" and add a custom validation to the field, so your user will allowed to fill 2 options. To do so, you need to edit "includes/post-functions.php" file, go to around line 614 ~ 624 you'll see these code :

    foreach ($all_child_array as $i){
    
    	//save old data into array, for form redisplay in case errors occured
    	$form_data[$base_element_name.$i]['default_value']   = $user_input[$base_element_name.$i];
    
    	//prepare data for table column
    	$table_data[$base_element_name.$i] = $user_input[$base_element_name.$i];
    
    }

    then replace the code with this

    $count_value = 0;
    foreach ($all_child_array as $i){
    
    	//save old data into array, for form redisplay in case errors occured
    	$form_data[$base_element_name.$i]['default_value']   = $user_input[$base_element_name.$i];
    
    	//prepare data for table column
    	$table_data[$base_element_name.$i] = $user_input[$base_element_name.$i];
    	if ($user_input[$base_element_name.$i] != '' or !empty($user_input[$base_element_name.$i])) {
    		$count_value++;
    	}
    }
    
    if ($count_value <> 2) {
    	if ($form_id == 5 && $element_id == 1)
    		$error_elements[$element_id] = 'You only need to choose 2 options';
    }

    in there I assume you've the field with element id 1 in form id 5, so you need to change those ID with yours


    MachForm Support

    Posted 15 years ago #
  3. pbadcock
    Member

    I've just tried this and the validation works fine, but when I correct and submit the form I get this message:

    Error sending email: SMTP Error: The following recipients failed: {element_2}
    Warning: Cannot modify header information - headers already sent by (output started at /home/ihbconli/public_html/machnew/machform2/includes/helper-functions.php:482) in /home/ihbconli/public_html/machnew/machform2/confirm.php on line 38

    However, the form submission is sent successfully, but the error message would put most users off.

    The same form sent fine before I did the alterations. I get the same error message if I attempt to send the form with the correct number of boxes ticked, if that helps.

    Can anyone help? I would love to use this addition,

    Peter

    Posted 15 years ago #
  4. redityo

    Hi Peter,

    From the error message :

    Error sending email: SMTP Error: The following recipients failed: {element_2}

    It seems the problem come from your mail setting. To fix it, try to re-set form mail setting and then try to submit the form again.

    Anyway if you restore the file to original state, will it solve the problem ? I think the problem not come from this customization


    MachForm Support

    Posted 15 years ago #
  5. pbadcock
    Member

    That sorted it, the fault was my end. Thanks very much for your help, sorry to trouble you.

    Posted 14 years ago #
  6. delvalcollege
    Member

    This is not working for me. I changed the element ID and form ID. The error message defaults to the "required" message, and when I select only one of the checkboxes, it still throws an error. Has something changed since this was posted?

    Posted 13 years ago #
  7. yuniar

    can you send us your modified file and let us know the URL to your form please?
    We'll check it.

    You can send it via email: customer.service [at] appnitro.com


    MachForm Founder

    Posted 13 years ago #
  8. chriskoeling
    Member

    Can someone tell me if this is still actual. I can imagine this will be an option in a new release?

    Posted 11 years ago #
  9. chriskoeling
    Member

    I see that is also a good solution: http://www.appnitro.com/forums/topic/limiting-checkbox-choices

    Posted 11 years ago #

RSS feed for this topic

Reply