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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to get value from this form?

    hello
    i have a appending form. please help me and show me how to get the user input value from the given form using PHP:

    <html>

    <head>

    <title>Title</title>

    <meta content="">

    <style></style>



    <script language="javascript">





    var counter = 0; // counter for naming the elements



    function moreFields()

    {

    counter++;

    var newFields = document.getElementById('readroot').cloneNode(true);

    newFields.id = '';

    newFields.style.display = 'block';

    var newField = newFields.childNodes;

    for (var i=0;i<newField.length;i++)

    {

    var theName = newField[i].name

    if(theName)

    {

    newField[i].name = theName + counter;
    newField[i].id = theName + counter;
    }

    }

    var insertHere = document.getElementById('writeroot');

    insertHere.parentNode.insertBefore(newFields,insertHere);

    }



    // -->

    </script>



    </head>

    <body onload="moreFields()">



    <div id="readroot" style="display: none">
    <div align="center">Job Experience <br>
    Company:
    <input type="text" name="company" size="70">
    <br>
    Post :
    <input type="text" name="post" size="70">
    <br>
    Job Duties:
    <textarea name="duties" cols="60" rows="10"></textarea>
    <input type="button" value="Remove" style="font-size: 10px" onClick="this.parentNode.parentNode.removeChild(this.parentNode);">
    </div>
    </div>



    <form method=post>



    <span id="writeroot"></span>

    <p class="hr">&nbsp;</p>



    <input type="button" value="Add New Line" onClick="moreFields()"><br>

    <input type="submit" value="Send form">



    </form>





    </body>

    </html>

  • #2
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    What you'll do is set the name of company and post to this

    Code:
    <input type="text" name="company[]" size="70">
    <input type="text" name="post[]" size="70">
    And that'll make an array in a number order starting from 0.
    so to use that you would do something like this

    PHP Code:
    <?php
    extract
    ($_POST);

    print_r($company);
    print_r($post);

    // OR
    foreach ($company as $input)
    {
      
    // DO THIS
    }
    ?>

  • #3
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    $_POST

    It's also good practice to specify what script the form is supposed to use.
    PHP Code:
    <form action="scriptName.php" method="post"
    Last edited by fl00d; 01-07-2008 at 11:41 PM. Reason: Iszak posted as I posted =0

  • #4
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanx for ur help. pls help me abit more..

    i added two more fields which wont expand. i m unable to get value from that field. im giving u the code of the form below:

    <html>

    <head>

    <title>title</title>

    <meta content="">

    <style></style>



    <script language="javascript">





    var counter = 0; // counter for naming the elements



    function moreFields()

    {

    counter++;

    var newFields = document.getElementById('readroot').cloneNode(true);

    newFields.id = '';

    newFields.style.display = 'block';

    var newField = newFields.childNodes;

    for (var i=0;i<newField.length;i++)

    {

    var theName = newField[i].name

    if(theName)

    {

    newField[i].name = theName + counter;

    newField[i].id = theName + counter;

    }

    }

    var insertHere = document.getElementById('writeroot');

    insertHere.parentNode.insertBefore(newFields,insertHere);

    }



    // -->

    </script>



    </head>

    <body onload="moreFields()">



    <div id="readroot" style="display: none">
    <div align="center">Job Experience <br>
    Company:
    <input type="text" name="company[]" size="70">
    <br>
    Post :
    <input type="text" name="post[]" size="70">
    <br>
    Job Duties:
    <textarea name="duties[]" cols="60" rows="10"></textarea>
    <input type="button" value="Add New Line" onClick="moreFields()">
    <input type="button" value="Remove" style="font-size: 10px" onClick="this.parentNode.parentNode.removeChild(this.parentNode);">
    </div>
    </div>



    <form method="post" action="test1.php">
    Name:<input type="text" name="name" size="70"><br>
    Address:<input type="text" name="name" size="70">



    <span id="writeroot"></span>

    <p class="hr">&nbsp;</p>




    <input type="submit" value="Send form">



    </form>





    </body>

    </html>

    Also im facing problem to insert all the data into mysql. Mysql TABLE field are
    ID, NAME, ADDRESS, COMPANY, POST, DUTIES, DATE. how can i insert data in a single row? please help me.


  •  

    Posting Permissions

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