Help with populating an html form having more than one attribute

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fjm
    Contributor
    • May 2007
    • 348

    Help with populating an html form having more than one attribute

    Hello all,

    I know it wouldn't be long before I was back. I have a dilemma and really have no idea where to look for an answer. I have two issues going on and I appoligize in advance if I'm wrong for putting them both into one single post.

    My first question has to do with more of a design issue than anything else.

    I have an html form that will be populated with data from a mysql database using php. My *insert* form has the basic name, address, phone number information. I am starting to wonder how my form will insert more than one phone number or even customer location.

    Say a customer has 15 (Highly unlikley but for example sake) telephone numbers. My insert form needs to have a list of fields that will allow the person to enter those numbers. I'm looking for a clean design. Can someone give me any pointers as to how this should be done?

    My tables are like this:

    Code:
    [i][b]customer_table[/b][/i]
    [u]customer_ID[/u]
    customer_Name
     
    [i][b]customer_Location_table[/b][/i]
    [u]customer_Location_ID[/u]
    [u]customer_ID[/u]
    address1
    address2
    city
    state
    zip
     
    [b]customer_Phone_table[/b]
    [u]customer_phone_ID[/u]
    [u]customer_Location_ID[/u]
    phone_Type
    area_Code
    phone_Number
    So if my insert form looks like this:
    Code:
    Customer Name
    Address1
    Address2
    City
    State
    Zip
    Phone Type
    Area Code
    Phone Number
     
    [SUBMIT BUTTON]
    How would I go about adding a second or third phone number to the db?
    The only way I can see to add another phone number would be to place an insert new button next to all of the fields that can have *many* of one thing such as customer location, phone number what have you but this design tenique does not strike me as clean.

    I would ultimately like to have "one" submit button that will enter everything in one shot.

    My second question has to do with SERIALIZABLE transactions. Is this hard to set up? Do I need to set up the entire db to use them? Again, just advice. Thanks Guys!

    Frank
  • shoonya
    New Member
    • May 2007
    • 160

    #2
    replying to your first query...
    [code=html]
    <script language=javasc ript>
    var counter=1 // present no of rows
    function add_row(){
    ---
    use pre defined addRow function here to add another row to the table.
    var inp=document.cr eateElemet('INP UT')
    inp.id='input_t ext_field'+coun ter;
    //append the inp to newly added
    counter++
    --
    }
    </script>
    <table><tr><td> <input type=text name=text_field _id0></td</tr></table> Telephone No <a href=javascript :add_row()>add another</a>
    [/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]

    assign the id's serially and put the whole thing in a form
    On your php page
    [code=php]
    $i = 0;
    while ( isset ( $_POST["text_field_id" .$i] ) ==1){
    --
    put your query here
    --
    $i++;
    }[/code]

    hope it's clean enough
    you can also add remove option by deleting the rows in the table.
    similarly implement this thing to all the fields that may have more than one values

    for storing in db you can make a separate a table like telephone_no, contact_details else you can use array data type to store the information in a single table

    shoonya

    Comment

    • fjm
      Contributor
      • May 2007
      • 348

      #3
      Shoonya,


      Thank you for you response and advice. I know that Yahoo mail has something similar when uploading a file (attachment). I'm not sure how to implement that into the code though. I am thinking about it and I'm not sure that it could work because I have a second table that is used as a FK in the phone table and indicates its type. Like this:

      phone_Type_Tabl e
      phone_Type

      phone_table
      phone_ID
      phone_Type
      area_Code
      phone_Number
      Some complete sample data would look like this:
      Code:
      phone_ID	 phone_Type	 area_Code	 phone_Number
      1				 Home				213				 555-1212
      2				 Work				 312						555-5455
      In order for me to use the javascript code you provided, wouldn't I have to also have some sort of a drop down box for the phone type as well? I just don't know how to impliment this.

      Also, I have a question about my php design. Please bear in mind that this is my first real stab at trying to get something working with php. I have about 20 or so php forms written in pure html to look exactly how I want. I will go and insert the code into the html when I am ready.

      My question is that I have seen many php scripts and I have never seen so many php scripts for each page. In other words, I usually see an index.php and class scripts. In my design, I will have 20 seperate php scripts and no classes. Is this a sucky design? Is there I way I can modulerize this some how without it becoming too difficult? I don't know OOP but I suspect that what I am referring to is OOP. Yes?

      Thanks for the help.

      Comment

      • shoonya
        New Member
        • May 2007
        • 160

        #4
        hey even I dont use/know OOP :D

        now for your drop down which has to be generated from the phone_type relation
        [PHP]<?php
        $query="select phone_type from phone_no_type";
        $result=pg_exec ($query);
        if(!$result){
        echo "<select size=1>";
        for($i=0; $i<pg_num_rows( $result); $i++){
        $data=pg_fetch_ array($result);
        echo "<option>$d ata[phone_type]</option>";
        }
        echo "</select>";
        }
        ?>[/PHP]

        I guess this is what you want.
        In case I am wrong do write back

        shoonya

        Comment

        • fjm
          Contributor
          • May 2007
          • 348

          #5
          Originally posted by shoonya
          hey even I dont use/know OOP :D

          now for your drop down which has to be generated from the phone_type relation
          [PHP]<?php
          $query="select phone_type from phone_no_type";
          $result=pg_exec ($query);
          if(!$result){
          echo "<select size=1>";
          for($i=0; $i<pg_num_rows( $result); $i++){
          $data=pg_fetch_ array($result);
          echo "<option>$d ata[phone_type]</option>";
          }
          echo "</select>";
          }
          ?>[/PHP]

          I guess this is what you want.
          In case I am wrong do write back

          shoonya
          The fact that you don't know OOP either makes me feel a whole lot better. :)

          The code you provided will pull the data into a drop down box but can I incorporate that code into that nice little javascript code to dynamically appear when a new phone number is required?

          I guess what I mean is that the js code will allow a new phone number but we also need the phone type to go with the new number for the parent table or the insert will fail.

          Is there a way to bring up a new phone textbox field and phone type drop down box all in one click? Or maybe a better way of designing this all together?

          Thanks Shoonya.

          Comment

          • shoonya
            New Member
            • May 2007
            • 160

            #6
            yeah ofcourse you can do it
            either use ajax to dynamically create the drop down each time user wants to enter a new telephone number
            one alternate unorthodox method is make a javascript array like

            content_array = new Array();
            loop{
            --
            content_array[i]=<?php echo &tel_type; ?>
            ---}
            now use this array to make a string like this

            var arg='<select><o ption>'+content _array[0]+'</option><option> ......'
            and now when any user will click to enter new phone no then along with showing him a text box show this string beside it or in a new cell

            hope you will get it

            shoonya

            Comment

            • fjm
              Contributor
              • May 2007
              • 348

              #7
              Originally posted by shoonya
              yeah ofcourse you can do it
              either use ajax to dynamically create the drop down each time user wants to enter a new telephone number
              one alternate unorthodox method is make a javascript array like

              content_array = new Array();
              loop{
              --
              content_array[i]=<?php echo &tel_type; ?>
              ---}
              now use this array to make a string like this

              var arg='<select><o ption>'+content _array[0]+'</option><option> ......'
              and now when any user will click to enter new phone no then along with showing him a text box show this string beside it or in a new cell

              hope you will get it

              shoonya
              I'm sorry Shoonya.. its like showing a Japanese person Chinese writing. I don't understand javascript at all.

              Is there or are there any ajax snippits out there that you could turn me on to that I can just kind of plug in? Maybe I am asking for something that is not possible. I don't know but it doesn't hurt to ask. :)

              Thanks again. Frank

              Comment

              • shoonya
                New Member
                • May 2007
                • 160

                #8
                no problem dude :)

                I will suggest you to go through any javascript basic site (w3school is good and precise).
                It will enhance your skill set and surely will be of great help
                and yeah as fai as my knowledge is concerned ajax doesn't has a plug-in
                it's an extension of javascript (very easy to use) used for fetching data from db without refreshing the whole page

                shoonya

                Comment

                • shoonya
                  New Member
                  • May 2007
                  • 160

                  #9
                  go through some basic javascript functions/methods like

                  Code:
                  document.getElementById()
                  ...innerHTML
                  ...style.display
                  shoonya

                  Comment

                  Working...