简体   繁体   中英

PHP functions in included files

I've been working on this problem way too long, and I'm getting nowhere. So please excuse what might be a vague question.

Basically, I've created what I think is a modular website, using php and html. I have an index.php page, which 'include's header.php, footer.php, and then in the middle, a content.php page based on 'case' statements in index.php. There are several choices for the content page, but I'll only mention content.php for now.

And here's the problem: content.php has a form, whose 'action' is content.php (with method = post), which is the file located in my web directory, and not the included file. When I hit 'submit', I need the processed form to come up in the included content.php file, displayed with header.php and footer.php, but it just goes to the isolated file on the server.

Any suggestions on a new approach? Thanks!

Set the action to point to the file that includes content.php.

You seem to have basically this:

index.php:

<?php
    include('header.php');
    switch($_GET['a']){
        case 'foo':
            include('content1.php');
            break;
        case 'bar':
            include('content2.php');
            break;
        default:
            include('default.php');
            break;
    }
    include('footer.php');
?>

Then your action points to index.php?a=foo , not, say, content1.php.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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