我想将表单数据放入会话中
表单的操作取决于按钮.bien
中的选择,尤其是onclick()函数中。
为此,我编写了以下代码:
title = "formulaire_commun_1"
url = "/formulaire_commun_1"
layout = "sidebar_layout"
is_hidden = 0
==
<?php
function onStart()
{
$this['transaction'] = Session::get('transaction');
$this['bien'] = Session::get('type_bien');
}
function onTest()
{
Session::put('transaction', input('TYPE_transaction'));
Session::put('type_bien', input('radio_type_bien'));
}
function onRedirectMe()
{
return Redirect::to('http://google.com');
}
?>
==
<ul class="progressbar">
<li class="active">transaction</li>
<li>details</li>
<li>confirmation</li>
</ul>
<br><br><br><br>
<form method="POST" data-request="onTest" data-request-success="onRedirectMe" name="formu" accept-charset="UTF8" enctype="multipart/form-data">
<input type="hidden" name="_handler" value="onUpdate">
{{form_token()}}
{{form_sessionkey()}}
<div class="form-group">
<label for="TYPE_transaction" class="col-sm-3">type de transaction:</label>
<div class="col-sm-9">
<select class="form-control" id="TYPE_transaction" name="TYPE_transaction">
<option>vendre</option>
<option>louer</option>
</select>
</div>
<br><br><br>
<p>choisissez un type de bien:</p>
<br><br>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default bien" onclick="type_bien(0)" >
<img src="{{ 'assets/img/icones/icone_maison.png'|theme }}">
</button>
</div>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default bien" onclick="type_bien(1)"><img src="{{ 'assets/img/icones/icone_villa.jpg'|theme }}"></button>
</div>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default bien" onclick="type_bien(2)"><img src="{{ 'assets/img/icones/icone_riad.jpg'|theme }}"></button>
</div>
<br><br><br><br><br>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default bien" onclick="type_bien(3)"><img src="{{ 'assets/img/icones/icone_appartement.png'|theme }}"></button>
</div>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default bien" onclick="type_bien(4)"><img src="{{ 'assets/img/icones/icone_ferme.png'|theme }}"></button>
</div>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-defaul bien" onclick="type_bien(5)"><img src="{{ 'assets/img/icones/icone_magasin.jpg'|theme }}"></button>
</div>
<br><br><br><br>
<div style="display: none;">
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=0 value="maison" ></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=1 value="villa"></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=2 value="riad" ></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=3 value="appartement" ></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=4 value="formulaire_appartement" ></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=5 value="magasin" ></label>
</div>
</div>
<br><br><br><br><br><br
<div class=" col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-default">Register</button>
</div></div>
</form>
<script type = "text/javascript">
$(function() {
var $buttonBien = $('.bien');
$buttonBien.on('click',function (event) {
event.preventDefault();
});
});
function type_bien(x){
switch( x) {
case 0:
document.getElementById(0).checked="true";
document.forms["formu"].action="formulaire_villa";
break;
case 1:
document.getElementById(1).checked="true";
document.forms["formu"].action="formulaire_villa";
break;
case 2:
document.getElementById(2).checked="true";
document.forms["formu"].action="formulaie_riad";
break;
case 3:
document.getElementById(3).checked="true";
document.forms["formu"].action="formulaire_appartement";
break;
case 4:
document.getElementById(4).checked="true";
break;
case 5:
document.getElementById(5).checked="true";
break;
default:
alert('local_commerce est selected');
}
}
</script>
_____________
但是不幸的是,ajax和表单之间存在冲突
如果我以data-request = "onTest" action = ""
为例
我没有重定向
所以我需要一种在提交后将表单重定向到另一页的方法:
请帮助我
先谢谢您