如何发布输入和输入选择单一形式的类型

时间:2016-11-18 07:13:11

标签: javascript php html forms

在posts.php文件中,我写了下面的代码。在单一形式我包括输入类型[textfield]&选择[选项]类型,当我提交表单时,我收到错误Notice: Undefined index: designerorder_id

表格

<form  method="post">
<div id="ordernumbers">
          <select name ="designerorder_id">
            <option>Select Order</option>
          </select>
        </div>
<input type="text" name="paid_status" />

<input name="register1" type="submit"  onclick="return updatepayment(); "/>

if (isset($_POST['register1'])) {

  $designerorder_id = trim($_POST['designerorder_id']);
  $paid_status = password_hash($_POST['paid_status'], PASSWORD_DEFAULT);

  $stmt = $reg_user->runQuery("SELECT * FROM order_details");
  $row = $stmt->fetch(PDO::FETCH_ASSOC);
  $stmt->execute();


    if ($reg_user->register1($designerorder_id,  $paid_status)) {
      $id = $reg_user->lasdID();
      $key = base64_encode($id);
      $id = $key;

      $message = " updated database";

   //   $subject = "Confirm updation";

    //  $reg_user->send_mail($email, $message, $subject);
      $msg = "database updated ";

    } else {
      echo "sorry , Query could no execute...";
    }
  }

脚本

function getOrderDetail(e)
  {
    var designerId=e.target.options[e.target.selectedIndex].value;    
    var url="http://sbdev2.kidsdial.com:81/php/site6/designerpaidstatus.php?designer_id="+designerId+"&opration=2";
       var request = jQuery.ajax( {
                url: url ,
                type: 'POST',                      
            } );

            request.done( function (result)
            {  
              document.getElementById('ordernumbers').innerHTML =result;

            } );
            request.fail( function ( error )
            {
                console.dir(error);             
            } );
     }

我尝试的是,

当我研究谷歌时,我发现 link1 link2link3之类的链接只使用Select [options] [非输入类型]形式。在其他一些links中,他们使用JS来实现这一点,我也尝试过link5并尝试了以下几种代码:

$selected_val = $_POST['designerorder_id'];
$stud = explode("_",$_POST['designerorder_id']);

但没有任何对我有用。我几乎花了2天才提问,我是php的新手,请帮助我。

修改 - posting.ph p文件的完整代码

<?php 

require_once 'dbconfig.php';
require_once 'class.user.php';
include 'home.php';
print_r($_POST);
//$reg_user = new USER();
$reg_user='';


$stmt = $user_home->runQuery("SELECT * FROM tbl_users");
  $stmt->execute(array(":uid" => $_SESSION['userSession']));
  $row = $stmt->fetch(PDO::FETCH_ASSOC);
  $stmt->execute();
?>

<?php

var_dump($_POST);

  if (isset($_POST['register1'])) {



  $designerorder_id = trim($_POST['designerorder_id']);
//  $selected_val = $_POST['designerorder_id'];
//$stud = explode("_",$_POST['designerorder_id']);
  $product_id = trim($_POST['product_id']);
  $paid_status = password_hash($_POST['paid_status'], PASSWORD_DEFAULT);
  $due_date = trim($_POST['due_date']);

  $stmt = $reg_user->runQuery("SELECT * FROM order_details");
  $row = $stmt->fetch(PDO::FETCH_ASSOC);
  $stmt->execute();


    if ($reg_user->register1($designerorder_id, $product_id, $paid_status, $due_date)) {
      $id = $reg_user->lasdID();
      $key = base64_encode($id);
      $id = $key;

      $message = " updated database";

   //   $subject = "Confirm updation";

    //  $reg_user->send_mail($email, $message, $subject);
      $msg = "database updated ";

    } else {
      echo "sorry , Query could no execute...";
    }
  }



?>

<style type="text/css">
  .paymentstatus{width:70%;margin: auto!important;}
  .inputpayment{/*width: 20%;clear:both;*/}
</style>


<div class="paymentstatus">
 <form class="form-signin" method="post"  action="posting.php" id="myFormId"> 
    <h2 class="form-signin-heading">Designer Payment Status</h2> 


    <table>


    <!-- Designer -->
      <tr>

        <td> Designer  </td>

        <td>
          <select onchange="getOrderDetail(event);" >
            <option>Select Designer</option>
            <?php while($data = $stmt->fetch())  { if($data['type']=="admin")continue;?>
              <option value="<?php echo $data['userID'];?>"><?php echo $data['name'];?></option>
            <?php } ?>
          </select> 
        </td> 

      </tr> 


     <!-- Designer Order Number: -->

    <tr>

        <td>Number: </td>

      <td>

        <div id="ordernumbers">
          <select name ="designerorder_id">
            <option>Select Order</option>
            <option value="1">abc</option>
          </select>
        </div>

      </td>

    </tr> 


      <!-- Product Related To Order Number:  -->

      <tr>  

        <td>Products</td>

        <td>

        <div id="productnumbers">
          <select name="product_id">
            <option>Select Products</option>
          </select>
          </div>

        </td>

      </tr>


      <!--  Paid Status: -->

      <tr>
        <td>Paid :</td>


        <td>
          <input type="text" class="inputpayment" placeholder="PaidStatus" name="paid_status" value="Paid" readonly="readonly" />
        </td>

      </tr>


      <!--  DueDate:-->

       <tr>
        <td>Due Date</td>


        <td>
          <input type="text" class="inputpayment" id="datepicker" placeholder="Duedate" name="due_date" value=""/>
        </td>
      </tr>



    </table>
    <hr/>


   <input class="btn btn-large btn-primary" name="register1" type="submit" id="btnSubmit" value="Update Payment" onclick="return updatepayment(); "/>

  </form>

</div>
<link rel="stylesheet" href="http://sbdev2.kidsdial.com:81/php/site6/bootstrap/css/jquery-ui.css"> 

<script src="http://sbdev2.kidsdial.com:81/php/site6/bootstrap/js/outthinking/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(

  /* This is the function that will get executed after the DOM is fully loaded */
  function () {
    $( "#datepicker" ).datepicker({
      changeMonth: true,//this option for allowing user to select month
      changeYear: true //this option for allowing user to select from year range
    });
  }

);
  function getOrderDetail(e)
  {
    var designerId=e.target.options[e.target.selectedIndex].value;  
//var designerId=e.target.options[e.target.options.selectedIndex].‌​value;  
    var url="http://sbdev2.kidsdial.com:81/php/site6/designerpaidstatus.php?designer_id="+designerId+"&opration=2";
       var request = jQuery.ajax( {
                url: url ,
                type: 'POST',                      
            } );

            request.done( function (result)
            {  
              document.getElementById('ordernumbers').innerHTML =result;

            } );
            request.fail( function ( error )
            {
                console.dir(error);             
            } );
     }
  function getProductDetail(e)
  {    
    var productId = $("#dproductselect option:selected").attr("class");  
    var finalstrig=productId.split(",");
    alert(finalstrig[1]);
    var select='';
    select+='<select><option>Select Product</option>';

    for(i=0;i<finalstrig.length;i++)
    {
      if(finalstrig[i]!=0)
      {
        select +='<option value="'+finalstrig[i]+'">'+finalstrig[i]+'</option>';
      }
    }
    select +='</select>';   
    document.getElementById('productnumbers').innerHTML =select;
  }

</script>

<script>

var request = jQuery.ajax( {
                url: 'posting.php' ,
                data : jQuery("#myFormId").serialize(),
                type: 'POST',                      
            } );


</script>

class.user.php

public function register1($designerorder_id, $product_id, $paid_status, $due_date)
  {
    try {

      $stmt = $this->conn->prepare("INSERT INTO order_details(designerorder_id, product_id, paid_status, due_date) 
            VALUES(:designerorder_id, :product_id, :paid_status, :due_date) ;");
      $stmt->execute(array(
          ":designerorder_id" => $designerorder_id,
          ":product_id" => $product_id,
          ":paid_status" => $paid_status,
          ":due_date" => $due_date

      ));
      return $stmt;
    } catch (PDOException $ex) {
      echo $ex->getMessage();
    }
  }

3 个答案:

答案 0 :(得分:0)

首先{name}移除name属性后的空格,它应该是<select name= "designerorder_id">

然后给这样的表格提供一些id。

<select name="designerorder_id">

并以ajax形式传递这样的表单数据。

<form  method="post" id="myFormId">

并且我可以看到你使用post方法在ajax中发送数据,那么为什么要在你的url字符串中使用get变量?

使用var request = jQuery.ajax( { url: url , data : jQuery("#myFormId").serialize(), type: 'POST', } );

传递您的其他有需要的变量及其值

这将是我想的简单方法。

您的功能<input type="hidden">也需要进行一些更改 你写过

function getProductDetail(e)

将其更改为select+='<select><option>Select Product</option>';

删除select+='<select name="product_id"><option>Select Product</option>';  ,如果你正在刷新你不需要的页面。

在您的PHP代码中将var request = jQuery.ajax( { url: 'posting.php' , data : jQuery("#myFormId").serialize(), type: 'POST',
} );
更改为$ paid_status = $ _POST ['paid_status'];

希望这有帮助。

答案 1 :(得分:0)

我在phpfiddle.org尝试了这个并且它运行正常。

代码:

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div id="ordernumbers">
          <select name ="designerorder_id">
            <option>Select Order</option>
            <option value="One">One</option>  
          </select>
        </div>
<input type="text" name="paid_status" />

<input name="register1" type="submit"  onclick="return updatepayment(); "/> <br><br>

<?php
if (isset($_POST['register1'])) {

  $designerorder_id = trim($_POST['designerorder_id']);
     echo $designerorder_id;  
}
?>

输出

enter image description here

答案 2 :(得分:-1)

是否可以更改表单并尝试

<form  method="post">
    <div id="ordernumbers">
              <select name ="designerorder_id">
                 <option value="">Select Order</option>
                <option value="1">abc</option>
              </select>
            </div>
    <input type="text" name="paid_status" />

    <input name="register1" type="submit"  onclick="return updatepayment(); "/>