两个从正常表格和模态表格提交

时间:2016-01-08 09:51:27

标签: php forms modal-dialog

我有一个表格输入一些细节,在那里有一个选择控件,选择一些选项(审核ID).IF用户找不到正确的选项,然后他可以使用相同的另一个按钮添加通过单击该按钮,将出现一个模态形式,输入控件在那里,输入数据并保存,将该值保存在一个表中(表:auditnumber)。主窗体将所有输入的数据保存在另一个表(auditplan)中。因此,我有两个提交按钮,为不同的表保存不同的值,模态窗体只是可选的..如果用户没有找到确切的选项。

我刚试过这些代码但是没有用。模态表单提交按钮无效。

我不知道这个是不是好主意。只是我在网络应用程序初学者。

<?php
include("config.php"); 
include("header.php"); 
session_start();
try {
    $sql = "SELECT * FROM auditnumber";
    $stmt = $DB->prepare($sql);                
    $stmt->execute();
    $result = $stmt->fetchAll();                    
    } 
    catch (Exception $ex) 
    {  echo $ex->getMessage(); }
?>

<div class="col-md-10 main">

 <form class="form-horizontal" role="form" action="auditplanentry.php" method="POST"> 

<div class="form-group">
  <label class="control-label col-sm-2" for="usr">Audit ID:</label>  
    <div class="col-sm-5"> 
     <select id="course" name="course" class="form-control" ><option>Select</option>
     <?php foreach($result as $row){ ?>
      <option><?php echo $row['auditnumber']?></option>
      <?php  }
        ?>
      </select>         
    </div>
    <button type="button" class="btn btn-primary btn-circle" rel="tooltip" title="Add audit ID,if not present in select option" data-toggle="modal" data-target="#auditidmodal"><i class="glyphicon glyphicon-plus"></i></button>
</div>

<div class="form-group">
  <label class="control-label col-sm-2" for="pwd">Year:</label>
    <div class="col-sm-5">
        <input type="text" class="form-control col-xs-3" id="year" name ="year">
    </div>
</div>

<div class="form-group">        
      <div class=" col-sm-offset-3">
        <button type="submit" name="submit" id ="submit" class="btn btn-primary">Save</button>
        <button type="submit" name="submit1" id ="clear" class="btn btn-primary">Cancel</button>
      </div>
 </div>     
</form>           
</div>

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

            if(trim($_POST['auditid'])=='')
                    {
            echo "<script language='javascript'>alert('Please Enter Audit ID.');</script>";
            exit;
                    }                   
            elseif(trim($_POST['year'])=='')
                    {
            echo "<script language='javascript'>alert('Please Enter Year.');</script>";
            exit;
                    }

            $audit=trim($_REQUEST['auditid']);
            $year=trim($_REQUEST['year']);          
    $sql = "INSERT INTO auditplan(auditid,year) VALUES " . "(:audit, :year)";

        try {           
              $stmt = $DB->prepare($sql);           
              // bind the values
              $stmt->bindValue(":audit", $audit);
              $stmt->bindValue(":year", $year);           
              // execute Query
              $stmt->execute();          
            } 
            catch (Exception $ex)
            {
              $_SESSION["errorType"] = "danger";
              $_SESSION["errorMsg"] = $ex->getMessage();
            }       
    }
    elseif(isset($_POST['submit1']))
    {               
    echo "<script language='javascript'>document.location.href='Auditplan.php';</script>";
    }           
?>

<div class="modal" id="auditidmodal" tabindex="-1" role="dialog" aria-labelledby="messageModelLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content"> 

    <div class="modal-body">
        <form id="auditidform" role="form" action="auditplanentry.php" method="POST">       
        <div class="control-group">
            <label class="control-label" for="leave_status">Enter Audit ID:</label>
            <div class="controls">
                <input id="audit" class="form-control" name="audit" placeholder="Eg: IA01" ></input>
            </div>
        </div>
        </form>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" type="submit" name="save" id ="save" >Save</button>
        <button class="btn" type="submit" name="clear" id ="clear">Cancel</button>
    </div>
</div>
</div>
</div>

<?php
    if(isset($_POST['save']))
        {           
            if(trim($_POST['audit'])=='')
                    {
            echo "<script language='javascript'>alert('Please Enter Audit ID.');</script>";
            exit;
                    }                   

            $audit=trim($_REQUEST['audit']);    

    $sql = "INSERT INTO auditnumber(auditid) VALUES " . "(:audit)";

        try {           
              $stmt = $DB->prepare($sql);            
              $stmt->bindValue(":audit", $audit);            
              $stmt->execute();           
            } 
            catch (Exception $ex)
            {
              $_SESSION["errorType"] = "danger";
              $_SESSION["errorMsg"] = $ex->getMessage();
            }       
    }
    elseif(isset($_POST['clear']))
    {               
    echo "<script language='javascript'>document.location.href='Auditplanentry.php';</script>";
    }           
?>

0 个答案:

没有答案