Northern Flame Posted January 5, 2008 Share Posted January 5, 2008 I've seen some forms that have something like <form name="form" method="POST"> whats the point of the name? I've tried messing around with this i created a php page like this: <?php if(!isset($_POST['submit'])){ ?> <form method="POST" name="form"> <input type="text" name="text" size="20"> <input type="submit" name="submit" value="submit"> </form> <?php } else{ echo $_POST['form'] . "<br>\n"; echo $_POST['text'] . "<br>\n"; echo $_POST['submit'] . "<br>\n"; } ?> just to see what $_POST['form'] returns is it comes back blank. is there a point to the name in a form? Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted January 5, 2008 Share Posted January 5, 2008 isn't the name used to identify different forms. It's possible a page to have multiple forms isn't it? I personally can't say for sure. On sites I had more than one form, I used a different name for the submit button and that did the trick! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 5, 2008 Share Posted January 5, 2008 The name attribute in the <form ...> tag only has meaning in the browser and is used by client-side scripting languages. Quote Link to comment Share on other sites More sharing options...
john010117 Posted January 5, 2008 Share Posted January 5, 2008 The name attribute in the <form ...> tag only has meaning in the browser and is used by client-side scripting languages. Expanding on that, it's used primarily by JavaScript for identifying specific fields in the form. Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted January 6, 2008 Share Posted January 6, 2008 Yes, the form name is used to identify the form. This way, you can use Javascript (heaven forbid!) to update form fields in the correct field. This way, you can have a permanent login script on every page of your site and still have an email form too. I use this principle when designing some of my sites (and yes, I do update forms using JavaScript too sometimes). I think dreamwever names them automatically form1 etc. but it's useful to name them yourself too. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 7, 2008 Share Posted January 7, 2008 Like others said, you can use JavaScript to easily access the form like this: <script> document.write(document.forms['form'].text.value); </script> That should print out whatever value in the <input name='text' /> field of the form name 'form'. In your case, it won't print out anything because the input doesn't have a value. But if you change it to: <input name='text' value='hi' />, the code will print "hi" The $_POST['form'] echos back a blank because it has no value. You didn't type anything in (not that you could) Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted January 7, 2008 Share Posted January 7, 2008 the naming idea has long been depreciated as the more modern technique is the id tag and then getelementbyID('IDHERE').Atributeshere Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted January 9, 2008 Author Share Posted January 9, 2008 oh thanks, i now understand why forms have the names on them Quote Link to comment 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.