I am using a Single Record Form
I have a AJAX custom Button called LoadValues
In the PHP segment of the LoadValues button if I put {m_dsr_month} = ‘January’;, by clicking the button the Form Field m_dsr_month gets the value ‘January’ and also shows it on the form
But my requirement is slightly different.
I have a form called form_user_log which has columns like , user_name, , u_log_month, scriptcase generated
This form has 2 fields user_name, u_log_month.
I have an an excel file which has 2 columns u_name and u_month.
I have a mySql table called userlog_excelcolumns with all the field names from the user_log table and column letters from the excel file . So the table has column tblFields = u_log_month.against which will be column letter ‘B’ as in the Excel Table. Same for the user_name which will have Column Letter “A”
Now the AJAX button will have to do the following
- Read the Excel File data
- Based on the column being read, look up the userlog_excelcolumns table matching the column Letter, get the column tblFields Value in to php Variable generated_form_field.
- Set the Form Field similar to the generated_form_field
For example
Step 2 returns u_log_month. Then I have to set the value read from Excel into Form Field {u_log_month}.
Step 1 and 2 is working fine
Step 3 works only if I use a condition statement like
if generated_form_field == ‘u_log_month’ {u_log_month} = excelValue;
But again, i am using a for loop, the excel has 44 columns , the for loop iterates each column. So I want to generate the Field Name and set value instead of using 44 IF statements
Can some one help
Tried Code
$form_fields = $this->nmgp_dados_form; // Create an array $form_fields of all the fields in the form
$form_fields[strtolower($fieldName)] = $value;