Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts

    a couple "simple" questions about forms and php

    Hi all,

    i have setup a form which is linked to my database, but there are a couple of things that im not sure how to do

    1. how do i make it so all of my textboxes lign up vertically? at the mo the lables are different lengths and the textboxes look a mess because they directly follow the lables therefor all out of align, is there a way of ligning them up without having them on a seperate line?

    2 how do i go about doing a date of birth: so far i have 3 combo boxes 1 for day,month,year, is there a way of filling the year one with years with out having to type every year in and how could i use all three to have just 1 entry, for example can i have a variable which has the value of (combo day)+(month)+(year), is this the best way?

    3. i have a gender option which is radio buttons, how do i get the php code to give a varible a value depending on the option chosen(male radiobutton is called gender_m and female is called gender_f) eg if male was selected then $gender = male. would i need an if statement and if so how would i do it?

    thanks for your time
    Luke
    Last edited by LJackson; 08-13-2008 at 05:12 PM.

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    1:

    Use tables:

    Code:
    <table>
    <tr><td>Name:</td><td>input field</td></tr>
    <tr><td>Email:</td><td>input field</td></tr>
    <tr><td>Birth Day:</td><td>input field</td></tr>
    </table>


    -----
    Leonard Whistler

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    i thought tables were "bad"? thought they were not good coding or something like that lol, well thats what i read somewhere, so ive been using divs since, are tables bad???

    cheers
    luke

  • #4
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by LJackson View Post
    i thought tables were "bad"? thought they were not good coding or something like that lol, well thats what i read somewhere, so ive been using divs since, are tables bad???

    cheers
    luke
    Nothing wrong with tables for tabular data, and the form is tabular data.





    -------
    Leonard Whistler

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ok cool, cheers for that

    Luke

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Quote Originally Posted by LJackson View Post
    Hi all,

    i have setup a form which is linked to my database, but there are a couple of things that im not sure how to do

    1. how do i make it so all of my textboxes lign up vertically? at the mo the lables are different lengths and the textboxes look a mess because they directly follow the lables therefor all out of align, is there a way of ligning them up without having them on a seperate line?

    2 how do i go about doing a date of birth: so far i have 3 combo boxes 1 for day,month,year, is there a way of filling the year one with years with out having to type every year in and how could i use all three to have just 1 entry, for example can i have a variable which has the value of (combo day)+(month)+(year), is this the best way?

    3. i have a gender option which is radio buttons, how do i get the php code to give a varible a value depending on the option chosen(male radiobutton is called gender_m and female is called gender_f) eg if male was selected then $gender = male. would i need an if statement and if so how would i do it?

    thanks for your time
    Luke
    1. Tables are awesome, you should always use them.

    2. Use the date stamp in your database for the field.

    3. For the radio button you would use like

    Code:
    $male = $_POST["gender_m"];
    $female = $_POST["gender_f"];

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ok so ive now used a table to align my form so thank you all for that, i have used the date stamp in my database but im not sure how to setup validation for it so that the user has to enter the date in the correct format,

    for the gender part of the form i have done what you have suggested but how do i have it check which one is checked i want it to check which one is checked and return a value (either male or female) to a varible $gender i asume ive got to use an if statment?

    cheers all for your help so far

  • #8
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by LJackson View Post
    I have used the date stamp in my database but im not sure how to setup validation for it so that the user has to enter the date in the correct format,
    I would use a drop down select box so that the data is sent in the correct format, which is what you were working on. Below is one that I have in my code snippet folder.

    PHP Code:
    <html>
    <body>
    <?php

    $month 
    date('F'); 
    $day date('j');
    $year date('Y');

    $months = array('January','February','March','April','May','June','July','August','September','October','November','December');
    $days range (131);
    $years range (19972015);

    $posted_month $_POST[month];
    $posted_day $_POST[day];
    $posted_year $_POST[year];

    echo 
    "<b>Todays Date:</b> $month $day, $year";
    echo 
    "<br><b>Posted Date:</b> $posted_month $posted_day, $posted_year";
    ?>
    <h2>PHP Drop Down Calendar</h2>
    <form action="<?php echo $_SERVER ['PHP_SELF']; ?>" method="post">
    <select name="month">
    <option value="">Month:</option>
    <option value=""></option>
    <?php
    foreach ($months as $value) {
    echo 
    "<option value=\"$value\">$value</option>\n";
    }
    ?>
    </select>
    <select name="day">
    <option value="">Day:</option>
    <option value=""></option>
    <?php
    foreach ($days as $value) {
    echo 
    "<option value=\"$value\">$value</option>\n";
    }
    ?>
    </select>
    <select name="year">
    <option value="">Year:</option>
    <option value=""></option>

    <?php
    foreach ($years as $value) {
    echo 
    "<option value=\"$value\">$value</option>\n";
    }
    ?>
    </select>
    <input type="submit" value="Submit" name="Submit">
    </form>
    </body>
    </html>



    ---------
    Leonard Whistler

  • Users who have thanked Len Whistler for this post:

    LJackson (08-12-2008)

  • #9
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    Hi Len Whistler,

    thank you very much, that makes life a lot easier than how i was doing it

    can you please explain these points so that i can understand them better

    $month = date('F');
    $day = date('j');
    $year = date('Y');

    <form action="<?php echo $_SERVER ['PHP_SELF']; ?>" method="post">

    i'd really appreciate it

    cheers
    Luke
    Last edited by LJackson; 08-12-2008 at 11:58 PM.

  • #10
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by LJackson View Post
    Hi Len Whistler,

    thank you very much, that makes life a lot easier than how i was doing it

    can you please explain these points so that i can understand them better

    $month = date('F');
    $day = date('j');
    $year = date('Y');

    <form action="<?php echo $_SERVER ['PHP_SELF']; ?>" method="post">

    i'd really appreciate it

    cheers
    Luke

    Study the date() php function for info on the F,J,Y, etc.

    "<form action="<?php echo $_SERVER ['PHP_SELF']; ?>" method="post">" will direct the script to the current page, you can also specify a certain page to process the script. I would Google php form action for more info.


    --------


    ----------
    Last edited by Len Whistler; 08-13-2008 at 12:28 AM.
    Leonard Whistler

  • #11
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    brilliant thanks mate, didnt relise ust how powerfull php is


  •  

    Posting Permissions

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