【发布时间】:2014-06-05 00:36:59
【问题描述】:
我最近更新了 Laravel 4.1,退出的模态窗口表单无法正常工作。我发现在 Laravel 4.1 更新后出于某种原因,Laravel 会自动将标签插入到我的模态正文中。 (我在页脚中有 Form::close() 。我只是好奇是否有其他人看到过这个或者可以解释为什么会发生这种情况以及如何防止它。我很擅长搜索我的问题,但是这个没有给我任何结果。
请注意,如果我将提交按钮移动到 modal-body div 中,那么提交会按预期工作,并且更新会通过正常过程进行。但由于某种原因,对于这个特定的模式,在页脚中有提交按钮会使在 modal-body div 结束之前自动插入表单关闭时在表单外部提交按钮。同样奇怪的是,我在另一个页面上进行了此操作,并且一切都按预期工作。
以下是相关代码:
<div class="modal-body">
<?php
$access = Session::get('user_access');
$userid = Session::get('user_id');
?>
{{ Form::open(array('method'=>'POST','route' => 'users.store', 'style' => 'display:inline')) }}
@foreach($user as $userinfo)
<!-- Set hidden form element with userid embedded -->
<input type="hidden" name='id' id='id' value={{ $userid }}>
<!-- Display the username and profile Picture -->
<h2><center>{{ $userinfo->username }}</center></h2>
<br><br>
<!-- 2 Column Form to change user information and display current status -->
<div class ='container col-md-offset-1'>
<div class='row col-md-3'>
<div>
{{ Form::label('givenname', 'First Name:') }} <br>
<input type="text" name='givenname' id='givenname' value={{ $userinfo->givenname }}>
</div><br />
<div>
{{ Form::label('surname', 'Last Name:') }} <br>
<input type="text" name='surname' id='surname' value={{ $userinfo->surname }}>
</div><br />
<div>
{{ Form::label('email', 'Email Address:') }} <br>
<input type="text" name='email' id='email' value={{ $userinfo->email }}>
</div><br />
</div>
<div class='row col-md-3'>
<div>
{{ Form::label('password', 'New Password:') }} <br>
<input type="password" name='password' id='password' value={{ $userinfo->password }}>
</div><br />
<div>
{{ Form::label('password_confirmation', 'Confirm New Password:') }} <br>
<input type="password" name='password_confirmation' id='password_confirmation' value={{ $userinfo->password }}>
</div><br />
<div>
{{ Form::label('useraccess', 'Current Subscription Status:') }} <br>
{{ $access }}
</div><br />
</div>
</div>
@endforeach
</div> <!-- End Modal Body -->
<div class="modal-footer">
{{ Form::submit('Save', array('class' => ' btn btn-warning')) }}
<!-- Close the form -->
{{ Form::close() }}
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
当我在浏览器中运行开发者工具时,我可以看到自动插入
<form method="POST" action="http://dev.app.myapp.com/users" accept-charset="UTF-8"><input name="_token" type="hidden" value="<TOKEN">
<!-- Set hidden form element with userid embedded -->
<input type="hidden" name="id" id="id" value="6">
<!-- Display the username and profile Picture -->
<h2><center>johndoe123</center></h2>
<br><br>
<!-- 2 Column Form to change user information and display current status -->
<div class="container col-md-offset-1">
<div class="row col-md-3">
<div>
<label for="givenname">First Name:</label> <br>
<input type="text" name="givenname" id="givenname" value="John">
</div><br>
<div>
<label for="surname">Last Name:</label> <br>
<input type="text" name="surname" id="surname" value="Doe">
</div><br>
<div>
<label for="email">Email Address:</label> <br>
<input type="text" name="email" id="email" value="johndoe@notarealemail.com">
</div><br>
</div>
<div class="row col-md-3">
<div>
<label for="password">New Password:</label> <br>
<input type="password" name="password" id="password" value="Encrypted Password String">
</div><br>
<div>
<label for="password_confirmation">Confirm New Password:</label> <br>
<input type="password" name="password_confirmation" id="password_confirmation" value="Encrypted Password String">
</div><br>
<div>
<label for="useraccess">Current Subscription Status:</label> <br>
User </div><br>
</div>
</div>
</form>
<div class="modal-footer">
<input class=" btn btn-success" type="submit" value="Save">
<!-- Close the form -->
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
【问题讨论】:
-
对我来说只是看起来很糟糕。您应该在
modal-bodydiv 之外打开表单,然后在modal-footerdiv 之外(底部)将其关闭。所以本质上,表单是包装一切。 -
尝试将打开的表单移动到模态标题,这只是使其将关闭表单也插入到模态标题中......不明白为什么它会自动关闭表单..我有其他模式使用完全相同的标记,我在正文中打开表单并在页脚中关闭它,它按预期工作。
-
如果改用“查看页面源”,还有吗?
-
请发布其他类似的标记,也许你忽略了一个微妙的细节造成差异。