-1

I'm creating a script on my website to echo the contents of an entire form. My html code looks like this:

<form action ="forma.php" method ="POST" name="FORM-TXT">
  First name:<br>
  <input type="text" name="firstname"><br>
  Last name:<br>
  <input type="text" name="lastname">
          <input type="submit" name="submitsave" value ="Submit">
</form>
My PHP code looks like this:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//use the html Name element to attach html to php scripts
//V-----------------=|txt file codes|=-----------------V
$text = $_POST["FORM-TXT"];
echo $text; 
?>

When I run the form, this error is thrown:

Notice: Undefined index: FORM-TXT in /homepages/31/d585123241/htdocs/mail/forma.php on line 7

How can I make it so the entire form echos, but no specific elements are referenced, only the form.

j08691
  • 204,283
  • 31
  • 260
  • 272
500man
  • 15
  • 5

2 Answers2

0

Like @EatPeanutButter says

<?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    //use the html Name element to attach html to php scripts

    //V-----------------=|txt file codes|=-----------------V
    $text = $_POST;

    var_dump($text); 

    ?>
Jose Bernalte
  • 177
  • 1
  • 10
0

You can't print out HTML that way. However, you can do one of two things:

1) Turn the entire HTML string into a variable, like so:

$form = <<<HTML
        <form action ="forma.php" method ="POST" name="FORM-TXT">
          First name:<br>
          <input type="text" name="firstname"><br>
          Last name:<br>
          <input type="text" name="lastname">
                  <input type="submit" name="submitsave" value ="Submit">
        </form>
HTML;

echo $form;

The other way is to simply close the php tag right after your logic, and the form will display automatically:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//use the html Name element to attach html to php scripts
//V-----------------=|txt file codes|=-----------------V 
?>

<form action ="forma.php" method ="POST" name="FORM-TXT">
  First name:<br>
  <input type="text" name="firstname"><br>
  Last name:<br>
  <input type="text" name="lastname">
          <input type="submit" name="submitsave" value ="Submit">
</form>
misdreavus79
  • 126
  • 1
  • 9