0

I am trying to get the posted information and display the info using the following code:

PHP code:

        $self = $_SERVER['PHP_SELF'];
        if(isset($_POST['send'])){                
            $words = htmlspecialchars($_POST['board']);
            print "<b>".$words."</b>";
        }            ​​​​

HTML code:

<form action="<?php $self ?>" method=post> <!--$self is the directory of the page itself-->
        <p><i>Comment</i></p>
        <textarea name="board" rows="20" cols="10"></textarea>
        <input name="send" type="hidden" />
        <p><input type='submit' value='send' /></p>
</form>  

The code above will work as I intented. However, if I get rid of the input name="send" type="hidden", the user input message will not show up once the send button is clicked. Why would this happen?

2
  • 2
    What's the name of your submit button? ;) Commented Jun 27, 2013 at 0:59
  • 2
    you can remove the action="<?php $self?>" since you are directing it on the same page. Commented Jun 27, 2013 at 1:06

3 Answers 3

4

You need to add name='send' to your submit button, your PHP code is reading the name of the form elements, and you have not specified one for your submit button.

<form action="<?php $self ?>" method=post> <!--$self is the directory of the page itself-->
        <p><i>Comment</i></p>
        <textarea name="board" rows="20" cols="10"></textarea>
        <p><input type='submit' name='send' value='send' /></p>
</form>  

Also, a quick note - you can change your form method to GET instead of POST to easily see what form data you're sending in the URL bar.

Sign up to request clarification or add additional context in comments.

Comments

2

This is because you are checking that the POST variable "send" isset. That is what you named your hidden input.

You should add a name to your submit input. Example:

    <p><input type='submit' name="submit_button" value='send' /></p>

Now in your php, check for the name of your submit button. I used "submit_button" in this example. Here is modified code example:

    $self = $_SERVER['PHP_SELF'];
    if(isset($_POST['submit_button'])){                
        $words = htmlspecialchars($_POST['board']);
        print "<b>".$words."</b>";
    }  

Comments

0

Dont have to bother naming your send button or anything, just remove that hidden line...

and change your php to....

 $self = $_SERVER['PHP_SELF'];
    if(isset($_POST)){                
        $words = htmlspecialchars($_POST['board']);
        print "<b>".$words."</b>";
    }     

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.