简体   繁体   English

自我提交表格,然后刷新页面?

[英]Self submitting form, then refresh page?

I have a page in PHP with a form that contains multiple checkmarks. 我在PHP中有一个页面,其中的表单包含多个复选标记。 These checkmarks can be used to either DELETE the records or create LABELS for whatever is selected. 这些选中标记可用于删除记录或为选定的内容创建标签。

I got the delete section going just fine as I use the same page ($_SERVER['PHP_SELF']) to run a query, but the labels isn't working because I need to pass the values to another page called PDF_Label_Print.php. 我使用同一页面($ _SERVER ['PHP_SELF'])来运行查询时,删除部分运行得很好,但是标签不起作用,因为我需要将值传递给另一个名为PDF_Label_Print.php的页面。 I would like to stay away from session variables if possible. 如果可能的话,我想远离会话变量。

The page works, but sometimes it doesn't refresh automatically. 该页面有效,但有时不会自动刷新。 Any ideas? 有任何想法吗? Thanks! 谢谢!

if (isset($_GET['labels']) && (is_array($news_ids) && count($news_ids) > 0))
{
    $label_list  = implode(',', $news_ids);
    echo "<form action='PDF_Label_Print.php' method='post' name='frm' target='_blank'>
    <input type='hidden' name='full_list' value='". htmlentities(serialize($label_list)) ."' />
    <input type='hidden' name='tbl_name' value='" . $_SESSION['officeid'] ."' />
    <input type='hidden' name='report' value='list' />
    <input type='hidden' name='avery' value='5160' />
    </form>";

    echo "<script language='JavaScript'>document.frm.submit();</script>";
    // refresh page.

    echo '<script language="javascript">window.location = "welcome.php"</script>';
}

the problem is that after submitting a form javascript might stop working till the post is done, and the form action is another page.BUT again, when submitting a form (without ajax) the page should refresh automatically. 问题是提交表单后,javascript可能会停止工作,直到发布完成,并且表单操作是另一个页面。但是,再次提交表单(不带ajax)时,页面应自动刷新。

So what you need is on the PDF_Label_Print.php page to redirect back to the welcome page 因此,您需要在PDF_Label_Print.php页面上将其重定向回到欢迎页面。

header("location:welcome.php"); // or anyother page you want to redirect after posting

Thank you for everyone who took to their time to look at my question. 感谢您抽出宝贵时间来研究我的问题。

Turns out I was able to resolve the issue by using POST instead of GET on my form. 原来,我能够通过在表单上使用POST而不是GET来解决此问题。 The header location is now refreshing the page correctly. 页眉位置现在可以正确刷新页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM