SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru Todd Temple's Avatar
    Join Date
    Mar 2005
    Location
    Tennessee
    Posts
    797
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What Is The Logic Behind Where The Form Action Code Is Placed?

    I have had several issues with forms in the past as to where the action line is placed and where the closing form tag is placed as well. What is the logic behind where they are placed? Does anyone know the rules on form elements and specifically where they need to begin and end?

    Here is my example:

    Code:
    <html>
    <head>
    </head>
    <body>
    <form action="index.php" method="post">
    <table>
    	<tr>
    		<td>Name:</td>
    		<td><input name="name" type="text" value="<?php echo $_POST['name'] ?>" size="24" tabindex="1"></td>
        </tr>
        <tr>
    		<td>Email:</td>
    		<td><input name="email" type="text" value="<?php echo $_POST['email'] ?>" size="24" tabindex="1" /></td>
        </tr>
    	<tr>
    		<td>&nbsp;</td>
    		<td><input name="submit" type="submit" value="Submit" /></td>
        </tr>
    </table>
    </form>
    </body>
    </html>
    Thanks in advance to anyone with some insight!
    Todd
    Todd Temple > T2 Design

  2. #2
    Team ********* Louis Simoneau's Avatar
    Join Date
    Sep 2009
    Location
    Melbourne, Australia
    Posts
    228
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your first input tag ("name") is not closed correctly. You need to add a slash ( / ) before the closing angle bracket. Otherwise your action attribute is correctly placed (in the opening form tag), and your closing form tag is correct as well.

    Tables are for presenting data in a table, though. If you just want to layout your form in a grid you should use divs and position them with CSS. You should also be using the label element for the labels of each field. If you set the "for" attribute of the label elements correctly it will make it so that clicking on the label will place the cursor in the associated form field, and is also could for accessibility as screen readers will be able to associate which text goes with which field.

  3. #3
    SitePoint Guru Todd Temple's Avatar
    Join Date
    Mar 2005
    Location
    Tennessee
    Posts
    797
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have added the closing forward slash to that input. Would the form have not submitted without it? Just curious...
    Todd Temple > T2 Design

  4. #4
    SitePoint Member
    Join Date
    Aug 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Todd Temple View Post
    I have added the closing forward slash to that input. Would the form have not submitted without it? Just curious...
    The form would have submitted just fine without it. Browsers do correct small mistakes like this on the fly.

    Having said that, you should still code valid xhtml and close your tags properly.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •