开发者

Nothing was clicked - php

I have a form as such:

<form method="post" action="user/?action=reply">
    <!--blah -->
    <input type="submit" name="action" value="Reply">

</f开发者_运维百科orm>

In user/index.php file I have:

switch ($_GET['action'])
{

    case 'reply':
        if (isset($_POST['action']) && $_POST['action'] == 'Reply' )
        {
            require_once USER_ROOT . 'thread_reply.php';
        }
        else
        {
            echo "Nothing was clicked";
        }
...

The output is nothing was clicked.

error_reporting(E_ALL); doesn't return anything.

Edit:

print_r($_GET) returns: Array ( [action] => reply )

print_r($_POST) returns an empty array


You are checking $_GET in your switch statement, but your form is set to post. Change it to method="get" or use $_POST instead.

Since the HTTP server can only send one type of request (GET or POST), your form will send a POST request. I recall that depending on the browser and also your PHP configuration, GET variables might be ignored when using POST requests.

Consider using hidden form fields instead.

And remember, a GET request should be used to retrieve, and a POST request should be used to create. In your case, it seems a POST is more appropriate (reply).


I have no idea why you are using two values but .. :)

You should remove the parameter from the form action and convert it to a hidden field inside the form. I'm not so sure you can have both a get an a post parameter when doing a request.

Like this:

<form method="post" action="user">
    <!--blah -->
    <input type="hidden" name="target_action" value="reply" />
    <input type="submit" name="action" value="Reply" />
</form>

And change the php file like this:

switch ($_POST['target_action'])
{

    case 'reply':
        if (isset($_POST['action']) && $_POST['action'] == 'Reply' )
        {
            require_once USER_ROOT . 'thread_reply.php';
        }
        else
        {
            echo "Nothing was clicked";
        }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜