如何显示用户从表单构建器中选择的字段名称和字段类型的最后一个字段? [英] How to display the last field which is user selected from form builder with the field name and field type?

查看:146
本文介绍了如何显示用户从表单构建器中选择的字段名称和字段类型的最后一个字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建表单构建器,并且我有一个名为Firstname,Lastname,Email,Iagree的输入字段。无论用户从表单构建器页面中选择字段,所有元素都将在单击按钮后存储在数据库中。



就像我选择元素Firstname,Lastname,Email和从我的表单生成器页面iagree并保存它。在数据库中,它将存储如下例所示


现在我更新表单生成器并更改表单元素。它显示如下图。





现在我有第二个表格,字段名称和字段类型

p>



我必须j在这两个表中获取字段名称和元素类型。

现在我必须显示表单构建器的最后一个元素,其中包含字段名称和字段类型。我的意思是它会显示字段类型的姓氏和电子邮件。



我使用CodeIgniter,我的控制器

  $ inst_id = 1; 
$ result ['data'] = $ this-> formbuilder_Model-> check_example_form_builder_fields($ inst_id);
$ this-> load-> view('user-form',$ result); //传递元素到视图页面

查看

  foreach($ data as $键){
$ 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
}}}?>

我需要一个输出,如$ /

 <标签>&姓氏LT; /标签> 
< input type =textname =lastname>

< label>电子邮件< / label>
< input type =emailname =email>

您能帮我解决吗?

解决方案



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



Id implode它并将其转换为数组,并使用whereIn子句从第二个表中获取数据。

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?

解决方案

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.

这篇关于如何显示用户从表单构建器中选择的字段名称和字段类型的最后一个字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆