提交表单以弹出窗口

时间:2013-10-23 18:23:31

标签: php jquery forms

我有一个用php-pear创建的表,以及一个处理click事件的jquery函数,用于将单元格信息提交到新的表单页面。 jquery是这样的:

    var row = $this.parent('tr').contents('th:eq(0)').html();
    var departmentID = $(".deptSelect").val();  
    var headerObj = $(this).parents('.main').find('th').eq(colIndex);
    var toPass =   $.trim(headerObj.text());
    var picked = $("#picked").val();
    var testDate = new Date(picked + " " + row);
    var today = new Date();

    if (testDate < today)
    {
        if (roleID > 2)
        {
        alert("You Cannot Schedule a New Job in the Past!");
        }
        return;
    }
    var thisForm = '';

    if (roleID == 5)
    {
        thisForm = '../forms/tentativeJobForm.php';
    }
    else
    {
        thisForm ='../forms/newJobForm.php';
    }

    var f = document.createElement("form");
    f.setAttribute('class','jobTime');
    f.setAttribute('method','post');
    f.setAttribute('action',thisForm);

    var iii = document.createElement('input');
    iii.setAttribute('type','hidden');
    iii.setAttribute('name','departmentID');
    iii.setAttribute('value',departmentID);
    f.appendChild(iii);

    var i = document.createElement('input');
    i.setAttribute('type','hidden');
    i.setAttribute('name','sTime');
    i.setAttribute('value',picked + " " + row);
    f.appendChild(i);

    var ii = document.createElement('input');
    ii.setAttribute('type','hidden');
    ii.setAttribute('name','ast');
    ii.setAttribute('value',toPass);
    f.appendChild(ii);

    document.getElementsByTagName('body')[0].appendChild(f);
    if (roleID > 2)
    $('.jobTime').submit;
    else
    return;
});

这实际上是有效的,但是我的用户抱怨在他们安排新工作时没有看到日历页面,并且它与已经安排的另一个工作发生冲突。我的新要求是生成的冲突页面将作为弹出窗口打开。不是存在冲突的警报,而是具有冲突信息的原始表格。上面的表单提交到我的php页面,以下函数处理冲突:

function checkRows($stmt, $msg=NULL, $params=NULL)//, $updatedInfo=NULL)
{
    if ($stmt != NULL)
    {
        $rows_affected = sqlsrv_rows_affected($stmt);
        if ($rows_affected > 0)
        {
            $starting = new DateTime($params[5]);
            $ending = new DateTime($params[6]);
            $starting = date_format($starting,'m/d/Y h:i a');
            $ending = date_format($ending,'m/d/Y h:i a');

            echo "Job:" . $params[0] . " was Successfully Scheduled for $starting to $ending<br>";
        }
    }
    else
    {
        $userSTime = new DateTime($params[0]);
        $userSTime = date_format($userSTime,'m/d/Y h:i a');

        $userETime = new DateTime($params[1]);
        $userETime = date_format($userETime,'m/d/Y h:i a');     
        $_SESSION['jbNum'] = $params[2];
        $_SESSION['asset'] = $params[4];
        $_SESSION['userSTime'] = $userSTime;
        $_SESSION['userETime'] = $userETime;
        $_SESSION['userDesc'] = trim($params[3]);
        $_SESSION['conJbNum'] = $msg['JobNum'];
        $_SESSION['conSTime'] = date_format($msg['StartTime'], 'm/d/Y h:i a');
        $_SESSION['conETime'] = date_format($msg['EndTime'], 'm/d/Y h:i a');
        $_SESSION['dueDate'] = $params[5];
        $_SESSION['comment'] = $params[6];
        $_SESSION['destination'] = $params[7];
        $_SESSION['jStat'] = $params[8];

        if ($_SESSION['recurring'] == 'n')
        {
        echo "<meta http-equiv='refresh' content='0;URL=../forms/newJobForm.php' target = 'mainFrame'/>";
        exit;
        }
        else
        {
            echo "Scheduling for Job:" . $params[2] ." failed for $userSTime to $userETime<br>";
        }
    }

}

遇到冲突时,会使用会话变量中的新信息打开原始表单。如何在弹出窗口中打开表单?我知道这不应该太难,但我无法让它发挥作用。建议使用FYI target ='_ blank',但只打开一个新选项卡。那不行。

2 个答案:

答案 0 :(得分:0)

你在寻找像对话框这样的东西吗?如果是这样,您可以使用jQuery UI .dialog()功能。

http://jqueryui.com/dialog/

答案 1 :(得分:0)

在checkRows函数中,我不得不改变:

echo "<meta http-equiv='refresh' content='0;URL=../forms/newJobForm.php' target = 'mainFrame'/>";
exit;

要:

    echo "<meta http-equiv='refresh' content='0;URL=../pages/schedule.php' target = 'mainFrame'/>";
    echo '<script>window.open("../forms/newJobForm.php",null,"height=550,width=900,status=yes, scrollbars=1, toolbar=no,menubar=no,location=no");</script>';
    echo "<script>window.close()</script>";