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()">
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.
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">
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?
Related
I am modifying an existing plugin, and it has a form. The perfect place for me to add my code is at the end of the form but before the submit button. I want to add a form that will allow users to enter their credit card info, but nesting my form within the plugin's form is causing problems.
I was wondering if it would be possible for my form nesting to somehow work with AJAX. So basically, I just need 4 input areas (CC#, Exp date, CCV, amount) to be submitted that to Braintree's servers. I need to maintain PCI compliance with anything I do, so is this possible? Is it recommended? If not, what is?
EDIT - I found a question on here that made me wonder if it would be possible to separate the 2 forms but use CSS to make it look like my screenshot. Below is a quote from one of the question's answers.
Why not place the input inside the form, but use CSS to position it elsewhere on the page?
Update - I'm still confused...
It is against the standards to do nested forms like you are thinking. (See this question for more about that: Can you nest html forms?)
That doesn't mean that you can't have the form send data to multiple locations on submit. Register a submit handler for the form with two ajax methods. The first takes the four pieces of data and sends them to your server. The second grabs the rest of the data and sends it to the location specified by the form.
I have a multi-step form for capturing leads and generating potential client estimates. I modified a framework that I found elsewhere on the web. The form looks and works beautifully now, but I need to pass the values from the form through PHP to email. I'm not a stranger to this process, but I believe that something in the Javascript required to make the form beautiful and interactive is voiding the values that should be passing from the form to the email.
What I have done to test (trust me, I hate to bother people, but this is driving me nuts):
I eliminated the fieldsets and any other extra form-formatting, all links to CSS and Javascript. I tested the form and it worked as expected. I took the name in the name="name" field and emailed it to me no problems.
I systematically reconstructed the form until it was complete with fieldsets and CSS. I tested at every step and the form continued to pass the name into the email.
Finally, I added the javascript used for transitions and calculations to the bottom of the page and it no longer performs as expected. It triggers the PHP, but it doesn't redirect as I want it to. and it sends the labels in the email, but doesn't pass the values from the form. If I move the Javascript links to the head, the transitions don't occur making it impossible to navigate to the submit button. Any clues?
Here is the link to the form: http://bigislandwebsitedesign.com/test_form.html
You can follow the links to the various scripts from the source.
I have a page in which almost all of the controls are created dynamically.
When I send the page I have no problem retrieving the data from those controls.
The problem comes when I have to retrieve the data of the "returns"(see buttons inside the blue frames), because since they are not inside any control I have to use an array to keep track of them.
This is the pop-up that is used to enter the returns for each expression (IF,ELSE IF,ELSE)
My question is, what would you do if you had to keep track of those returns??
Would you create an js array of returns for every expression(IF,ELSE IF,ELSE) knowing that you would have to create arrays of arrays since each structure can have several instructions,which in turn can have several expression, which in turn can have several returns?? What would you do to keep the solution as simple as possible, considering that the only thing I don't have inside controls is the returns.
At present I'm using the js array approach but , I have to do a lot of things so that when I remove a structure of all the returns associated with the expressions inside that structure, get removed too.
EDIT:
==============
The code I use to create all the controls in my page is too large to be posted it here, but here's an image showing the structure of the js array I use to store all the returns for each expresion(IF,ELSE IF,ELSE) and that I later submit as a json object.
Considering that structure, do you think it would be possible to simplified that structure so that while I am still editing the page I only have to have the returns in a array??
To make a long story short, I want to create the whole structure shown in the image just before I summit the form, NOT while I'm still editing the page.
Just a couple of extra things to consider:
structures : Structure #1,Structure #2
instructions: All the frames with a dropdown list showing "Multiple IF"
expressions : All the IF's,ELSE IF's and ELSE's
==============
P.S. I'm not asking for any working code, I only want to hear your suggestions of what you would you do if you had to deal with a situation like the one described above.
Use the form element's onsubmit event.
<form action="" onsubmit="this['returns'].value = createReturnsArray();">
<input type="hidden" name="returns" />
</form>
When the form is submitted, the function createReturnsArray is called and its return value send along with the form as returns. Of course, you would change all these things to suit your needs.
I wonder if anyone can advise? I have a JSP which contains two forms, both of which are mapped to the same servlet on the server.
Everything seems fine although when I submit one form, a necessary piece of data entered on the other form is not being submitted at the same time.
The first form is used to add or delete the address of an RSS feed. As there may be several addresses on the page, a table is used to store them. Each cell of the table contains a form like this for deletion:
<form action = "<c:url value = '/deleteRSSFeed?rssFeedURL=${rssFeedURL}' />" method = "post">
<input type = "image" src = "${imageFileURL}myApp_rightArrow.png" />
<input name = "writeWordcloud" type = "hidden" value = "true" />
</form>
And there is another form for adding a feed.
The situation is that upon submission of either of these forms, a wordcloud must be redrawn on the page. But the wordcloud's settings are contained in the other form.
As it not possible for me to merge the forms, can anyone tell me if I can share data betwen forms in HTML? Or better yet, is it possible to submit one form, and have this action submit the second form?
At this point, it is not practical for me to have the forms served by different servlets.
Thanks
Mr Morgan
By using Javascript (or better, jQuery), you can have hidden fields in one form get the other form's fields values before submitting.
Update
This fiddle shows the code you need: http://jsfiddle.net/MqsK8/1/
You should probably use a single form, and have the server-side script perform both actions.
Depending on your scenario, you may want to have two submit buttons for different tasks; the server can check which button was clicked.
It would if you can provide detail of what you are trying to do. You can use Javascript to add elements to DOM but again all of this will depend on your use-case.
A little web design dilemma: I have a form with a lot of options, mainly radio buttons but not only.
I want the form to open up gradually, meaning at the beginning only two radio buttons are visible, and after the user picks one, more options appear under the chosen radio button. If the user then switches the pick, the page updates and shows the options under the new pick.
This happens on several levels, say 4 or 5 levels, and at the end there is a submit button that submits only certain inputs according to the branches the user chose. Also some of the branches have identical components even though the initial choice was different.
These are the options I could think of:
Build the complete form in the html body and use jquery to hide and show them according to the choices of the user. This means I have to write sections that repeat themselves twice.
Write nothing in the body, and append new elements when the user makes certain choices. This means the JavaScript is more complicated, because I have to make sure nothing appends twice.
Write an HTML skeleton of the form, and use append to fill it. Then use jquery to show and hide elements. This has none of the disadvantages but seems a bit unaesthetic.
Which one should I pick? Any better ideas?
It really comes down to your knowledge of javascript. The cleanest way would be to append to form using javascript. This way you can avoid having duplicates in your form.
If you are not that familiar with javascript and don't know how to append the form, then I would use javascript to show/hide the different parts of the form.
I think using javascript to append would be the correct way, but I don't see anything really wrong with using javascript to just hide parts of the form.
Probably going to use http://wiki.jqueryui.com/w/page/12137997/Menu
or JStree (http://www.jstree.com/) which I found out about from here http://wiki.jqueryui.com/w/page/12138128/Tree