SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    May 2001
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick Question About Forms!

    Hi folks,

    I just have a really quick question about forms...I know that it isn't quite the place for it, but it has to do with getting a value to use as a year in a MySQL database using PHP.I know that you put INPUT TYPE=TEXT when you want to have a text entry in a form field, but what about when you want it to be numeric? In particular I am trying to have a 4 digit year entry, if that helps!
    Here is the code:
    Year: <INPUT TYPE=???? NAME="pdate" VALUE="<?php echo($pdate); ?>" SIZE=20 MAXLENGTH=4><BR>

    is that anywhere near right, notwithstanding the unknown type? (P.S. - it is stored as a YEAR type in MySQL if that might make a difference).


    Cheers,

    XGuy

  2. #2
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think you can set a input box that will only allow numbers. If you can, Great! Something I didn't know.. Anyone else know if you can or can't? But in my experience I have never seen anything like it.

    If there isn't I would like to know a function in PHP that will be able to tell if a variable is numeric or not.

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you're right manipura there's no "number only" input. if you want to check that when someone submits something, you can do it client side w/ JavaScript or w/ a reg. expression in PHP.

    XGuy, in your example, you're displaying an existing value from MySQL, right? then yeah, it's fine the way you have it, you just need input type="text". but as i said if you want to verify that it's a date when someone changes it, you'll have to use a reg. expression in PHP.

  4. #4
    SitePoint Evangelist Umair.ms's Avatar
    Join Date
    Sep 2000
    Location
    Lahore, Pakistan
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no way to make a text field to accept numbers (only) by using any html tags.

    But there are other methods:
    • Use a client-side Javascript to check for the valid type (numeric) and range before submitting the form.
    • Use a server-side scripting language (PHP, APS, etc) to check for the valid type and range.
    • Display a drop-down list box with numbers from the range of 1900 to 2010, etc. If its the year of birth, you can get away with 00 to 99.
    TinyPlanet.org
    Discuss and Debate World Events, Politics and Religion.
    Interact and Share your Views with People around the Globe.


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
  •