HTML form not POSTing

Asked
Active3 hr before
Viewed126 times

6 Answers

90%

Your <input> tag needs name attribute. it'll be used to be index in your $_POST, so, this input:, Are there countries that ban public sector unions, but allow private sector ones? ,To learn more, see our tips on writing great answers.,Thanks for contributing an answer to Stack Overflow!

Your <input> tag needs name attribute. it'll be used to be index in your $_POST, so, this input:

<input name="some" type="text" />

will produce:

$_POST['some']
load more v
88%

GET is better for non-secure data, like query strings in Google,Appends form-data inside the body of the HTTP request (data is not shown in URL),Appends form-data into the URL in name/value pairs,The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute).

Definition and Usage

The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute).

method

Definition and Usage

The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute).

action
load more v
72%

An HTML form on a web page is nothing more than a convenient user-friendly way to configure an HTTP request to send data to a server. This enables the user to provide information to be delivered in the HTTP request.,Note: Servers can be configured with a size limit for files and HTTP requests in order to prevent abuse.,The <form> element defines how the data will be sent. All of its attributes are designed to let you configure the request to be sent when a user hits a submit button. The two most important attributes are action and method.,The method attribute defines how data is sent. The HTTP protocol provides several ways to perform a request; HTML form data can be transmitted via a number of different methods, the most common being the GET method and the POST method

<form action="https://example.com">
load more v
65%

Take out the @ symbols - they suppress errors,its probably the file functions?,symbols - they suppress errors,Take out the file functions for now and see if the data posts to the page:

My html form:

<form id="form1" name="form1" method="post" action="anthonyBook.php">
   <p>
      <label for="name">name</label>
      <input type="text" name="name" id="name" />
   </p>
   <p>
      <label for="email">email</label>
      <input type="text" name="email" id="email" />
   </p>
   <p>
      <label>comments
         <input type="text" name="comments" id="comments" />
      </label>
   </p>
   <p>
      <input type="submit" name="submit" id="submit" value="Submit" />
   </p>
</form>

My php page:

<?php
echo '<a href="form1.html">sign my guest book</a>';

$guestbook = @fopen("sign.txt", "r");
    while (!feof($guestbook)) 
        {
            echo "\n" . @fgets($guestbook) . "<br />";
        }
@fclose($guestbook);

$datetime=date("y-m-d h:i:s");
$data = "<h1>" . $datetime . " \n" . $_POST['name'] . " \n" . $_POST['email'] . " \n" . $_POST['comments'] . "</br></h1>";

$guestbook = @fopen("sign.txt", "w");
echo @fputs($guestbook, $data);
@fclose($guestbook);
?>
load more v
75%

One more thing to notice: the “action” on the form is now missing. Technically, this is not valid HTML. However, by not putting in an action, browsers will assume that the form is submitting to itself. This is important because it will also preserve the querystring when the form is submitted (the ?lang=english part). You can use server variables like $_SERVER['PHP_SELF'] and $_SERVER['QUERY_STRING'] to build an action value.,POST data is submitted by a form and “posted” to the web server as form data. POST data is encoded the same way as GET data, but isn't typically visible to the user in standard browsers.,The above code will only display the submitted values if the submit button was clicked.,As easily as a user can monkey with GET data in a URL, the same thing can be done with POST data. You should always assume that the user can submit whatever form and form data that they want to, and process the data accordingly. Don't trust user input, whether it's from GET or from POST!

<?php
   echo("First name: " . $_POST['firstname'] . "<br />\\n");
   echo("Last name: " . $_POST['lastname'] . "<br />\\n");
?>
load more v
40%

One of the most powerful features of PHP is the way it handles HTML forms. The basic concept that is important to understand is that any form element will automatically be available to your PHP scripts. Please read the manual section on Variables from external sources for more information and examples on using forms with PHP. Here is an example HTML form: , You can also deal with XForms input in PHP, although you will find yourself comfortable with the well supported HTML forms for quite some time. While working with XForms is not for beginners, you might be interested in them. We also have a short introduction to handling data received from XForms in our features section. , There is nothing special about this form. It is a straight HTML form with no special tags of any kind. When the user fills in this form and hits the submit button, the action.php page is called. In this file you would write something like this:

<form action="action.php" method="post">
   <p>Your name: <input type="text" name="name" /></p>
   <p>Your age: <input type="text" name="age" /></p>
   <p><input type="submit" /></p>
</form>
load more v

Other "undefined-undefined" queries related to "HTML form not POSTing"