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

Multiple Entries for selection lists?


  1. Dean
    Member

    What I'm trying to do is build a registration database for motorcycle races that our local club hosts. Our race timing software likes to see a race entry per race class selected. So if I have a single form, and the user selects 3 out of 10 checkboxes, can I get the software to create 3 entries? Sort of like, for each checkbox selected, insert a row into the database as an entry. Would this be easy to do?

    Posted 16 years ago #
  2. yuniar

    That would be 3 duplicated entries. Am I correct?


    MachForm Founder

    Posted 16 years ago #
  3. Dean
    Member

    Yes, that would be correct, 3 duplicated entries, one for each choice they made on the checkbox field. Of course if they chose 4 of those 10, then it would be 4 duplicated entries.

    Posted 16 years ago #
  4. yuniar

    Ok, let say you have a form with form_id = 4 and your checkboxes are having id element_3_1, element_3_2, element_3_3 ..and so on (view the HTML source of your form to see it)

    So, we're now having:
    form id = 4
    element id = element_3

    Edit your includes/post-functions.php, search around line 860 and you'll find this code:

    $query = "INSERT INTO ap_form_{$form_id} ($field_list) VALUES ($field_values);";
    do_query($query);


    Replace that code with this one:

    $query = "INSERT INTO ap_form_{$form_id} ($field_list) VALUES ($field_values);";
    if($form_id == 4){
    	$total_checkbox = 0;
    	foreach ($user_input as $element_name=>$value){
    		if((strstr($element_name,'element_3') != false) && !empty($value)) {
    		 $total_checkbox++;
    		}
    	}
    
    	for ($i=0;$i<$total_checkbox;$i++){
    		do_query($query);
    	}
    }else{
    	do_query($query);
    }


    Adjust the code above with your own form_id and element_id.
    That should do what you need.

    Let me know if you have any trouble.


    MachForm Founder

    Posted 16 years ago #
  5. Dean
    Member

    Yuniar, you rock! Your customer support is awesome, and I will be recommending your software to anyone who needs forms!

    Posted 16 years ago #

RSS feed for this topic

Reply