Menu

How do you pass $_GET form variables????

Jae Choi
2010-04-12
2012-09-07
  • Jae Choi

    Jae Choi - 2010-04-12

    Hi, I am having a real issue with this for weeks now. Basically my php webpage
    has img linked to my phplot PieChart.php which displays in image format. I
    have set some form variables to be linked to Pie_Chart.php so that it picks up
    the variables from my main php file. This has not happened as passed variables
    are never recognised and basically comes up as NULL.

    Below are my codes...

    Main PHP:

    <form name="form2" action="Pie_Chart.php" method="GET" id="user-content-form2"> <input type="hidden" name="Annual_Expenses" value="&lt;?php $Annual_Expenses ?&gt;"> <input type="hidden" name="Mortgage_Interest" value="&lt;?php $Mortgage_Interest ?&gt;"> <input type="submit" name="Calculate" id="Calculate"> </form>

    Pie_Chart.php:

    SetPlotType("pie"); $legend = array(); //Define some data $data = array( array('a',$_GET,$_GET,5526.09,12000,2805.48) ); $graph->SetDataValues($data); $graph->SetLegendPixels(1,5,false); $graph->SetLegend($legend); //Draw it $graph->DrawGraph(); ?>

    Anyone have any ideas? If anyone could give me a workable solution, I would
    highly appreciate your work!!!

    Thank you very much!!!

     
  • Alex Doll

    Alex Doll - 2010-04-12

    Try putting echo in your , and end the line with a
    semicolon.

    Also, always validate the values you get from a $_GET to make sure hackers
    don't take over your computer. If the values are numeric, you can do something
    like this:

    (0 + $_GET)

    Also, the array('a',$_GET,$_GET contains a $_GET that doesn't have a
    specified. Not sure if that is what you are attempting to do.

     
  • Jae Choi

    Jae Choi - 2010-04-12

    Hi adoll, thanks for the reply but it still does not work with echo in it. Is
    there any other solutions?

     
  • lbayuk

    lbayuk - 2010-04-12

    Is that the whole form, 2 hidden fields and a submit button, or are there
    other fields not shown above? If that is all, you might want to use a plain
    link instead instead of a form:

    href="Pie_Chart.php?Annual_Expenses=$Annual_Expenses&Mortgage_Interest=$Mortgage_Interest"
    

    After you made the changes from adoll, and you click the Calculate button,
    does the URL in the browser show the correct syntax and parameters? Also as
    adoll wrote you need to fix the bare $_GET inside the data array.

     
  • Alex Doll

    Alex Doll - 2010-04-12

    Looking at the code fragments, I can think of a number of possibilities.

    First, try hard-coding the array() in Pie_Chart.php and see if it works:

    $data = array( array('a',1000 ,5526.09,12000,2805.48) );

    If you see a chart with the hard coded value in the array, then the trouble is
    in the $_GET statements.

    If you don't see a chart with the hard coded values, then we need to dig
    deeper into the $data array. It wouldn't hurt to do an audit on the contents
    of the array like this:

    var_dump($data);

    What happens when you try these?

     
  • Jae Choi

    Jae Choi - 2010-04-13

    Hi the chart with hardcoded values does work so I think the trouble is in the
    $_GET statements...

    Is there any other way guys??

     
  • Alex Doll

    Alex Doll - 2010-04-13

    First, have you corrected the error in your $data array?

    array('a',$_GET,
    

    That $_GET isn't right. What is it supposed to be? Perhaps:

    array('a', $_GET['Annual_Expenses'],
    

    Second, what does your $data array look like? What does the var_dump($data)
    look like?

    Third, this is probably a problem with the way your code is formatted on
    Sourceforge, but can you confirm that:

    //Draw it $graph->DrawGraph();
    

    is actually:

    //Draw it 
    $graph->DrawGraph();
    

    (should be a carriage-return separating the // Draw It from the
    $graph->DrawGraph();)

     
  • Jae Choi

    Jae Choi - 2010-04-13

    Hi adoll, thanks for the prompt reply! The code for the Pie_Chart.php is

    SetPlotType("pie"); $legend = array(); //Define some data $data = array( array('a',$_GET,$_GET,5526.09,12000,2805.48) ); $graph->SetDataValues($data); $graph->SetLegendPixels(1,5,false); $graph->SetLegend($legend); //Draw it $graph->DrawGraph(); ?>

    Real Estate Analyzer.php is:

    <form name="form2" action="Pie_Chart.php" method="GET" id="user-content-form2"> <input type="hidden" name="Annual_ExpensesH" value="&lt;?php echo $Annual_Expenses; ?&gt;"> <input type="hidden" name="Mortgage_InterestH" value="&lt;?php echo $Mortgage_Interest; ?&gt;"> <input type="submit" name="Calculate" id="Calculate"> </form>

    Sorry it does have code form name after first $_GET also //Draw it is actually
    on top of $graph->DrawGraph(); which is also correct. But I'm not sure about
    var_dump($data), is this meant to be included in Pie_Graph.php?

     
  • Jae Choi

    Jae Choi - 2010-04-13

    Hi, I have downloaded phplot.php and over-written on the existing file and it
    worked!!! But now the problem is that it goes to the does not display on the
    Real Estate Analyzer.php page but it displays on Pie_Graph.php. Is there any
    way we can display this in the Real Estate Analyzer page?

     
  • Alex Doll

    Alex Doll - 2010-04-13

    Because you are using the plot as the action of a form, the plot has to be a
    separate page. Here is what you have actually set up:

    (Browser) person sees a form. Presses the Submit button.

    (Browser) collects the information on the form and sends it to the webserver.

    (webserver) sees an incoming form data stream. Creates a Pie_Graph.php
    instance and feeds it the form data to graph.

    (webserver) onces the graph is finished creating itself, the server sends it
    to the person who clicked the submit button.

    (Browser) sees a graph.

    If that isn't the action you want, then try lbayuk's suggestion to code an IMG
    tag with the parameters coded in the URL:

    <input type="submit" name="Calculate" id="Calculate">

    "; ?>

    This will put the img tag below your form, and when somebody clicks Submit,
    the page will reload with the graph showing the numbers filled into the form.
    Note you have hidden fields for the inputs, so the user can't input numbers.
    If you have another page that generates the numbers to plot, you can call the
    tag from there and not mess around with this form. The way this is set
    up, somebody still needs to press a submit button to make it work.

     
  • lbayuk

    lbayuk - 2010-04-13

    Side note: Added to my TODO list for the reference manual: Add a short but
    complete example of a web form handler script and plot generator script
    .

     
  • Jae Choi

    Jae Choi - 2010-04-14

    It is now working perfectly. Thank you very much for your support you saved my
    life!!!! One question I had was that is there any customized phplot graphs
    that I could download so I can use them in some of my future projects? I'm not
    sure if there are any nice looking 3D ones around...

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.