Jump to content

unable to display textbox contents


Recommended Posts

I am doing simple program to display text entered by user..


Following is my code but its display 'error msg' instate of txtbox contents





<form action="" enctype="multipart/form-data">

Enter Date:

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

<input type="submit" value="Display"/>








$display =$_POST['txtdate'];

echo 'You have entered'.$display;




echo 'Error msg';






Link to comment
Share on other sites

The form's METHOD is either POST or GET.  The ACTION is where the form goes.  Action is allowed to be blank, it will default to the current URL.  Method defaults to POST.


Take out the enctype, and if that doesn't work add this to the top of your script:



What is the result?  Maybe your webserver is translating post data somehow.



Link to comment
Share on other sites

According to W3, the action attribute is required, and should be a URI. Technically, even action="process.php" is incorrect.

User agent behavior for a value other than an HTTP URI is undefined.

Though generally a browser will default a blank action to the same page it's executing on, it is incorrect markup.


The W3 also states that a method isn't a required attribute, and should default to GET when missing or invalid.



Link to comment
Share on other sites

Wow, I had no idea the default was GET.  I've never actually left METHOD off my forms, but I assumed it would be POST, since that's generally the purpose of forms.  Good to know.


As for invalid tags, 7 of the top 10 websites in the world aren't compliant with the HTML spec.  Nobody cares.  "Working" and "matches the RFC" are so far from each other that it's sad.

Link to comment
Share on other sites

I agree, but in a place of learning I like to follow known best practices and teach 'proper' code, no matter how archaic W3 has made it.


Upon further reading it seems I have made an ass of myself. I apologize.


4.2. Same-document References


  A URI reference that does not contain a URI is a reference to the

  current document.  In other words, an empty URI reference within a

  document is interpreted as a reference to the start of that document,

  and a reference containing only a fragment identifier is a reference

  to the identified fragment of that document.  Traversal of such a

  reference should not result in an additional retrieval action.

  However, if the URI reference occurs in a context that is always

  intended to result in a new request, as in the case of HTML's FORM

  element, then an empty URI reference represents the base URI of the

  current document and should be replaced by that URI when transformed

  into a request.


Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.