开发者

Let PHP decide which part of the page to load

开发者 https://www.devze.com 2023-02-11 16:36 出处:网络
I have two buttons. If o开发者_如何学编程ne button is clicked, part one of the file should be displayed. When the other button is clicked, the other part should be displayed.

I have two buttons. If o开发者_如何学编程ne button is clicked, part one of the file should be displayed. When the other button is clicked, the other part should be displayed.

And you have to be able to switch between those pages anytime.

Anyone an idea how to do this (in php)?


First of all: you really should express what you have already tried to achieve this and why things are not working. This is really basic stuff and after reading the PHP manual and some HTML tutorials, you really should be able to get this thing going on your own.

The easiest way would be to make your buttons include a different parameter:

<button onclick="window.location.href='index.php?page=foo';">click me</button>
<button onclick="window.location.href='index.php?page=bar';">click me</button>

And read out the parameter with PHP:

<?php

if (isset($_GET['page'])) {
    switch($_GET['page']) {
        case 'foo':
            // include page foo
        break;
        case 'bar':
            // include page bar
        break;
    }
}

Disclaimer: I said easiest, not most elegant. :)


for instance try:

your form:

<form name="form" action="<?=$_SERVER['PHP_SELF'];?>" method="post">

    ... your form fields ...

  <input type="submit" name="btn1" value="go1" />
  <input type="submit" name="btn2" value="go2" />

</form>

your php verification file: (it can be the same file as you wish)

anywhere in your form you need to verify the objects of the form that was sent:

<?

if ($_POST['btn1'] = "go1") {

  ... the instructions ...

}

if ($_POST['btn2'] = "go2") {

  ... the instructions ...

}


?>

That all! I hope this help you!

0

精彩评论

暂无评论...
验证码 换一张
取 消