Menu

Interactive HTML form and PHPlot

seeker052
2010-01-17
2012-09-07
  • seeker052

    seeker052 - 2010-01-17

    Hi, I am new to php and phplot. I am using phplot 5.0 as my provider is only
    on php4.something.

    I am trying to get a web page that contains a form and a plot from phplot all
    on the same page.

    I want to be able to

    1) enter data into the form

    2) press the submit button and

    a) have the data values remain in the form

    b) have the plot update with the new/modified data

    3) be ready to get new/modified data

    I have tried using two different php files, one php file, even writting the
    image to a file and reading it with tag (the file seems to never get
    updated). I would really rather not read/wrtie a file, but have tried many
    variations with no luck.

    Does anyone have an idea how this might be done, or may have already done this
    type of web page?

    Thanks in advance for any help you can give.

    Steve T.

     
  • lbayuk

    lbayuk - 2010-01-17

    I am using phplot 5.0 as my provider is only on php4.something.

    That's sad. It has been 2 years since PHP 4 support was discontinued.

    I am trying to get a web page that contains a form and a plot from phplot
    all on the same page.

    Here is the basic idea. There are certainly other ways.

    For your web page with form and image, you need 2 PHP scripts. Call them
    form.php and image.php just for discussion. form.php is the main script that
    the browser references by URL. The script needs to check for form parameters.
    If there are no form parameters, depending on what you are doing, you may want
    to display a default plot or no plot at all.

    If there are form parameters, they are used to populate default values for the
    form, and to display the plot.

    To display the plot, the form.php script sends an IMG tag to the browser in
    the page it produces. The URL in the IMG tag points to your second script,
    image.php. You also need to send parameters (from the form submission or
    defaults) to the image.php script, to tell it how to draw the plot. You can do
    this with URL parameters, with appropriate escaping. (You can use session
    variables instead, which is most useful if you are already doing sessions.) So
    image.php might contain something like this:

    echo "<img src=\"image.php?param1=$value1&amp;param2=value2\">";
    

    Which passes 2 parameters, values assumed to already be escaped with
    urlencode(). When the browser processes the returned page from form.php, it
    will make a second request to image.php for the image.

    The image.php script checks and validates its GET parameters (or session
    variables, if you are doing it that way), and uses PHPlot to produce the
    image. Note that if image.php gets an error, it must not just output an error
    message in HTML, because the browser is expecting an image.

     
  • seeker052

    seeker052 - 2010-01-18

    Ibayuk, thank you for your quick reply. I was thinking about that approach as
    well. I will et you know how it comes out.

    It is sad about the php version, it was not on my mind when I got my current
    provider. I will start shopping for a new provider.

    Thanks, again. Steve T.

     
  • seeker052

    seeker052 - 2010-01-19

    Well, I decided to take the opportunity to learn about sessions and session
    variables. It solved my problem and all is working well.

    Thank you, Steve T.

     

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.