Content TextArea in PHP with $ _POST

1

I am creating a test form which I want you to send me the entered data to php . He sends me the Name and the Mail but the text entered in TEXTAREA does not send it to me. I leave the code

feedback.html:

<form action="feed.php" method="post">
<table>
    <tr>
        <td >Your Name:</td>
    </tr>
    <tr>
        <td ><input type="text" name="name" size="25" maxlength="30" /></td>
    </tr>

    <tr>
        <td >Your Email Address:</td>
    </tr>
    <tr>
        <td ><input type="text" name="email" size="25" maxlength="30" />
</td>
    </tr>
    <tr>
        <td >Your Feddback:</td>
    </tr>
    <tr>
        <td ><textarea rows="6" cols="40" name="feedback" form="usrform"  >
</textarea></td>
    </tr>
<tr>
    <td colspan="2" align="center"><input style="margin-left:-80px;" 
type="submit" value="Send Feddback" name="submit" /></td>
</tr>
</table>


</form>

feed.php:

<?php
$name = $_POST["name"];
$email = $_POST["email"];
$feedback = $_POST["feedback"];

echo $name . "</br>";
echo $email . "</br>";
echo $feedback . "</br>";

?>
    
asked by hayber 21.11.2017 в 17:34
source

1 answer

4
  

What is happening in this case?

By adding the attribute form within an element, it is indicating to which form that element belongs, this is beneficial for a particular case where the elements are not necessarily within the form

Ejm

<form action="feed.php" method="post" id="usrform">
  <!-- más elementos-->
</form>
<textarea rows="6" cols="40" name="feedback" form="usrform"  >
</textarea>

By sending this form, you might think that the textarea is not being sent, but since the attribute form was added, it is also sent and can be accessed from the place where it is being sent.

In your example, you are adding the attribute and there is no form element with that id, so this element is not sent as it is within form .

To solve your problem, you have two options, remove the form attribute from textarea since it is inside the form tags and you would not need to add it, or add the id to the form with the value that you already have (usrform)

<form action="feed.php" method="post">
  <textarea rows="6" cols="40" name="feedback"  >
</form>

<form action="feed.php" method="post" id="usrform">
</form>
<textarea rows="6" cols="40" name="feedback" form="usrform"  >
  

The documentation of said attribute is available in each element,   such as textarea , input , this attribute is available for button , fieldset ,input , label, meter, object, output ,select , textarea.

    
answered by 21.11.2017 / 17:41
source