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

Post Data to Table?


  1. johnburke
    Member

    Is it possible to post some of the data that is asked for in a form onto a table?

    I created a form that gets some basic "member" information and I am looking for a way to populate some of those fields, not all, onto a table.

    For example, I would like to be able to grab the data from the form and have a table of Name, Email, etc.

    Is this possible?

    Posted 16 years ago #
  2. redityo

    Hi,

    It's possible by editing your "post-functions.php", but maybe it will not work for some condition. In here I assume you have form id = 12 and 3 elements with information :

    1. name element (element_1)
    2. text 1 (element_2)
    3. text 2 (element_3)

    let say you want to save those data to "tb_test" table with field name (names,text1,text2). Now go to around line 939 ~ 951 you will find these code :

    foreach ($table_data as $key=>$value){
    
    	if($value == ''){ //don't insert blank entry
    		continue;
    	}
    	$value		    = mysql_real_escape_string($value);
    	$field_list    .= "<code>$key</code>,";
    	$field_values  .= "'$value',";
    
    	if(!empty($value)){
    		$has_value = true;
    	}
    }

    you can replace with this one

    //look up data
    $custom_lookup['element_1_1'] = 'names';
    $custom_lookup['element_1_2'] = 'names';
    $custom_lookup['element_2'] = 'text1';
    $custom_lookup['element_3'] = 'text2';
    
    foreach ($table_data as $key=>$value){
    
    	if($value == ''){ //don't insert blank entry
    		continue;
    	}
    	$value		    = mysql_real_escape_string($value);
    
    	$field_list    .= "<code>$key</code>,";
    	$field_values  .= "'$value',";
    
    	//build query for custom data
    	if (array_key_exists($key, $custom_lookup) && $form_id = 12) {
    		$custom_data[$custom_lookup[$key]] .= "$value ";
    	}
    
    	if(!empty($value)){
    		$has_value = true;
    	}
    }

    after that go to line 1019, you'll see this code :

    $query = "INSERT INTO <code>ap_form_{$form_id}</code> ($field_list) VALUES ($field_values);";

    replace with this

    if ($form_id == 12 && !(empty($custom_data)) ) {
    	$custom_field = '';
    	$custom_values = '';
    
    	foreach ($custom_data as $key=>$value) {
    		$custom_field .= "<code>$key</code>,";
    		$custom_values .= "'".trim($value)."',";
    	}
    
    	$custom_field = substr($custom_field,0,-1);
    	$custom_values = substr($custom_values,0,-1);
    
    	$custom_query =  "INSERT INTO <code>tb_test</code> ($custom_field) VALUES ($custom_values);";
    	do_query($custom_query);
    }

    make sure you look up the element_id with "tb_test" column properly, you can see in those code like this :

    //look up data
    $custom_lookup['element_1_1'] = 'names';
    $custom_lookup['element_1_2'] = 'names';
    $custom_lookup['element_2'] = 'text1';
    $custom_lookup['element_3'] = 'text2';

    MachForm Support

    Posted 16 years ago #

RSS feed for this topic

Reply