如何使用形式和输入选择语言


How to choose language using form and input

我想创建的方法="post"后,点击标志语言应该改变表单。点击后如何发送值?

<form method="post" action="">
     <input name="btn_lang1" type="image" src="<?php echo $this->baseUrl;?>/public/images/strona/flag_pl.png" alt="Submit" value="pl"></input>
     <input name="btn_lang2" type="image" src="<?php echo $this->baseUrl;?>/public/images/strona/flag_gb.png" alt="Submit" value="en"></input>
</form>

我想你应该给你的输入"btn_lang"起一个相同的名字,像这样:

<form method="post" action="">
     <input name="btn_lang" type="image" src="<?php echo $this->baseUrl;?>/public/images/strona/flag_pl.png" alt="Submit" value="pl"/>
     <input name="btn_lang" type="image" src="<?php echo $this->baseUrl;?>/public/images/strona/flag_gb.png" alt="Submit" value="en"/>
</form>

和get in php:

$lang = $_POST['btn_lang'];

根据您的代码,只需检查已单击哪个按钮并执行如下操作:

<?php
if(isset($_POST['btn_lng1'])){
?>
      this is where you should put your PL form
<?php
 }elseif(isset($_POST['btn_lng2'])){
?>
      this is where you should put your EN form
<?php
}
?>

重要:此解决方案在页面刷新时发生。如果你想要它动态改变表单,你必须使用js