简体   繁体   中英

Two html forms one submit button for one results page

I have two forms the first one is full of different networks (ex: A, B, C) and the second form is full of different java functions (ex: average.java, length.java, edges.java) that take the text file that represents the network (ex: networkA.txt is the text file for network A) and run the code. I have this part figured out. Where I am running into a problem is that I want to cut down on the amount of pages that I need to be using for efficiency purposes. I have 26 different networks and I dont want to make that mean that I have 50 different network form files and consequently 26 different function form files.

Ideally I want network.php (where user can pick from 26 different networks ---> A, B, C...Z) with radio buttons. And then I want the user to be able to submit the form. The next page that pops up function.php I would want to have the function form on there with radio buttons (ex: average, length, amount. Then with this submit button (for function.php), I want to take the two forms and with the selected choices (Ex: network: A function: edges) run that network txt file through the java code for that function and spit out the result in a results.php page.

So to clarify my question I am wondering if there is a way to keep the choice from networks stored when i go from network.php to function.php to then run through the java code and spit out in results.php. Ive been reading that there is a show./hide function in javascript that does this however I cannot find any good tutorial or web page addressing how to do this in the context that I am trying to do it. Any help, hints, pointers, or example code is welcome and much appreciated.

NetworkA.txt
0 1 0 2 0 3 1 2 2 3 3 4 4 5 5 6 5 7 6 7



Edges.java

import java.util.*;
import java.io.*;

class Edges{

    public static void main(String[] args){

    try{

        FileReader fr = new FileReader(args[0]);
        BufferedReader br = new BufferedReader(fr);

        String line = null;

        int numEdges = 0;

        while (  (line = br.readLine() ) != null){
            System.out.println(line);
            numEdges++;
        }

        System.out.println("Total # Edges: "+numEdges);


    }
    catch(Exception e){e.printStackTrace();}

    }

}



RunCode.php ---> This is what i use to compile java code in my php page

$PATH="C:\Program Files\Java\jdk1.8.0_101\bin";
      echo exec("javac Edges.java 2>&1");//shows # of errors
      echo "<br />";
      echo exec("java Edges networkA.txt 2>&1");//this line executes it
      echo "<br />";
      echo shell_exec("javac Edges.java 2>&1 ");//compiles it



networkA.php ---> networkA complies the code and gives me a result of in this case = 10 edges

<header>

    <div class="nav">

        <ul>
            <li><a href="logout.php">Logout</a></li>
        </ul>

    </div>

    <div class="form">
      <?php


      $PATH="C:\Program Files\Java\jdk1.8.0_101\bin";
      echo exec("javac ListEdges.java 2>&1");//shows # of errors
      echo "<br />";
      echo exec("java ListEdges networkA.txt 2>&1");//this line executes it
      echo "<br />";
      echo shell_exec("javac ListEdges.java 2>&1 ");//compiles it

      ?>
      <a class="tryagain" href='index.php' target="_blank">Try Again?</a></p>
    </div>

</header>

<footer>

    <div class="footer">
      by Jason Bruno

    </div>
</footer>

Sounds like you want to use a form POST action to submit your choices to network.php:

<form action="network.php" method="post">
<label><input type="radio" name="networkChoice" value="A"> Network A</label>
<label><input type="radio" name="networkChoice" value="B"> Network B</label>
...put more options here...
<input type="submit">
</form>

Then you can get the data you posted back out in PHP using $_POST[]

$network = $_POST["networkChoice"];
...do stuff...

More POST/GET examples: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_and_retrieving_form_data#The_POST_method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM