How to get a Dynamic Javacript Form variables seperated in PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • propizzy

    How to get a Dynamic Javacript Form variables seperated in PHP

    Appreciate any help!!!

    PROBLEM: I have this form that allows the user to dynamically create
    additional fields (see javascript code bellow). I am trying to retrieve
    the values entered into these fields from my php script. I ultimatly
    need to pick out the variables and place the values into my php script
    page. I have worked with a little code I found on php.net (see php code
    below), but I wan unable to grasp the knowledge on how to seperate the
    variables in the address bar. Please reply.

    QUESTION: How do I create variables in my php script from my dynamic
    javascript form?

    PHP CODE:
    foreach($_GET as $name => $value) {
    print "$name : $value<br>";
    }

    JAVASCRIPT CODE:
    <HEAD>
    <!-- Begin
    function createForm(numb er) {
    data = "";
    inter = "'";
    if (number < 16 && number > -1) {
    for (i=1; i <= number; i++) {
    if (i < 10) spaces=" ";
    else spaces=" ";
    data = data + "URL " + i + " :" + spaces
    + "<input type='text' size=10 name=" + inter
    + "url" + i + inter + "'><br>";
    }
    if (document.layer s) {
    document.layers .cust.document. write(data);
    document.layers .cust.document. close();
    }
    else {
    if (document.all) {
    cust.innerHTML = data;
    }
    }
    }
    else {
    window.alert("P lease select up to 15 entries.");
    }
    }
    // End -->
    </script>
    </HEAD>
    <BODY>
    <center>
    <form name=counter>
    Number of URLs to enter:
    <input type=text name=number size=5>
    <input type=button value="Update"
    onClick="create Form(counter.nu mber.value);">
    </form>
    <br>
    <form name="webform" action="get.php ">
    <input type=text size=20 name=name onChange="msg(t his.form)">
    <!-- Placeholder for dynamic form contents -->
    <span id=cust style="position :relative;"></span>
    <input type=submit value="Send">
    </form>

  • Geoff Berrow

    #2
    Re: How to get a Dynamic Javacript Form variables seperated in PHP

    I noticed that Message-ID:
    <1109115375.842 943.6680@z14g20 00cwz.googlegro ups.com> from propizzy
    contained the following:

    well I'd do it all with PHP but...

    data = data + "URL " + i + " :" + spaces
    + "<input type='text' size=10 name=" + inter
    + "url[]" + i + inter + "'><br>";

    adding square brackets to the name of the text box means the urls will
    be added to an array.

    <form name="webform" action="get.php ">

    you need to change this to

    <form name="webform" method="post" action="get.php ">

    Then you can do this

    $urls=$_POST['url'];

    foreach($urls as $key=>$value){
    $key++;
    echo "URL#$key: $value<br>\n";
    }



    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • propizzy

      #3
      Re: How to get a Dynamic Javacript Form variables seperated in PHP

      Thanks for the reply Geoff,

      I'm going to change my Javascript to PHP first, then I'll try it. I put
      the brackets in the url and paste the code you supplied in my get.php
      page and I got the following errors. I also changed the method to post.
      Please check back later...

      Notice: Undefined index: url in D:\My Webs\My Extreme Web\get.php on
      line 11
      Warning: Invalid argument supplied for foreach() in D:\My Webs\My
      Extreme Web\get.php on line 14

      ~propizzy

      Comment

      • propizzy

        #4
        Re: How to get a Dynamic Javacript Form variables seperated in PHP

        Thanks for the reply Geoff,

        I'm going to change my Javascript to PHP first, then I'll try it. I put
        the brackets in the url and paste the code you supplied in my get.php
        page and I got the following errors. I also changed the method to post.
        Please check back later...

        Notice: Undefined index: url in D:\My Webs\My Extreme Web\get.php on
        line 11
        Warning: Invalid argument supplied for foreach() in D:\My Webs\My
        Extreme Web\get.php on line 14

        ~propizzy

        Comment

        • propizzy

          #5
          Re: How to get a Dynamic Javacript Form variables seperated in PHP

          never mind I messed up because I changed your $urls=$_POST['url']; to
          $urls=$_GET['url'];... Now that I changed it back it works. Thanks for
          the help

          Comment

          • Geoff Berrow

            #6
            Re: How to get a Dynamic Javacript Form variables seperated in PHP

            I noticed that Message-ID:
            <1109120093.675 044.119680@c13g 2000cwb.googleg roups.com> from propizzy
            contained the following:
            [color=blue]
            >never mind I messed up because I changed your $urls=$_POST['url']; to
            >$urls=$_GET['url'];... Now that I changed it back it works. Thanks for
            >the help[/color]

            :-)
            --
            Geoff Berrow (put thecat out to email)
            It's only Usenet, no one dies.
            My opinions, not the committee's, mine.
            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

            Comment

            • propizzy

              #7
              Re: How to get a Dynamic Javacript Form variables seperated in PHP

              Geoff,

              Maybe you can help me with this.

              PROBLEM: Trying to take a couple foreach statements and control the
              output. My dynamic form now has an additional input text box that
              submits to the PHP CODE below. I need to take the values out of the 1st
              input ("system") plus 2nd input ("ipaddress" ) and eliminate the values
              in the middle (please see RESULTS below).

              QUESTION: How can I control the output of these foreach statements to
              ultimately eliminate the two middle results?

              NOTE: Middle values are noted with an star *.

              PHP CODE:
              //create vlan <system> and <ipaddress>
              foreach($system as $key=>$value1){
              $key++;
              foreach($ipaddr ess as $key2=>$value2) {
              $key2++;
              echo "create system $value1 <br>\n";
              echo "configure $value1 ipaddress $value2 <br>\n";
              }
              }

              RESULTS:
              create system system1
              configure system1 ipaddress 10.10.10.2
              *create system system1
              *configure system1 ipaddress 10.10.10.3
              *create system system2
              *configure system2 ipaddress 10.10.10.2
              create system system2
              configure system2 ipaddress 10.10.10.3

              Comment

              • Geoff Berrow

                #8
                Re: How to get a Dynamic Javacript Form variables seperated in PHP

                I noticed that Message-ID:
                <1109182871.010 522.123920@o13g 2000cwo.googleg roups.com> from propizzy
                contained the following:
                [color=blue]
                >PHP CODE:
                >//create vlan <system> and <ipaddress>
                >foreach($syste m as $key=>$value1){
                >$key++;
                > foreach($ipaddr ess as $key2=>$value2) {
                > $key2++;
                > echo "create system $value1 <br>\n";
                > echo "configure $value1 ipaddress $value2 <br>\n";
                >}
                >}[/color]

                Well if I have this right you have an array of systems and a
                corresponding array of ip addresses, each with the same number of
                elements and each with sequential array keys?

                If so...

                for($i=0;$i<cou nt($system);$i+ +){
                echo "create system ".$system[$i]." <br>\n";
                echo "configure ".$system[$i]." ipaddress ."$ipaddress[$i]." <br>\n";
                }

                --
                Geoff Berrow (put thecat out to email)
                It's only Usenet, no one dies.
                My opinions, not the committee's, mine.
                Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                Comment

                • propizzy

                  #9
                  Re: How to get a Dynamic Javacript Form variables seperated in PHP

                  that is tight!!!! (as they say here in California)... Thanks Dude!

                  Comment

                  • Geoff Berrow

                    #10
                    Re: How to get a Dynamic Javacript Form variables seperated in PHP

                    I noticed that Message-ID:
                    <1109184195.270 121.282230@o13g 2000cwo.googleg roups.com> from propizzy
                    contained the following:
                    [color=blue]
                    >that is tight!!!! (as they say here in California)... Thanks Dude![/color]

                    I hope it's a compliment, in the UK 'tight' either means drunk or
                    miserly. :-)

                    --
                    Geoff Berrow (put thecat out to email)
                    It's only Usenet, no one dies.
                    My opinions, not the committee's, mine.
                    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                    Comment

                    • JDS

                      #11
                      Re: How to get a Dynamic Javacript Form variables seperated in PHP

                      On Wed, 23 Feb 2005 19:20:36 +0000, Geoff Berrow wrote:
                      [color=blue]
                      > I hope it's a compliment, in the UK 'tight' either means drunk or
                      > miserly. :-)[/color]

                      A dictionary of real slang words. The Online Slang Dictionary has a slang ('urban') thesaurus, maps, usage voting, offensiveness ratings, and more.


                      --
                      JDS | jeffrey@example .invalid
                      | http://www.newtnotes.com
                      DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

                      Comment

                      • propizzy

                        #12
                        Re: How to get a Dynamic Javacript Form variables seperated in PHP

                        nice hook up jeff...

                        Comment

                        Working...