Jump to content

hidden form fields


Recommended Posts

What are the purposes of hidden form fields, I know XHTML, CSS, PHP, SQL, Java Script, what are hidden form fields going to be useful for. for instance if it has to do with processing the form, I always call each variable, and afterwards I mail them, so I wouldn't have a need for a hidden field that gives the email address and subject. What other purposes would they be useful for. I have been looking around online for there purpose, and can't find anything that is helpful. Thanks again for the help.

Link to comment
Share on other sites

Perhaps you are loading a users information into a form. You need to pass the user's unique id (databse auto generated number) but don;t want the user using hte form to see it. So you store it in a hidden inout field...it will get passed the same as a regular one except the user does not see it.If you get into createing complex applications you quickly realise how useful it is.You could use them to store and pass parameters instead using a querystring too.

Link to comment
Share on other sites

Not really, only the place where to store data that should not instantly be visible to the user (remember they can show the source, do not use them for passwords)However you can do something more with them, with JavaScript I mean.You can edit its value onclick of something in your form, or add one, whatever. You can leave it empty when sending the form to the user, but let JavaScript add a value afterwards. Could be handy :)

Link to comment
Share on other sites

Sometimes when you reload the same page for validation/ data manipulation then you have say PHP code in the page but that must not be executed during the first time and must execute when the page loads on submit. the hidden fields is used in the bottom of the form with some value.Page Start<html><? PHPif request.form("mode")="test" // this will be true only when the page loads the 2nd time.{..........}?><other HTML code><form action="samepage.php">.........page bottom<input type=hidden name="mode" value="test" /></html>

Link to comment
Share on other sites

If that is the case, you might use this instead:

<?php echo "<form ...>",  "<input type=\"text\" name=\"Something\" value=\"",  (isset($_POST['Something']) == true)    ?$_POST['Something'] :"alternate value", "\" />";?>
Recognise the conditional operator: (variable == value) ?"if true do this" :"else do this" :) Edited by Dan The Prof
Link to comment
Share on other sites

well sort of if you mean that repopulation. For instance someone fills out a form, it gets validated through javascript and php, at both time the form refreshes normally clearing the data, I would rather have the data stay in the form, so they don't have to lose the data and retype it all everytime they make a mistake. I don't know if it's possible to have the proper checkbox fields repopulate, but I know the text can be reentered.

Link to comment
Share on other sites

same idea in ASP, i'm not good in PHP... validations must not happen when the page loads first time, because it will fail. but on submit it will. this is just to avoid a seperate page for validations etc...<% MODE = Request.Form("mode") IF MODE = "Check" THENThis is where your validation, SQL Update code will be.END IF %><html><form action="Currentpage.asp" method="post" name="frm">HTML Code for textbox etc...<input type="Hidden" name="mode" value="Check" /></form></html>The top ASP code will not be executed in the first time, since the IF condition will fail. But when the submit button is clicked, the page is reloaded but by that time the hidden textbox will get the value and will go through IF condition. This will make the top ASP code to execute.I guess i didnt confuse more

Link to comment
Share on other sites

Also useful for file uploading in php<form enctype="multipart/form-data" action="uploader.php" method="POST"><input type="hidden" name="MAX_FILE_SIZE" value="100000" />Choose a file to upload: <input name="uploadedfile" type="file" /><br /><input type="submit" value="Upload File" /></form> Sets the maximum allowable file size, in bytes, that can be uploaded (sets the max file size to 100KB in this example)I also use it alot for this.

Perhaps you are loading a users information into a form. You need to pass the user's unique id (databse auto generated number) but don;t want the user using hte form to see it. So you store it in a hidden inout field...it will get passed the same as a regular one except the user does not see it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...