How to display the last field which is user selected from form builder with the field name and field type?

自作多情 提交于 2019-12-01 13:49:09

问题


I am making the form builder and I have an input field which is called as Firstname, Lastname, Email, Iagree. Whatever user choose the field from the form builder page, all the elements will store in the database after clicking on a button.

Like I choose elements Firstname, Lastname, Email and iagree from my form builder page and saved it. In the database, it will store like below example

Now I update the form builder and I change the form elements. It's displaying like below image.

Using below query I am getting the last record updated

 SELECT form_id,form_elements,form_builder_type, update_date FROM `form_builder` WHERE form_id=1 AND form_builder_type='example' ORDER BY update_date DESC LIMIT 1

the output of above query

Now I have the second table with field name and field type

I have to join both the table to get the field name and type of the elements.

Now I have to display the last elements of the form builder with field name and field type. I mean it will display the last name and email with field type.

I am using CodeIgniter, my controller

$inst_id=1;
    $result['data']=$this->formbuilder_Model->check_example_form_builder_fields($inst_id);
     $this->load->view('user-form',$result);//passing elements to the view page

View

foreach ($data as $key) {
 $exp_fields_name=$key->fields_name;
 $exp_fields_type=$key->fields_type;
 $exp_form_elements=$key->form_elements;
  $abc=explode(',',$exp_form_elements);
    foreach ($abc as $value) {
      if ($exp_fields_name == $value) {?>
      <div class="form-group row label-capitals">
              <label class="col-sm-5 col-form-label"><?php echo $exp_fields_name;?></label>
              <div class="col-sm-7">
              <input type="<?php echo $exp_fields_type;?>" name="<?php echo $exp_fields_name;?>" placeholder="<?php echo $value;?>" class="form-control" />
               <?php echo form_error($exp_fields_name); ?>
            </div>
            </div>
              <?php 
       }}}?>

I need a output like

<label>Lastname</label>
<input type="text" name="lastname">

<label>Email</label>
<input type="email" name="email">

Would you help me out in this?


回答1:


Rather than storing form_elements in fom_builder table, store their respective id and then use query something like this

SELECT form_elements_id FROM form_builder WHERE form_id=1 AND form_builder_type='example' ORDER BY update_date DESC LIMIT 1

Once you get all form elements Id implode it and convert it into array and use whereIn clause to get data from second table.



来源:https://stackoverflow.com/questions/46661435/how-to-display-the-last-field-which-is-user-selected-from-form-builder-with-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!