2015-12-11 36 views
3

下午好,表单元素不被控制在Laravel

我一直试图让这个到现在工作了一段时间,但似乎无法认可。我有一种形式的观点。在这种形式下是一个选择下拉列表和一些输入,将信息传递给控制器​​进行处理。

问题是,表单需要能够通过添加或删除新的输入来改变自己,这取决于select中选择了哪个选项。

我所做的是使用JQuery来追加和删除元素。它可以很好地工作,但是以这种方式创建的元素无法被控制器识别。请看看:

控制器

public function userface2show() { 

    $keymaker = Request::get('Search'); 

    dd(Request::all()); 

//this works only on the original elements in the view, any element created by my JQuery does not reflect in the dd(Request::all()); 

} 

查看:

<script> 

    $(document).ready(function(){ 

    $(function(){ 


     $('#specialselect').change(function() { 

     if($("#specialselect option:selected").text() == "Year") { // activates the change when option from the select is activated 

      $("#selectornode").remove(); // removes original element 
      $("#selectorbox").append("<input id='selectornode1' name='Search1' type='text'>"); // adds new element with another "name" 

     } 

     else { 

      $("#selectornode1").remove(); // removes new element 
      $("#selectorbox").append("<input id='selectornode' name='Search' type='text'>"); // creates replicate of the original element. This replica does not work either. 
     } 

     }); 

    }); 

    }); 

    </script> 

      <table class="formstyle"> 
      {!! Form::open(array('action' => '[email protected]')) !!} 
      <tr> 
      <td> 
      {!! Form::label("Select Area/Field of Study") !!} 
      </td> 
      <td> 
      {!! Form::select('Area', $Area) !!} 
      </td> 
      <td> 
      {!! Form::label("Specify Search Parameter") !!} 
      </td> 
      <td> 
      {!! Form::select('Parameters', $Parameters, 'default', array('id' => 'specialselect')) !!} 
      </td> 
      <td> 
      {!! Form::label("Input Word to Search", null, array('id' => 'selectortext')) !!} 
      </td> 
      <td id="selectorbox"> 
      {!! Form::text('Search', null, array('id' => 'selectornode')) !!} // this is the only element that needs to be changed. 
      </td> 
      <td> 
      {!! Form::submit('Go', ['class' => 'buttonite']) !!} 
      </td> 
      </tr> 
      {!! Form::close() !!} 
      </table> 

有没有什么办法让这些新创建的窗体输入的工作?

谢谢你们,任何帮助,将不胜感激。

回答

0

下午好偷看,

你永远不会相信什么固定的这个问题。我和其他一些开发人员查看了这个问题,并且无法分辨出什么是错误的,所以我们开始逐个移除元素以查看导致问题的原因。

当我们删除了HTML <table>格式时,它开始工作。 <tr> s和<td>正在干扰前端将信息传递到后端的能力。

谢谢大家检查出这个问题。

1

您还没有将请求实际连接到您的控制器功能。 赞同描述here。 将您的控制器功能更改为此,您应该能够立即访问该变量。

public function userface2show(Request $request) { 

    $keymaker = $request->input('Search'); 
    dd($request); 
}