buttons and "action"

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

<form id="chooser" action="chooser.php" method="post">

<button type="submit" name="plan" value="basic">

On my web page I'm building I will have a two column layout with header.
The left column will have the menu which I think I can do better with
buttons. What all can I do with "action"?
As that is obviously the key to making it all work when a button is clicked

When the page loads, an initial page loads in the right column.
When user clicks a button, that page is changed. I've seen this done before
so I know it will work.

So how do I pass a value on to the next step?

For instance, my variable will be named $item.

if ($item=="basic"){echo "basic"}


Re: buttons and "action"


Quoted text here. Click to load it

You can do all this with html and straightforward links but if you
really want to do it with PHP then use differently named input
buttons.  No need to set the action to a different page, you can do it
all in the same page

<input type="submit" name="basic" value="basic">
<input type="submit" name="advanced" value="advanced">

Check which is pressed by seeing if it is set

if( isset($_POST['basic'])){
$rightcolumn="'basic' html goes here";
$rightcolumn="'advanced' html goes here";
echo $rightcolumn;

Or you could use switch if you prefer.
Geoff Berrow (Put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs www.ckdog.co.uk/rfdmaker

Re: buttons and "action"


Quoted text here. Click to load it

Submitting a form, but forms are not really navigation elements.

Quoted text here. Click to load it

Technically maybe, but it may cause a lot of problems for the users.
Don't do it. Use normal links in your menu (you can style them as
buttons if you want with CSS), and don't try to just change a part of
the page when clicking a link. Use flat pages. One URL, one document.


Re: buttons and "action"

Quoted text here. Click to load it

Yeah, I'd have to say that a switch statement would be best in this
scenario.  You can pass the values through the url (ex: www.yourwebsite.com=


if (isset($_GET['p'])) {
             $p = $_GET['p'];
    } elseif (isset($_POST['p'])) {
         $p = $_POST['p'];
    } else {
         $p = NULL;

     switch ($p) {

     case 'basic';
            $page = 'basic.html';

     case 'advanced';
        $page = 'advanced.html';

        $page = 'basic.html';

    include ('pages/' . $page);



Re: buttons and "action"

brkn wrote:
Quoted text here. Click to load it

It is not necessary to pass them in the URL.

Set your form method to POST and set up you buttons to submit the form.

<form action="" method="POST">
<input type="submit" name="a" value="a1">
<input type="submit" name="b" value="b1">

When either button in clicked the form will be submitted and the post
variable will contain the data.

Indexed with (name) and filled with (value).

pretty simple actually.

Then just use whatever control structure that fits the bill to perform
any task depending on the values


Site Timeline