您好我正在开发一个laravel应用程序,我有一个如下所示的表单
<div class="row form-wrapper">
<form class="form-horizontal" method="get" autocomplete="off" name="calculateform" id="calculateform" >
<div class="form-group {{ $errors->has('Year') ? ' has-error' : '' }}">
<label for="Year" class="col-md-3 control-label calculate-label">@lang('admin/calculate2014/form.Calculate_dep')</label>
<?php
global $Year;
$years = array();
for ($i = 2013; $i < 2050; $i++)
{
$years[] = $i;
}
echo '<select name="Year" class="controls assettext select2 selectyear" id="Year" >';
echo '<option value="">-- Select Year --</option>';
foreach($years as $option)
{
echo "<option value='{$option}'";
if (isset($_GET['Year'])) { if ($_GET['Year'] == $option) { echo 'selected'; } }
echo ">{$option}</option>";
}
echo "</select>";
?>
<input type="submit" class="btn btn-flat gray nextbtn" id ="next" value="Proceed" />
<div class="form-group {{ $errors->has('recalculate') ? 'error' : '' }}">
<label for="nesd" class="col-md-3 control-label recallabel">Recalculate</label>
<div class="controls col-md-7">
<input name="recalculate" type="checkbox" id="recalculate" value="yes" class="recalculate recalbtn" >
{{ $errors->first('recalculate', '<span class="alert-msg"><i class="icon-remove-sign"></i> :message</span>') }}
</div>
</div>
<?php
if($_GET)
{
echo'<br/>';
echo'<br/>';
echo'<br/>';
$Year =$_GET['Year'];
}
?>
{{ $errors->first('Year', '<span class="alert-msg"><i class="icon-remove-sign"></i> :message</span>') }}
</div>
<div class="proceedhide" id="caution" >
<span class="alert-msg cautionmsg"><b>Caution:</b>Be careful if recalculate is checked the database will be refreshed.</span>
</div>
</form>
</div>
这里我试图从复选框传递一个值并将其传递给一个函数,点击提交按钮。值通过url传递,复选框值再次刷新。
如何避免在提交php页面后刷新复选框。我尝试了这个问题的可能副本,但没有一个能够正常工作。
请帮我实现这个......
我试过下面没有运气它显示未定义的索引:重新计算。
<input type="checkbox" name="recalculate" value="yes" <?php echo ($_GET['recalculate']=='yes' ? 'checked="checked"' : '');?> />
答案 0 :(得分:0)
试试这个:
<input type="checkbox" name="recalculate" value="yes" <?php if($_GET['recalculate']=='yes') { ?> checked="checked"<?php } ?> />
答案 1 :(得分:0)
尝试删除value="yes"
,然后检查它是否已开启:
<input type="checkbox" name="recalculate" <?php echo(isset($_GET['recalculate']) && $_GET['recalculate']=='on')?"checked":""?>>