0

我正在尝试集成 jqgrid 和 jqform,但数据没有填充到我的 jqform 中。我进行了测试以确保 jqgrid 正在传递表单的搜索键值,并且有效。但由于某种原因,我的改革不会正确查询并填充表单对象。

  <?php 
        if(!isset($_SESSION))
                session_start();

            // Include class  
        include_once 'jqformconfig.php'; 
            if(!class_exists('jqGridUtils'))
            {   
            include_once $CODE_PATH.'jqUtils.php';
            }  
        include_once $CODE_PATH.'jqForm.php';  

            $today = getdate(time());
            $displayDate = $today['mon']."/".$today['mday']."/".$today['year'].'  '.$today['hours'].':'.$today['minutes'].':'.$today['seconds'];
            $machrecs = null;

        // Create instance  
        $newForm = new jqForm('MWOForm',array('action' => 'forms/mwoForm.php', 'method' => 'post', 'id' => 'MWOForm')); 

        // Demo Mode creating connection  
            if(!class_exists('jqGridDB'))
            {
                include_once $CODE_PATH.'/jqGridPdo.php';
            }  
        $conn = new PDO(DB_DSN, DB_USER, DB_PASSWORD); 
        $conn->query("SET NAMES utf8");
        $newForm->setConnection( $conn ); 

        // Set url 
        $newForm->setUrl($SERVER_HOST.$SELF_PATH.'forms/mwoForm.php'); 

        // Set parameters  
        $mwo_id = jqGridUtils::GetParam('mwo_id',0901270825);
        $mwo_id = is_numeric($mwo_id) ? (int)$mwo_id : 0; 
        $jqformparams = array($mwo_id); 

        // Set SQL Command, table, keys  
        $newForm->SelectCommand = 'SELECT mwo_id, asset_id, short_desc as machDesc 
                                                             FROM mfg_eng_mwo.mwo 
                                                                 WHERE mwo_id =?';

          $newForm->table = 'mfg_eng_mwo.mwo'; 
        $newForm->setPrimaryKeys('mwo_id'); 
        $newForm->serialKey = true; 

        // Set Form layout  
        $newForm->setColumnLayout('twocolumn'); 
        $newForm->setTableStyles('width:500px;','','');

            $statusSQL =   'SELECT distinct type FROM mfg_eng_mwo.wo_status';
            $prioritySQL = 'SELECT distinct type FROM mfg_eng_mwo.wo_priority';
            $deptSQL =     'SELECT dept_id FROM mfg_eng_mwo.department';

            $deptData = '-1:Select a Department';
        $machData = "";
        $assetData = "";
        $postData = "";

            if(isset($row))
            {
            $deptData = "$row[dept]:$row[dept]";
            $machData = "$row[asset_no]:$row[machDesc]";
            $assetData =$row['asset_no'];
            $postData = $row['post'];
            }

            $parts = '-:Order Parts?;1:YES;0:NO';
            $tools = '-:Order Tools?;1:YES;0:NO';

        // Add elements         
            $newForm->addElement('woStatus',   'select',   array('label' => '<b>Status</b>',            'datasql' => $statusSQL, 'id' => 'woStatus', 'required'=>true));
        $newForm->addElement('WOPriority', 'select',   array('label' => '<b>Priority</b>',          'datasql' => $prioritySQL, 'id' => 'woPriority'));
            $newForm->addElement('dept',       'select',   array('label' => '<b>Deptartment</b>',       'datalist' => $deptData,  'datasql' => $deptSQL, 'id' => 'dept', 'required'=>true));        
        $newForm->addElement('machDesc',   'select',   array('label' => '<b>Machine Desc</b>',      'datalist' => $machData, 'id' => 'machDesc','required'=>true));
            $newForm->addElement('asset_id',   'text',     array('label' => '<b>Asset ID#</b>',         'value' => $assetData, 'size' => '20', 'id' => 'MWOForm_asset_id', 'readonly'=>true, 'required'=>true));        
            $newForm->addElement('post',       'text',     array('label' => '<b>Post</b>',              'value' => $postData, 'maxlength' => '40', 'id' => 'post', 'readonly'=>true, 'required'=>true));
            $newForm->addElement('requester',  'text',     array('label' => '<b>Requester</b>',         'value' => $_SESSION['user'], 'maxlength' => '60',  'id' => 'requester', 'readonly'=>true, 'required'=>true));
        $newForm->addElement('enterTime',  'text',     array('label' => '<b>Created</b>',           'value' => $displayDate, 'maxlength' => '15', 'size' => '20', 'id' => 'enterTime', 'readonly'=>true,'required'=>true));
        //$newForm->addElement('short_desc', 'text',     array('label' => '<b>Short Description</b>', 'maxlength' => '15', 'size' => '20', 'id' => 'short_desc', 'required'=>true));
            //$newForm->addElement('parts',      'select',   array('label' => '<b>Parts Needed</b>',      'datalist' =>     $parts, 'id' => 'parts', 'required' => 'true', 'hidden' => 'true'));
            //$newForm->addElement('tools',      'select',   array('label' => '<b>Tools</b>',             'datalist' => $tools, 'id' => 'tools', 'hidden' => 'true'));
        $newForm->addElement('problem',    'textarea', array('label' => '<b>Problem</b>', 'rows' => "3", 'cols' => "50", 'id' => 'problem', 'required'=>true));
        $newForm->addElement('solution',   'textarea', array('label' => '<b>Solution</b>', 'rows' => "3", 'cols' => "50", 'id' => 'solution'));
            $elem_8[]=$newForm->createElement('newSubmit','submit', array('value' => 'Submit')); 
        $newForm->addGroup("newGroup",$elem_8, array('style' => 'text-align:right;', 'id' => 'newForm_newGroup'));

    // Add events
    $onchangeDept = <<< CHANGEDEPT
    function(event) 
    {
      $("#machDesc").show();    
        var deptval =  $("#dept").val();    
        jQuery.ajax(
        { 
          url: 'machine.php', 
          dataType: 'json', 
          data: {q:deptval}, 
          success : function(response) 
          {                                     
                 $('#machDesc').find('option').remove();    
                     $('#machDesc').append('<option value=-1>Select Equipment</option>');                                     
                 jQuery.each(response, function(i,mach) 
                 { 
                  $('#machDesc').append('<option value='+mach.asset_no+'>'+mach.asset_no+'::'+mach.short_desc+'</option>');                         
             });
                     $('#asset_no').val('');                          
             $('#post').val('');                     
          }             
       });      
    }
    CHANGEDEPT;
    $newForm->addEvent('dept','change',$onchangeDept);

    $onchangeMach = <<< CHANGEMACH
    function(event) 
    {       
      var assetval = $("#machDesc").val();  
        jQuery.ajax(
        { 
                url: 'post.php', 
          dataType: 'json', 
          data: {q:assetval},               
          success : function(response) 
          {                                                                           
                 jQuery.each(response, function(i,mach) 
                 {
                      $('#MWOForm_asset_id').val(mach.asset_no); 
                $('#post').val(mach.post);                          
           });

          } 
       });      
    }
    CHANGEMACH;
    $newForm->addEvent('machDesc','change',$onchangeMach);

    $beforeSubmit = <<< BS
    function(arr, form, options) 
    {  
        var toolval =  $("#tool").val();
        var partval =  $("#part").val();

      if(toolval == 0 || toolval == 1) 
      { 
        alert("Please select 'YES' or 'NO' for tools."); 
        return false; 
      } 
        if(partval != 1 || partval != 0) 
      { 
        alert("Please select YES or NO for tools."); 
        return false; 
      }
    } 
    BS;

    // Add events
    $onclicknewButton = <<< CLICKNEWBUTTON
    function(event) 
    {
      if($("#ajax-dialog") ) {
        $("#ajax-dialog").remove();
      }
    }
    CLICKNEWBUTTON;
    $newForm->addEvent('close_modal','click',$onclicknewButton);
    // Add ajax submit events
    $success = <<< SU
    function( response, status, xhr) {
    if(response=='success')
    {
      $("#grid").trigger("reloadGrid", [{current:true}]);
    }
    }
    SU;


    // Add ajax submit events 
    $newForm->setAjaxOptions( array('dataType'=>null, 
                                    'resetForm' =>false,
                                                                    'clearForm' =>false,
                                                                    'success' =>'js:'.$success,
                                                                    'beforeSubmit' =>'js:'.$beforeSubmit,
                                                                    'iframe' => false,
                                                                    'forceSync' =>false) ); 

    // Render the form  
    echo $newForm->renderForm($jqformparams);

    ?>
    </body>
4

0 回答 0