-1

I have a DB-based AMCharts form/page that graphs figures that are entered in a separate edit form accessed from that main page. This latter php edit form is set up to always bring up the present set of entries in every field. This edit form serves two purposes: one is to be able to correct earlier mistakes, and the other is to enter a whole set of new ones. The new figures are entered in this edit page and then submitted. A series of four sets of previous generations are saved in identical tables, which are also graphed on the same main page. A JS div slider script allows the user to compare among 5 generations of separate graphs in the same space. A trigger built into MySql allows each new set to be passed on to older sets, 5 gen deep. Without getting into too many details, the trigger is written so that it is activated if two specific fields in the form are different from the previous. Thus allowing mistakes to be corrected without activating the trigger. With me so far? My question does not concern the structure of the thing, it works fine, but just one problem that does not seem to be available on SO or any other google search result. Specifically, in the case that the edit form is used to enter a brand new set of numbers, how could you use a reset button that activates a script that clears all the old figures from the inputs? I've found numerous answers on SO that use either pure JS or JQuery, but they are not used on PHP forms, rather HMTL forms. Some posters point out that this is anyhow not possible, as edit forms contain DB values cannot be replaced unless the SUBMIT button is used. This simple device is to make entry of new figures easier when they are empty, but I haven't found any scripts so far that succeed in clearing them. The simple reset code that works in HTML forms but in my php one:

   <script>function resetform() {
   document.getElementById("myform").reset();}</script>

   <form action="" method="post" id="myform">

   <input value="RESET" onclick="resetform()">

enter image description here

user3241848
  • 71
  • 10
  • 1
    There is no such thing as a PHP form. PHP creates HTML. All forms are HTML. And you might want to look into the concept of paragraphs. – j08691 Mar 29 '17 at 20:15

3 Answers3

0

As no one answered this question, I assume, as I conjectured in the question, that this is not possible. My solution is to circumvent this problem by having two forms. Since you can recall DB values with this line-

  value="<?php echo $var;?>"

I created another form almost exactly as the edit form minus the echo info:

  value=""

so that I end up with two forms-the "edit" one with echo which is used to correct mistakes, and a "new" form without the echo instruction. So, one form recalls the DB values, the other doesn't. Keep in mind both submit to the table with the same ID, since I want the latest values, and older ones of more than 5 gens become irrelevant. Hope this is useful to anyone with similar problems. Post questions and maybe I'll be able to answer them.

EDIT: Also thanks to @miken32's suggestion, the following article does the trick, but my solution, though not 100% addressing the issues in initial post, is the best for my purposes: How can I use a reset button for php form?

Community
  • 1
  • 1
user3241848
  • 71
  • 10
  • Not sure about the mentality here. I find a solution to my problem, post it, and immediately get 2 downvotes. Funny... – user3241848 Mar 30 '17 at 21:16
0

Like j08691 said, you might wish to brush up on your information on what PHP is and what it does.

It creates a HTML page and once it's created, it doesn't "touch" it anymore. It's done, finito. The only way for PHP to "modify" the page is to create (reload) it again.

If you wish to interact with a ready, loaded HTML page - such as a form with values inputed in the fields, you will have to use another technology like Javascript.

Now, if your problem is the "echo $var" -part - you could avoid populating the form fields with values by either emptying the $var (in which case the value would be '' like in your empty form) or having some kind of "toggle" which sniffs if you wish to print old values or have empty ones like:

$echo ($want_empty_form ? '' : $var);

... in which case you somehow, with a GET or POST parameter perhaps, tell the form at load time you want a empty form, leading to...

$want_empty_form = true;

... and thus the form fields to being empty.

DocWeird
  • 288
  • 1
  • 7
0

You want to reset all form values to their initial values? What's wrong with this:

<button type="reset">Reset</button>

Or, if you want to party like it's 1999:

<input type="reset" value="Reset">
miken32
  • 42,008
  • 16
  • 111
  • 154