表单提交null值

时间:2016-04-04 22:23:01

标签: javascript php mysql forms

我正在使用echo从另一个页面中抓取一个表单

<div id = "consult-form-wrapper">
   <?php include('consultation.php') ?>
</div>

实际表格

<div id="acordeon">
<div class="panel-group" id="accordion">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" href="#collapseThree">
          Consult Form
        </a>
      </h4>
  </div>
        <form name ="consult-form" method="post" id="consult-form">
            <div class = "col-md-8">
                <div id="collapseThree" class="panel-collapse collapse">
                  <div class="panel-body">
                        <h5>Why did you sign up?</h5>
                         <textarea class="form-control" name = "q1" id="q1"></textarea>
                      </div>

                        <h5>What are your goals?</h5>
                         <textarea class="form-control" name = "q2" id="q2"> </textarea>

                    <div class="footer text-center">
                        <button type="submit" class="btn btn-fill btn-success" onClick="submitconsult()"
                            >Submit</button>
                         <button id="reset" class="btn btn-fill btn-danger" type="reset">Reset</button>
                    </div>
                </div>

            </div>
        </form>
  </div>
</div>
</div>

sql代码

$comment = $_POST['q1'];
$id2=$_SESSION['new_id'];
$id4 = '1026';

try {
        $pbr = $conn->prepare("UPDATE `memberInfo` mi
                       INNER JOIN `loginInfo` AS li
                       ON li.userID = mi.UserID
                       SET `q1` = ?
                       WHERE mi.userID = ?");
        //mysqli_real_escape_string($conn, $q1);
        $pbr->bind_param("ss", $comment, $id2);
        $pbr->execute();

javascript代码

function submitconsult() {
    var data = $('#consult-form').serialize();
    $.ajax({
        type: "POST",
        url: "postconsult.php",
        data: data,
        cache: false,
        success: function(html) {
        //alert(html);
        //document.getElementById('regform').reset();
        }
        });
}

如果我直接导​​航到consultation.php它会发布很好,但如果我尝试从页面上做这件事,我就会回复它,只是提交为空。我想也许它不是抓住会话ID($id2)所以我硬编码了id($id4)并且仍然是同样的问题。

1 个答案:

答案 0 :(得分:1)

您已使用提交按钮

提交表单一次
<?php endif; ?>

然后再通过submitconsult()函数。您需要更改该函数以阻止第一次提交,以便您可以执行Ajax:

$scope.chart_realtimeForceConfig = {
options: {
  chart: {
    type: 'line',
  },   
  xAxis: { 
    type: 'datetime' ,         
    labels: {
    format: '{value:%H:%M:%S %Y}'
    }
    },
},
series: [{
  name: 'Fx',
  data: [],

}, ],
func: function(chart) {
  $timeout(function() {
    chart.reflow();

  }, 300);

  $interval(function() {

    var shift = chart.series[0].data.length > 100;

    chart.series[0].addPoint([Date.now(),Math.floor(Math.random() * 100) + 1], true, shift, false);
  }, 1000);
},
loading: false

或者只是从按钮中删除提交类型并将按钮移出表单,然后调用Ajax函数而不自动触发表单提交。