dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: Form Fields

  1. #1
    Join Date
    Sep 2012
    Posts
    14

    Form Fields

    Is it customary to wrap each form field in it's own div?
    Or just add a class to each imput so you can use different colors or styling if it is a required field vs. a not required field.

    Thanks,
    Michael

  2. #2
    Join Date
    Mar 2011
    Posts
    1,156
    You don't have to enclose <input> tags in a <div>. You can set the CSS for the <input> tag directly, or enclose it in any appropriate container element and set the style for the container if that works best for you.

    Do yourself a favor and spend some time with a book on CSS or an online tutorial. Don't try to pick things up as you go or you'll end up constantly frustrated and waste a lot of time and effort. Once you have the basics, the rest will fall into place for you pretty quickly.

  3. #3
    Join Date
    Sep 2012
    Posts
    14
    Hi,
    I guess div was not quite right, and I should have said container, I know you can use p and others. But if I did a form that has some fields required and others not required, I was trying to figure out if the best practice was to enclose the form fields in a container to style each field differently.

    HTML Code:
    <form...>
    <div class="FormFieldRequired"><label for="name">Name: <em>required</em></label><input type="text" name="name" id="name" value="<?php if(isset($_POST['name'])){ echo $_POST['name'];}?>"></div>
    <div class="FormField"><label for="email">E-mail: </label><input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])){ echo $_POST['email'];}?>"></div>
    </form>
    or is this the best practice way.

    HTML Code:
    <form...>
    <label for="name">Name: <em>required</em></label><input class="FormFieldRequired" type="text" name="name" id="name" value="<?php if(isset($_POST['name'])){ echo $_POST['name'];}?>">
    <label for="email">E-mail: </label><input type="text" class="FormFieldRequired" name="email" id="email" value="<?php if(isset($_POST['email'])){ echo $_POST['email'];}?>">
    </form>
    Or does it even really matter, and is it just personal preference.

    yes, I have read tutorials and articles online, but the problem is they do not always tell you the best practices. they are normally just how one person does it, which might not be the best way. And I know with PHP even stuff that has recently been written is using depreicated functions and isn't really the best way to do stuff.

    Thanks,
    Michael

  4. #4
    Join Date
    Sep 2012
    Posts
    14
    Oops, second form should have been this. I had to repost it because I can't edit messages.
    HTML Code:
    <form...>
    <label for="name">Name: <em>required</em></label><input class="FormFieldRequired" type="text" name="name" id="name" value="<?php if(isset($_POST['name'])){ echo $_POST['name'];}?>">
    <label for="email">E-mail: </label><input type="text" class="FormField" name="email" id="email" value="<?php if(isset($_POST['email'])){ echo $_POST['email'];}?>">
    </form>
    Thanks,
    Michael

  5. #5
    Join Date
    Mar 2011
    Posts
    1,156
    You're right that this isn't an instance where there's a true best practice. You start with valid HTML mark-up and then code for the desired appearance. This sometimes requires a container, or even multiple containers, to allow for differentiating instances within the CSS styling. Good luck!

  6. #6
    Join Date
    Sep 2012
    Posts
    14
    thanks for that, that is good to know I do not have to worry about some best practices stuff concerning this at least.

    Michael

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles