Search code examples
phppchart

How to preserve form values after submit and executed form action


I made some PHP script with a form that contains dozen of text fields, some of them like text fields arrays, others as single text field. Part of these values I try to pass to another PHP script (pChart lib script) where I read them into variables and transform into arrays as chart input. pChart script then create chart as a PNG image on disk that I planned to show bellow form that supplied chart data. I have few problems:

  • how to provide unique name for chart image to differentiate images of many users that run script at same time;
  • how to fire pChart script in order to get chart and in same time show image bellow form with data?

My tries ended with empty form and chart image above it. Do I need session or some other "tricks"? Javascript is also welcome... Thank you.


Solution

  • Since you don't have any code I am not 100% sure how you are going about most things but I can still give suggestions.

    For your first problem, you could use $_SERVER['REMOTE_ADDR'] to get the user's unique IP Address and the time they are using your script using $_SERVER['REQUEST_TIME']

    Like this

    $uniqueName = $_SERVER['REMOTE_ADDR'] . "_" . $_SERVER['REQUEST_TIME'];
    

    As for the other problem you can just save the variables in the session so you can recall them anytime after you call the script. You could also use ajax to asynchronously call the script that created the image and then using jquery to populate the chart underneath it using the info from the form while at the same time removing form from the page.