cags Posted November 13, 2009 Share Posted November 13, 2009 Simple question, more an academic matter than an actual problem. When using an HTML form, what are the advantages/disadvantages of using these differen't actions for a self posting form. 1. <form method="post"> 2. <form action="" method="post"> 3. <form action="literal_url_path_here" method="post"> 4. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Note: Sorry if this should have been under HTML, I placed it here simply because there is some, allbeit limited, PHP code. Link to comment https://forums.phpfreaks.com/topic/181375-form-action/ Share on other sites More sharing options...
trq Posted November 13, 2009 Share Posted November 13, 2009 I'm not sure the first two will validate, I know for sure an empty action attribute won't validate in xhtml. Link to comment https://forums.phpfreaks.com/topic/181375-form-action/#findComment-956764 Share on other sites More sharing options...
cags Posted November 13, 2009 Author Share Posted November 13, 2009 Hmm... I decided I'd test them all to see which validate. I made this little test page... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Test</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <p> This is a test?</p> <form action="bob.php" method="post"> <input type="text" name="bob" /> <input type="submit" name="submit" /> </form> </body> </html> But it doesn't validate, I can't work out why. The error messages are... 1. Error Line 10, Column 33: document type does not allow element "input" here; missing one of "p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "pre", "address", "fieldset", "ins", "del" start-tag <input type="text" name="bob" /> The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element. One possible cause for this message is that you have attempted to put a block-level element (such as "<p>" or "<table>") inside an inline element (such as "<a>", "<span>", or "<font>"). 2. Error Line 11, Column 40: document type does not allow element "input" here; missing one of "p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "pre", "address", "fieldset", "ins", "del" start-tag <input type="submit" name="submit" /> The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element. One possible cause for this message is that you have attempted to put a block-level element (such as "<p>" or "<table>") inside an inline element (such as "<a>", "<span>", or "<font>"). ... but I can't figure out why it doesn't like the form there. Perhaps I've done something stupid, but I can't spot anything. Link to comment https://forums.phpfreaks.com/topic/181375-form-action/#findComment-956803 Share on other sites More sharing options...
sawade Posted November 13, 2009 Share Posted November 13, 2009 I didn't see anything wrong with the code either. So I played with it. Validator wanted to look as such... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test</title> </head> <body> <p>This is a test?</p> <form method="post" action="bob.php"> <table> <tr> <td><input type="text" name="bob" value="" /></td> <td><input type="submit" name="submit" value="Submit" /></td> </tr> </table> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/181375-form-action/#findComment-956822 Share on other sites More sharing options...
cags Posted November 13, 2009 Author Share Posted November 13, 2009 That is un-semantic code though, which is not correct. Link to comment https://forums.phpfreaks.com/topic/181375-form-action/#findComment-956877 Share on other sites More sharing options...
sawade Posted November 17, 2009 Share Posted November 17, 2009 How do you figure. Link to comment https://forums.phpfreaks.com/topic/181375-form-action/#findComment-959219 Share on other sites More sharing options...
cags Posted November 17, 2009 Author Share Posted November 17, 2009 The table and hence related tags (tr, th, td, etc.) are used for presentation of tablature data. For example a League table with Played, Won, Lost, Points etc. A form is a bit more or a gr(a|e)y area in as much as some people do consider it tablature data, but in the grand scheme of things it is probably not tablature data in the way intended by the w3c expectations of symantic use. Link to comment https://forums.phpfreaks.com/topic/181375-form-action/#findComment-959221 Share on other sites More sharing options...
sawade Posted November 17, 2009 Share Posted November 17, 2009 True. But last time I checked tables were still considered a foundation for xhtml. You could use CSS to create two columns (or whatever) for your form in place of a table. Not everyone knows how to do so, so tables are nice to fall back on when the designer is a beginner or novice even. You can always add CSS to the tables to further beautify the form. Link to comment https://forums.phpfreaks.com/topic/181375-form-action/#findComment-959223 Share on other sites More sharing options...
jcombs_31 Posted November 17, 2009 Share Posted November 17, 2009 I wrap my input tags with fieldset, obviously grouped accordingly, this will then validate. You could also use a div or p, but that is not semantic as far as I'm concerned. Link to comment https://forums.phpfreaks.com/topic/181375-form-action/#findComment-959226 Share on other sites More sharing options...
cags Posted November 17, 2009 Author Share Posted November 17, 2009 I wrap my input tags with fieldset, obviously grouped accordingly, this will then validate. You could also use a div or p, but that is not semantic as far as I'm concerned. Curious. I'd tried using both div and p tags to fix it but it didn't work. I had however placed the tags outside the form tags, trying it again with the div tags inside the form does indeed validate. Any ideas why this is? Am I missing something obvious? Your quite right in as much as fieldset would perhaps be the most semantic solution, it's just annoying that I'd have to reset the styling in the CSS. Still I guess that doesn't really matter in the end. Link to comment https://forums.phpfreaks.com/topic/181375-form-action/#findComment-959242 Share on other sites More sharing options...
jcombs_31 Posted November 17, 2009 Share Posted November 17, 2009 I guess the XHTML spec just doesn't want input tags floating around without being contained. I think the idea is to have properly organized fieldsets for the data. Just quickly set the fieldset border to none and set your margins and padding. Link to comment https://forums.phpfreaks.com/topic/181375-form-action/#findComment-959344 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.