0

I have a page in PHP with a form that contains multiple checkmarks. 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. 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>';
}
Ronaldo
  • 111
  • 7
  • 1
    If your using PHP_SELF just make sure you read up on this: http://stackoverflow.com/questions/10272282/how-to-secure-serverphp-self – Liam Sorsby Feb 18 '16 at 18:17
  • Also, does it have to refresh using javascript? Can't you redirect using the php header function? – Liam Sorsby Feb 18 '16 at 18:19
  • thanks for looking into the issue I'm having. I tried the PHP_SELF solution and replaced the javascript refresh with header location. It's not reloading the page welcome.php. Could it be because I already used header location elsewhere in the code? – Ronaldo Feb 18 '16 at 18:24
  • 1
    Does PDF_Label_Print.php have to be a different page, or can you not just include the file within your page php if appropriate? – James Feb 18 '16 at 18:26
  • For what it's worth, I've yet to see a use condition where a self-submitting form was useful. If something submits without my doing, I'll assume fishy stuff is happening. – Sterling Archer Feb 18 '16 at 18:30
  • PDF_Label_Print.php simply runs a select query and sets up the TCPDF stuff to create my Avery 5160 labels. I cannot include this page in welcome.php. Since the entire site uses Sessions, I didn't want to pass the array (checkbox IDs) via a session. The other thing that I can think of is having my original form submit values to a second page. – Ronaldo Feb 18 '16 at 18:38

2 Answers2

0

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.

So what you need is on the PDF_Label_Print.php page to redirect back to the welcome page

header("location:welcome.php"); // or anyother page you want to redirect after posting
Guilherme Ferreira
  • 2,209
  • 21
  • 23
0

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. The header location is now refreshing the page correctly.

Ronaldo
  • 111
  • 7