LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Using php to call am html file (https://www.linuxquestions.org/questions/programming-9/using-php-to-call-am-html-file-761723/)

jus71n742 10-13-2009 10:04 PM

Using php to call am html file
 
I have some files I am trying to get to communicate with my main file default.php. So what have is menu.css (takes care of my sidebar), menu.htm (contains JS for all the submnmenus and such), topmenu.htm (has JS for the top menu), and footer.htm (same as the other 2 but obviously footer) , default.css (takes care of all other css info). So what I am trying to do is call the .html files from default.php so that I don't have a .html file with all this excess JS everywhere. so here is what I have in default.php
Code:

//this is the very top lines//
<?php include("menu.htm"); ?>
<?php include("topmenu.htm"); ?>
<?php include("footer.htm");?>

//html stuff that was prexisting

<?php topmenu(); ?>
//this is placed where I want the menu followed by content//


<?php menu(); ?>  //located where that menu goes



<?php footer();?> //located at the bottom where the footer goes

I have used this technique calling a .php script to a .php file. but I am not sure if it works the same way.

hopefully this is clear enough.

Wim Sturkenboom 10-13-2009 10:45 PM

Just try it.

If it does not work, you can do the following
rename topmenu.htm to topmenu.php; if your server parses htm files as php, this step is not necessary but I consider it neater.
edit topmenu.php
Code:

<?php
function topmenu() {
?>
your original html content here
<?php
}
?>

The first three lines open a function called topmenu and the last three lines close the function. The content in between is treated as html.

You can now include topmenu.php in your other php files and call topmenu(). Repeat this step for the other files.

jus71n742 10-13-2009 10:50 PM

did try it...doesn't display anything.

jus71n742 10-13-2009 11:02 PM

Still nothing, do I need to remove the <html> tags at the beginning and the end of the menu.php, topmenu.php, footer.php? Also do I still include them like did above in default.html?
and lastly should I do anything special with the JS inside what I just made into a .php script? or are the included html tags surrounding them work just fine?

Wim Sturkenboom 10-14-2009 04:32 AM

Sorry, the existing html should only be the stuff that's inside the body tags (so excluding the body tags.

Code:

<?php
include("menu.php");
include("topmenu.php");
include("footer.php");
?>
<html>
<header>
</header>
<body>

<?php
topmenu();
menu();
footer();
?>
</body>
</html>


Below is how I use it
page.inc.php
Code:

<?php

include("../inc/menu.inc.php");

function do_htmlheader($title="")
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<?php
    echo "<head>\n";
    if(isset($_SESSION['db']))
    {
        $db=strtoupper($_SESSION['db']);
        echo "<title>Incident Logging System - $db - $title</title>\n";
    }
    else
        echo "<title>Incident Logging System - $title</title>\n";
    echo "<link rel=\"stylesheet\" href=\"btd2.css\" type=\"text/css\">\n";
    echo "<link rel=\"stylesheet\" href=\"menu.css\" type=\"text/css\">\n";
?>
<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<script type="text/javascript">
<!--
window.onload=montre;

/******************/
/* show a submenu */
/******************/
function montre(id)
{
    var d = document.getElementById(id);
    // hide submenus
    for (var i = 1; i<=10; i++) {
        if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
    }
    if (d) {
        d.style.display='block';
    }
    else
    {
    }
}

//-->
</script>

<?php
    echo "</head>\n";
    // we add a montre (show) here to remove open menus when a user clicks on another element
    echo "<body>\n";

    echo "<div id=\"menu\">\n";
    display_menu();
    echo "</div>\n";

    // if one puts the onclick event in the body, the context menu for the submenus does not work with the mouse
    // it confused me as a user and will definitely confuse other users
    echo "<div id=\"site\" onclick=\"javascript:montre();\">\n";

    if(isset($_SESSION['db']))
    {
        $db=strtoupper($_SESSION['db']);
        echo "<h1>Incident Logging System ($db)<hr />$title</h1>\n";
    }
    else
    {
        echo "<h1>Incident Logging System<hr />$title</h1>\n";
    }
}

function do_htmlfooter()
{
    echo "</div>\n";
    echo "</body>\n";
    echo "</html>\n";
}
?>

The function display_menu() is defined in menu.inc.php
Code:

<?php
function display_menu()
{
// menu taken from
//  http://tutorials.alsacreations.com/modelesmenus/hd1.htm
//  http://tutorials.alsacreations.com/modelesmenus/hd2.htm
// slightly modified (css and added onfocus) and converted to php

?>
I don't escape from php as the menu content dependfs on the login of the user
<?php

}
?>

I include page.inc.php in every page that I have
Code:

<?php
include ("../inc/page.inc.php");

do_htmlheader("Incident Overview");

// other PHP code specific for the page

do_htmlfooter();
?>

Hope this helps enough. And check your server logs to see where it goes wrong.

jus71n742 10-16-2009 11:11 AM

Thank you I will try that. I am unable to edit right now so I will let you know in the next day or so if it works

jus71n742 10-21-2009 12:42 PM

ok so I have everything KINDA working, the site finds all the image stuff I need. Now my question is how to get the Java Script working for the menu's submenus. I have tried including the exported .htm and what I just converted to .php The only issue is in the side menu not showing the submenu on mouseover like it does if I just run that HTML. I have the pages included correctly cause all of the images are called with the .htm and .php pages that I mentioned above. it is just not using the javascript.

jus71n742 10-21-2009 04:44 PM

never mind, i forgot a file.

Wim Sturkenboom 10-21-2009 11:27 PM

Great. Please mark your thread as solved using the thread tools just above the first post on the page.


All times are GMT -5. The time now is 02:43 PM.