嗨, 我有html代码,允许用户上传图像,然后允许他们为该图像选择难度级别。但是,我需要传递该按钮的值(或选择任何按钮到我的PHP代码进行处理)。例如,如果他们选择新手级别,我想在我的PHP代码中将变量设置为1,如果他们选择高级,我希望将变量设置为2.
我在html中的代码如下:
<form id="formUploadFile" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post" >
<p>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">
</p>
<p align="left">
<label for="file" >First, Choose your image!</label>
<input type="file" name="files[]" />
</p>
<p class="text-center">
<h5>Then, Choose your Difficulty!</h5>
<div class="btn-group" data-toggle="buttons">
<button type="submit" class="btn btn-success" name="difficultybutton" value="0" onclick="loadingCircle()">Kids</button>
<button type="submit" class="btn btn-success" name="difficultybutton" value="1" onclick="loadingCircle()">Novice</button>
<button type="submit" class="btn btn-success" name="difficultybutton" value="2" onclick="loadingCircle()">Intermediate</button>
<button type="submit" class="btn btn-success" name="difficultybutton" value="3" onclick="loadingCircle()">Advanced</button>
</div>
如何将这些按钮的值传递给php代码?我的loadingCircle()代码隐藏了页面上的所有内容,并在我的php代码处理时显示加载圈。
答案 0 :(得分:0)
尝试此代码可能有助于您理解
我建议你选择单选按钮,但我也有按钮的例子
<form action="" method="post">
<input type="radio" name="radio" value="1">Kids
<input type="radio" name="radio" value="2">Novice
<input type="radio" name="radio" value="3">Intermediate
<input type="radio" name="radio" value="3">Advanced
<input type="submit" name="submit" value="Get Selected Values" />
</form>
<?php
if (isset($_POST['submit'])) {
if(isset($_POST['radio']))
{
echo "You have selected :".$_POST['radio']; // Displaying Selected Value
}
?>
<form action="" method="POST">
<input type="submit" value="0" name="zero">
</form>
<?php
if (isset($_POST["zero"])){
echo $_POST["zero"];
}
?>