下午好,表单元素不被控制在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>
有没有什么办法让这些新创建的窗体输入的工作?
谢谢你们,任何帮助,将不胜感激。