3
Contributors
2
Replies
26
Views
3 Years
Discussion Span
Last Post by iamthwee
0

Yes, you can use multiple submit buttons in your forms:

submit buttons: When activated, a submit button submits a form. A form may contain more than one submit button.

and:

If a form contains more than one submit button, only the activated submit button is successful.

source: http://www.w3.org/TR/html401/interact/forms.html

to access a function in other php file?

Use the action attribute of the form to point a switcher file, there you can redirect or just use include() to perform the pre-selected operation.

Here is an example:

<?php

    $print = '';
    $action = '';

    if($_POST)
    {
        $print = $_POST;

        if(array_key_exists('query', $_POST))
        {
            // do query
            $action = 'query';
        }

        if(array_key_exists('edit', $_POST))
        {
            // edit action
            $action = 'edit';
        }
    }

?>
<!DOCTYPE html>
<html>
<head>
    <title>Yet Another Form</title>
</head>
<body>

    <form method="post" action="">
        <input type="text" name="msg" />
        <input type="submit" name="query" value="search" />
        <input type="submit" name="edit" value="edit" />
    </form>

    <pre><code>
        <?php
            print_r($print);
        ?>
    </code></pre>

    <p>
        <?php
            echo $action;
        ?>
    </p>

</body>
</html>

Bye!

Edited by cereal

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.