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
concantenate two fields to fill another field
Started 15 years ago by drbobtampa | 3 posts |
-
Suppose form-user enters text field A= "XYX" and text field B= "123".
I want to populate a hidden, administrator-only third field, C, like this:
concatenate("code"+A+B) to yield text field C= "codeXYZ123".What code and which php can I do that in?
As a bonus question, how can I convert "XY Z" into "XYZ) (that is, remove blanks at the same time)?Many thanks!
Posted 15 years ago # -
You need to edit "includes/post-functions.php" file to do this. Let say you have this information :
Field "A" element id = 1
Field "B" element id = 2
Field "C" element id = 3
Form id = 53Then go around line 939 ~ 951, you will see this 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; } }
replace those code with this one
$temp = ''; $temp_field_list= ''; $temp_field_values = ''; if($form_id == '53') { $element_1_data = mysql_real_escape_string(ereg_replace(' ','',$table_data['element_1'])); $element_2_data = mysql_real_escape_string(ereg_replace(' ','',$table_data['element_2'])); if (array_key_exists('element_3',$table_data)) { $temp = 'code' . $element_1_data . $element_2_data ; } else { $temp = 'code' . $element_1_data . $element_2_data ; $temp_field_list = "<code>element_3</code>,"; $temp_field_values = "'".$temp."',"; } } foreach ($table_data as $key=>$value){ if($value == '' && ($form_id != '53' && $key != 'element_3')){ //don't insert blank entry continue; } $value = mysql_real_escape_string($value); $field_list .= "<code>$key</code>,"; if ($form_id == '53' && $key == 'element_3') $field_values .= "'$temp',"; else $field_values .= "'$value',"; if(!empty($value)){ $has_value = true; } } if ($form_id == '53' && $temp_field_values != '') { $field_list .= $temp_field_list; $field_values .= $temp_field_values; }
make sure you adjust form id and element id number with yours. Also it will remove "space" character in field "A" or field "B".
MachForm Support
Posted 15 years ago # -
Hello, I tried this and i get the following error :
INSERT INTO
ap_form_1
(element_1,element_2,element_3,ip_address,date_created) VALUES ('2583','5900','code25835900','84.198.91.208','2011-01-25 08:20:09'); Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'element_1,element_2,element_3,ip_ad' at line 1Can you help me ?
Posted 13 years ago #
Reply
You must log in to post.