How to redirecting pages in php (with js and forms)

i have menu.php, this page contain menu options and each option is an individual page that I redirect using javascript functions, and the load pages in a container div.

The problem: the page, SearchProductHtml.php have a button with action form, the problem is that pressing button, this button call a controller php and controller php redirect to, SearchProductHtml.php, this success but the menu disappears and only load page SearchProductHtml.php

<html>
<head>
    <title>Welcome</title>
</head>
<body>

 <a href="#"><i class="fa fa-paper-plane"></i>Products<span class="fa arrow"></span></a>
   <ul class="nav nav-second-level">
   <li>
      <a href="#" id="opcIns">insert product</a>
   </li>
   <li>
       <a href="#" id="opcSearch">Search product</a>
   </li>             

        <div id="page-wrapper">
            <div id="container">
                     //there are content
            </div>
        </div>
    </div>
</body>

js file:

`setupButtons: function() {
    $("#opcSeacrh").on("click", menu.loadSearch);
},


loadSearch: function() {
    $("#container").load('../pages/SearchProductHtml.php');
},`

html search:

<html>
<head>
    <title>Welcome</title>
</head>
<body>
      <form Action="../Controller/SearchController.php" method="POST">
          <input type="text" name="idCategory"></input>
          <input type="submit">Button</input>


          <table>
             //all content
          </table>

      </form>
</body>

controller php:

process....
$list = $db->getList($id);
$_Session["list"] = $list;
include_once = "SearchProductHtml.php"; -->this work, but only show this page, and menu dissapears

How can I redirect to the "SearchProductHtml.php" page with the included menu?

I do not want to put the menu on all pages

1 answer

  • answered 2017-06-17 18:15 derHugo

    To redirect to another page in php you use

    header("Location: yourpage.php");
    

    In your question I don't see the menu but you could solve it by passing a variable to the controller and back

    And than check on your search page if e.g. showMenu was 0 or 1

    E.g. by

    header("Location: yourpage.php?showMenu=1");