This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 3

Limit drop down options once they have been selected on a form submission


  1. akerr
    Member

    I see you can limit the number of form submissions as a whole, but I'm wondering if there's a way to disable an option in a drop-down list once a user has made a submission for that particular time, so for instance:

    Select list options
    8am
    9am
    10am
    11am

    So once 8am and 9am has been submitted those options would no longer show-up on the form.

    Thanks for your time.

    Posted 10 years ago #
  2. redityo

    You can not disable the option or disable it, but you can create custom validation to the selected drop down option.
    So if someone select the option which already submitted, the form would show an error.

    To do this, you need to customize "includes/post-functions.php" file, I assume your form id is "25481" and the drop down element id is "1".
    Then go to around line 1657, you will see these code :

    $process_result['form_redirect']  = $form_redirect;

    then put these code above that line

    if ($form_id == 25481) {
    	if (!empty($table_data['element_1'])) {
    		$query = "select count(id) total_entry from " . MF_TABLE_PREFIX . "form_{$form_id} where element_1=? and status=1";
    		$params = array($table_data['element_1']);
    
    		$sth = mf_do_query($query,$params,$dbh);
    		$row = mf_do_fetch_result($sth);
    		if(!empty($row['total_entry'])){
    			$error_elements['1'] = 'Sorry, but this option already selected.';
    		}
    	}
    
    }

    you need to change the id's number with yours.


    MachForm Support

    Posted 10 years ago #
  3. akerr
    Member

    Thanks for the followup.

    As a feature request, 123 Contact Form has a neat little tool here: http://www.123contactform.com/docs/how-to-limit-the-number-of-times-an-option-is-selected/

    Which allows you to select a number of times a field can be selected, thanks for the great product!

    Posted 10 years ago #

RSS feed for this topic

Reply