believeinsharing Posted November 9, 2011 Share Posted November 9, 2011 I am doing simple program to display text entered by user.. Following is my code but its display 'error msg' instate of txtbox contents <html> <head><title>Date</title></head> <body> <form action="" enctype="multipart/form-data"> Enter Date: <input type="text" name="txtdate"/> <input type="submit" value="Display"/> </form> </body> </html> <?php if(isset($_POST['txtdate'])) { $display =$_POST['txtdate']; echo 'You have entered'.$display; } else { echo 'Error msg'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/250794-unable-to-display-textbox-contents/ Share on other sites More sharing options...
xyph Posted November 9, 2011 Share Posted November 9, 2011 What in your form tells PHP to put the 'txtdate' variable into the $_POST array? Is the form being posted? Is a blank action in a form considered valid? Quote Link to comment https://forums.phpfreaks.com/topic/250794-unable-to-display-textbox-contents/#findComment-1286769 Share on other sites More sharing options...
believeinsharing Posted November 9, 2011 Author Share Posted November 9, 2011 yes... When I run form.. it shows blank textbox when I entered some text in textbox and click on Display button Its shows Error.. I tried 1 more option I put whole php code in another php file and add that in action attribute of form.. but still showing error msg. Quote Link to comment https://forums.phpfreaks.com/topic/250794-unable-to-display-textbox-contents/#findComment-1286773 Share on other sites More sharing options...
thomasw_lrd Posted November 9, 2011 Share Posted November 9, 2011 What he's saying is you're form doesn't do anything. You should look up form action= and make the form actually do something. form action = post? maybe? Quote Link to comment https://forums.phpfreaks.com/topic/250794-unable-to-display-textbox-contents/#findComment-1286785 Share on other sites More sharing options...
ManiacDan Posted November 9, 2011 Share Posted November 9, 2011 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: print_r($_POST); What is the result? Maybe your webserver is translating post data somehow. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/250794-unable-to-display-textbox-contents/#findComment-1286786 Share on other sites More sharing options...
believeinsharing Posted November 9, 2011 Author Share Posted November 9, 2011 thanks to all.... its working nw... Quote Link to comment https://forums.phpfreaks.com/topic/250794-unable-to-display-textbox-contents/#findComment-1286789 Share on other sites More sharing options...
xyph Posted November 9, 2011 Share Posted November 9, 2011 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. http://www.w3.org/TR/html4/interact/forms.html#h-17.3 Quote Link to comment https://forums.phpfreaks.com/topic/250794-unable-to-display-textbox-contents/#findComment-1286791 Share on other sites More sharing options...
ManiacDan Posted November 9, 2011 Share Posted November 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/250794-unable-to-display-textbox-contents/#findComment-1286797 Share on other sites More sharing options...
xyph Posted November 9, 2011 Share Posted November 9, 2011 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. http://www.ietf.org/rfc/rfc2396.txt Quote Link to comment https://forums.phpfreaks.com/topic/250794-unable-to-display-textbox-contents/#findComment-1286801 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.