如何使用具有相同名称的多个隐藏字段

时间:2016-03-27 16:00:10

标签: laravel-5.2

嗨,我试图获得产品的价格,我试过这个:

public class ToUppercase implements JavaDelegate {
    Expression text;

  public void execute(DelegateExecution execution) throws Exception {
    String value = (String) text.getValue(execution);
    value = value.toUpperCase();
    execution.setVariable("upperedText", value);
  }

}

但它一直给我只有5的价值,我怎么能得到每个价值,因为我不仅想要最后一个?

以下是完整表格:

<div class="pro-rate">
  <span class="fa fa-star" data-rate="1" ><input type="hidden" name="evaluation" id="1" value="1"></span>
  <span class="fa fa-star" data-rate="2" ><input type="hidden" name="evaluation" id="2" value="2"></span>
  <span class="fa fa-star" data-rate="3" ><input type="hidden" name="evaluation" id="3" value="3"></span>
  <span class="fa fa-star" data-rate="4" ><input type="hidden" name="evaluation" id="4" value="4"></span>
  <span class="fa fa-star" data-rate="5" ><input type="hidden" name="evaluation" id="5" value="5"></span>

我该怎么做?

1 个答案:

答案 0 :(得分:1)

使用'评估[]'

但评估将是服务器上的数组

  <div class="pro-rate">
  <span class="fa fa-star" data-rate="1" ><input type="hidden" name="evaluation[]" id="1" value="1"></span>
  <span class="fa fa-star" data-rate="2" ><input type="hidden" name="evaluation[]" id="2" value="2"></span>
  <span class="fa fa-star" data-rate="3" ><input type="hidden" name="evaluation[]" id="3" value="3"></span>
 <span class="fa fa-star" data-rate="4" ><input type="hidden" name="evaluation[]" id="4" value="4"></span>
 <span class="fa fa-star" data-rate="5" ><input type="hidden" name="evaluation[]" id="5" value="5"></span>

$ _ POST ['evaluation']将是一个数组

 $evaluation = $_POST['evaluation'];
 foreach($evaluation as $val){
    //do something with the values here
 }
好吧,好吧所有人似乎都在为我工作

<?php
 if($_POST)
        print_r($_POST['email']);
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 Name: <input type="text" name="name"><br> 
 E-mail: <input type="text" name="email"><br>

 hidden <input type="hidden" name="email[]" value='hjdfkhds'  ><br>
 hidden: <input type="hidden" name="email[]" value='iufd'><br>
 hidden: <input type="hidden" name="email[]" value='78642di'><br>
 hidden <input type="hidden" name="email[]" value='uidynsx' ><br>
 hidden <input type="hidden" name="email[]" value='qsqaaa'><br>

 <input type="submit">
 </form>
点击提交后

。这就是我得到的

enter image description here

enter image description here