2017-07-03 181 views
-1

我应该试着写一些更详细的错误。 我需要一种问卷调查问卷,只有您可以选择的几个答案中的一个。 该问题被分组为<fieldset>元素,这些元素在最后一组问题回答后变为可见。 由于设计原因,我写了一个设置为键入“按钮”的几个button元素。 我不能让页面重新加载回答问卷。<button type =“button” - 通过POST传递值到PHP

现在我想传递它们的值,如果点击到PHP将它们保存到数据库。

jQuery(document).ready(function($) { 
 
     var current = 1, 
 
     current_step, next_step, steps; 
 
     var buttonname = ''; 
 
     var buttonvalue = ''; 
 
     var btnarray = []; 
 
     steps = $(".fieldset").length; 
 
     $(".next").click(function() { 
 
     buttonname = $(this).attr('name'); 
 
     buttonvalue = $(this).val(); 
 
     btnarray.push(buttonname + ":" + buttonvalue); 
 
     current_step = $(this).parents("fieldset"); 
 
     next_step = $("fieldset").eq(current); 
 
     buttonvalue = $(this).val(); 
 
     current_step.hide(); 
 
     next_step.show(); 
 
     //setProgressBar(++current); 
 

 

 

 

 
     }); 
 
     
 
     });
.parallelogram { 
 
    background: #fff; 
 
    width: 100%; 
 
    height: auto; 
 
    position: relative; 
 
    border: solid 5px #0793EB; 
 
    margin-left: -10px; 
 
    transform: skew(-15deg); 
 
    font-size: 24pt; 
 
    color: #0793EB; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<form id="reg_form" novalidate action="action.php" method="POST"> 
 
    <fieldset> 
 
    <button type="button" class="parallelogram next" name="topic[]" value="1"><span class="text-uppercase boldtext">Button 1-1</span></button> 
 

 
    <button type="button" class="parallelogram next" name="topic[]" value="2"><span class="text-uppercase boldtext">Button 1-2</span></button> 
 
</fieldset> 
 
    
 
    <fieldset hidden> 
 
    <button type="button" class="parallelogram next" name="secondtopic[]" value="1"><span class="text-uppercase boldtext">Button 2-1</span></button> 
 

 
    <button type="button" class="parallelogram next" name="secondtopic[]" value="2"><span class="text-uppercase boldtext">Button 2-2</span></button> 
 
</fieldset> 
 
</form>

在Firebug中,我可以看到的参数,并在预览中的数组,但var_dump($_POST);不给我任何东西。

有没有人有想法?

在此先感谢。

问候。

回答

0

给按钮作为数组,你可以访问在PHP中。

<button type="submit" class="parallelogram next" name="topic[]" value="1"><span class="text-uppercase boldtext">Button 1</span></button> 

     <button type="submit" class="parallelogram next" name="topic[]" value="2"><span class="text-uppercase boldtext">Button 2</span></button> 



    <?php 

     $buttonData = $_POST['topic']; 

    // do database operations 
    ?> 
+0

事情是,这是一个多步骤的形式,我只想在最后提交。所以我将按钮定义为type =“button”以留在我的页面上。 – Gardinero