I have a webpage that contains a form, and i need to refresh the page right before the form is submitted. Is there a way to have the Submit button refresh the current page and then submit the form to the proper php document?
I am using a general form with the submit button looking like
<input name="Submit" value="Submit" type="submit" />
Fix the page - do not pursue making this problem larger than it already is. I think it's some tunnel vision, you've made some mistakes on how you have setup your form or page, and now you are trying to continue down the wrong path instead of correcting your original problem.
Refreshing the page to submit some javascript data and then submit the form etc... is incorrect and needs to be fixed.
Best of luck and happy coding!
You can give the form a target to submit it in a new window and bind an event handler to it that refreshes the page on submit.
Please clarify what exactly you're trying to achieve. If you're trying to get some data from the server that's required to submit the form, it's possible to do (though it's not the best way to handle it). You'll need to intercept form submit, stop the events, perform an AJAX request to the server and then submit the form from code.
Related
I've got a form that will be using two submit buttons to post to two different databases.
One to hold permanent information, the other so that they may save the submission and return to it at a later point in time. Normally, I would use $_SERVER["REQUEST_METHOD"] == "POST" when the user hits the submit button, but since there are multiple submit buttons, would I be better off checking each button via if($_POST["button1"]){} and if($_POST["button2"]){}?
Is there a better way to do this? I've tried attaching a click event via jQuery to do this, however, when I get to a certain point, the script actually breaks and I'm not sure why. Regardless of which submit button is pressed, the form calls the same action page.
if($_POST["button1"]=='your-button-value'){}
and/or
if($_POST["button2"]=='your-other-button-value'){}
are best option to manage/handle data while submit from same form.
I don't think you will find anything better than this.
I am wondering if it is possible to to resubmit a form with a button click that calls up a javascript command.
So this is basically what I'm trying to do -
page 1: form; action = page2.php
page 2: generate a randomized list according to parameters set by page 1
I would like to place a button on page 2 so that on click, it would be as if the user has hit F5, and a new list would be generated with the same parameters.
I found a lot of help on Google with people trying NOT to get this to happen, but I'm not sure how to actually get it to happen.....
Thank you!
You could use location.reload(true); to refresh the page.
<button onclick="location.reload(true);">refresh</button>
you only need to use. location.reload() instead of location.reload(true). since this will not disable caching for the reload but using true as the parameter will.
here is the reference. How to refresh a page in jquery?
EDIT: why not just use hidden input field and preserve the values and fetch it anytime you want to?
FIXED, Wrapping the input tag with an anchor tag around it seemed to
have worked.
The question could sound a bit confusing, let me elaborate.
I have made a mail form with PHP. This form is all the way at the bottom of the page.
When I click send (this is an input tag), if there are errors, it will display them above the form.
But when you click on send the page will first go back to the top and you have to scroll all the way down to see if you have made any errors.
So is it possible to keep the page from jumping back the the start?
You could have a page anchor on the form and point at that anchor in the form action, something like this should do that for you.
<form action="someformaction.php#form-anchor" id="form-anchor">
</form>
Now when the form is submitted it should move the page down to where that anchor is.
By the sounds of it, you are submitting a normal form which in turn sends the email.
You can possibly put an anchor at the bottom of the page and have the action of the form point to it, so that your user will open up on that part of the page, or you could submit via a ajax instead which will not cause a page reload. Here are a bunch of tutorials you could adapt to your code.
I wonder whether someone could help me please.
I've been working on, and I've managed to put together this jQuery Modal Dialog box and it works fine.
What I'm now trying to do is to link this page to the dialog box via a button click, to be specific the 'Upload Image(s)' button.
On the button click, the dialog box correctly appears on screen, but rather than it hovering over the main page which it's called from, it appears on a seperate web browser page.
I've been working on this for days now and I just can't seem to get around the problem. I don't think the problem is with the dialog box code, but most likely in how I call the opening of it. i.e. having two submit buttons on the main form, means that I have called the page as shown below
because I wasn't sure how to deal with both of the 'submit' buttons for this particular scenario.
<form name="savemyfindstolocation" id="savemyfindstolocation" method="post" action="testdialog.php">
I just wondered whether someone could perhaps take a look at this please and let me know where I've gone wrong.
Many thanks and kind regards
You're going absolutely wrong mate. You have created a form with the action as testdialog.php which is the dialog form, if I'm not wrong.
You've given the button Upload Image as type="submit", which would SUBMIT the form ofcourse, as it is doing now.
To open a dialog, you will require to use either an input button with type="button" or a link/anchor with an onClick event.
Can you please tell where is your dialog located and how are you working with the dialog?
So I am making a small quiz app that shows one question at a time, in order to move on to the next question you have to answer the current one correctly, and you have as many tries as it takes you...The quiz works perfectly. When you have answered the last question correctly, a form is displayed and it asks you to fill out some information so that the "quizzer" can send you a gift...The submission of this form is done via php, I did plan on implement JQuery/AJAX but right now I am just testing out the DB connectivity and other functions so i kept it simple...the problem I am having is that when I hit submit the page automatically gets refreshed showing the first question again and not outputting anything from my php script..I am not really sure what kind of code I could include to help anyone solve this, as I think it is a more theoretical problem, but let me know if you want me to post more...
Thanks in advance for any help, it is greatly appreciated!
<form action"/index.php" method="POST">
Congratulations! You passed! Please enter in your email address and we will send you something cool!<br />
<input type="text" name="email" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
If the page submits and posts back to itself, the form is going to reset by design. You have to add code that detects the postback and if "True" then repopulate the form with the postback values to give the appearance of data persistance.
Havne't used PHP in a long time, but in .net you would detect a postback by calling:
....If IsPostBack Then....
When you do a postback, the entire page reloads, so that is going to fire your Javascript code again.
To avoid that, you should encapsulate just the form with AJAX to submit just the form so that the rest of the page doesn't post back (including the javascript).
Hope this gives you some direction.
Or... you can change
to post to a different file (like /index2.php) and that way you don't have to worry about postbacks or stuff like that.
Did you check the post data on the same index.php page, like doing:
if(isset($_POST) AND !empty($_POST)) {
var_dump($_POST);
}
This might help you in some way.
I am having the same issue, but with jQuery Mobile. I have implemented this on the form submit but all I need to do refresh the query results:
onClick="window.location.reload(true)"
This is basically a page refresh more than anything but might point you on the direction you need as well.