#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    5
    Rep Power
    0

    PHP form to mulitple pages


    I have a text box with 5 radio buttons. What i want to do is send the query to the appropriate url . It goes to the page but I don't know how to set the value equal to the actual query itself,i.e whatever the user inserts. I'm fairly sure that this is either very simple to do or else impossible. I know a form can have only one action but I also know there is loads of ways around it with different buttons. Any ideas? TIA


    PHP Code:
    <form id ='searchbox' method "GET" action="" 
    <
    input type 'text' id="query" required placeholder 'enter query' >
    <
    input type 'submit' id ='submit' value 'Query' ><br />
    <
    input name="query" type="radio" value =""id='blekko'onclick="searchbox.action='blekko3.php';" />Blekko<br \>
    <
    input name="query" type="radio" value="" id='query'onclick="searchbox.action='bing_basic.php';"/>Bing<br \>
    <
    input name="query" type="radio" value="" id='faroo'onclick="searchbox.action='faroo_basic2.php';"/>Faroo<br \>
    <
    input name="query" type="radio" value=""id='aggregated' onclick="searchbox.action='aggregated.php';"/>Aggregated<br \>
    <
    input name="query" type="radio" value=""id='non-aggregated'onclick="searchbox.action='non-aggregated.php';" />Non-aggregated<br \>
    </
    form
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    I'm not sure whether or not this is a JavaScript question, but I moved the thread because it sounds like it might be. Your question isn't completely clear to me though.

    It goes to the page but I don't know how to set the value equal to the actual query itself,i.e whatever the user inserts.
    It goes to which page? The page containing the form, the page you're specifying with the onclick action, or some other page?

    Set which value equal to the actual query? I assume by "actual query" you mean the value the user entered.

    Your query text input doesn't have a name attribute, which might be the issue.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    5
    Rep Power
    0
    Originally Posted by E-Oreo
    I'm not sure whether or not this is a JavaScript question, but I moved the thread because it sounds like it might be. Your question isn't completely clear to me though.


    It goes to which page? The page containing the form, the page you're specifying with the onclick action, or some other page?

    Set which value equal to the actual query? I assume by "actual query" you mean the value the user entered.

    Your query text input doesn't have a name attribute, which might be the issue.
    Sorry that might have been explained a little badly.

    It goes to the page of whatever radio button is ticked.

    <input name="query" type="radio" value =""id='blekko'onclick="searchbox.action='blekko3.php';" />Blekko<br \>

    If the blekko radio button is ticked it goes to the right page, in this case blekko3.php. However i cant get it to $_GET/$_POST the user input/search terms to the blekko page. I can put value="turnips" into the above code. It will go to Blekko3.php and output a hundred search results for the term "turnips". But I can't seem to get the equivalent of value="the input of the user/whatever was put into the text box" . Do i have to use javascript to do this??

    Pretty confident it's not a server side issue the PHP works with a single form for a lone action = "blekko3.php".
  6. #4
  7. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,156
    Rep Power
    183
    Try this; it should do what your wanting to do:
    Code:
    <script>
    function changeAction(act,radio)
    {
    document.getElementById(radio).parentNode.action = act;
     document.getElementById(radio).parentNode.onsubmit = function(){
     var inputs = document.getElementsByTagName("input");
      for(i=0;i<inputs.length;i++){
         if(inputs[i].getAttribute("type") == "radio"){
          inputs[i].removeAttribute("name");
         }
        }
      }
    }
    </script>
    
    
    <form id="searchbox" method="get"> 
    <input name="query" type="text" id="query" name="query" placeholder="enter query" required/> 
    <input type="submit" id="submit" value="Query"/><br />
    <input name="url" type="radio" value="" id="blekko" onclick="changeAction('blekko3.php',this.id)"/>Blekko<br/> 
    <input name="url" type="radio" value="" id="query" onclick="changeAction('bing_basic.php',this.id)"/>Bing<br/> 
    <input name="url" type="radio" value="" id="faroo" onclick="changeAction('faroo_basic2.php',this.id)"/>Faroo<br/> 
    <input name="url" type="radio" value="" id="aggregated" onclick="changeAction('aggregated.php',this.id)"/>Aggregated<br/> 
    <input name="url" type="radio" value="" id="non-aggregated" onclick="changeAction('non-aggregated.php',this.id)"/>Non-aggregated<br/> 
    </form>
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    5
    Rep Power
    0
    Originally Posted by web_loone08
    Try this; it should do what your wanting to do:
    Code:
    <script>
    function changeAction(act,radio)
    {
    document.getElementById(radio).parentNode.action = act;
     document.getElementById(radio).parentNode.onsubmit = function(){
     var inputs = document.getElementsByTagName("input");
      for(i=0;i<inputs.length;i++){
         if(inputs[i].getAttribute("type") == "radio"){
          inputs[i].removeAttribute("name");
         }
        }
      }
    }
    </script>
    
    
    <form id="searchbox" method="get"> 
    <input name="query" type="text" id="query" name="query" placeholder="enter query" required/> 
    <input type="submit" id="submit" value="Query"/><br />
    <input name="url" type="radio" value="" id="blekko" onclick="changeAction('blekko3.php',this.id)"/>Blekko<br/> 
    <input name="url" type="radio" value="" id="query" onclick="changeAction('bing_basic.php',this.id)"/>Bing<br/> 
    <input name="url" type="radio" value="" id="faroo" onclick="changeAction('faroo_basic2.php',this.id)"/>Faroo<br/> 
    <input name="url" type="radio" value="" id="aggregated" onclick="changeAction('aggregated.php',this.id)"/>Aggregated<br/> 
    <input name="url" type="radio" value="" id="non-aggregated" onclick="changeAction('non-aggregated.php',this.id)"/>Non-aggregated<br/> 
    </form>
    Worked perfectly thanks.

IMN logo majestic logo threadwatch logo seochat tools logo