By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,528 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,528 IT Pros & Developers. It's quick & easy.

Refresh or close after form submission

100+
P: 219
I have a page that I want to be refreshed after a user submits a form. I also have another page that I want to be closed after a user submits a form.

How would I go about doing this??
Nov 7 '08 #1
Share this Question
Share on Google+
21 Replies


gits
Expert Mod 5K+
P: 5,390
could you explain that a bit more? what do you mean with closing a page - do you mean closing a window that displays a page? when you submit what happens then - do you call a php script that you control?

kind regards
Nov 7 '08 #2

100+
P: 219
I have a popup form that's used to submit comments. When the user clicks the submit button, I'd like the popup window to close once the submission takes place.
Nov 10 '08 #3

gits
Expert Mod 5K+
P: 5,390
just call a js-function onsubmit of your form that uses window.close()

kind regards
Nov 10 '08 #4

100+
P: 219
just call a js-function onsubmit of your form that uses window.close()

kind regards
Excellent, I'll give that a try
Nov 10 '08 #5

100+
P: 219
How come if I try to do this:

onSubmit="window.location.reload();" in my form tag it's not submitting the form, it's just refreshing the screen. I want the screen to refresh after the form gets submitted to allow the user to enter a new form without having to jump between screens.
Nov 12 '08 #6

acoder
Expert Mod 15k+
P: 16,027
onsubmit is called as soon as the submit button is pressed, not after the submit takes place. Add the refresh to the submitted page instead.
Nov 13 '08 #7

P: 20
I have the same problem as I want to make the submit button refresh.

I have 3 frames on my page and need the page to refresh after a submit button is pressed for its changes to take effect (change style sheet)

However using


<input type="submit" onSubmit="window.location.reload();" value="Go">just submits and does not refresh.

I am using the http://php.about.com/od/finishedphp1...s_switcher.htm script.

Does anyone know how to make the button refresh the page as well?
Jun 10 '09 #8

acoder
Expert Mod 15k+
P: 16,027
onsubmit is a form event, not an input button event. In any case, that wouldn't work either. I assume the form is in a frame and the form submits to the same frame. What you'd need to do is refresh the whole page after the page has been submitted.
Jun 11 '09 #9

P: 20
Yes, I don't want my visitors to have to manualy do that.

I was thinking of putting js into my cookie.php which is what the form is linked to.
But don't know what to add?
Jun 11 '09 #10

acoder
Expert Mod 15k+
P: 16,027
You'd need to reference the parent using 'parent' or 'top' and then reload. It is possible to change styles without reloading the page. One other thing: if possible, try to avoid frames.
Jun 11 '09 #11

P: 20
I tried targeting it with _Parent but it just loaded the same frame in the frame that was suppost to refresh.
Jun 11 '09 #12

acoder
Expert Mod 15k+
P: 16,027
Do you only want to reload one frame or the page which contains the 3 frames?
Jun 11 '09 #13

P: 20
just 1 other frame would do, but either. If its possible to reload the whole page then i'd prefer that.
Jun 11 '09 #14

acoder
Expert Mod 15k+
P: 16,027
To access the parent (the page containing the frames) and reload it:
Expand|Select|Wrap|Line Numbers
  1. parent.location.reload();
You would call this after page load in one of the frames. Is there any particular reason why you're using frames?
Jun 12 '09 #15

P: 20
Where would I put that thought.

Its part of the design.
Jun 12 '09 #16

acoder
Expert Mod 15k+
P: 16,027
You can put it in the form action page:
Expand|Select|Wrap|Line Numbers
  1. window.onload = function() {
  2.     parent.location.reload();
  3. }
Jun 12 '09 #17

P: 20
Thank you very much.
Thats the one.. nearly, as this runs the whole page in a loop :P
I just added
Expand|Select|Wrap|Line Numbers
  1. framename.document.
  2.  
So the whole code reads

Expand|Select|Wrap|Line Numbers
  1. window.onload = function() { 
  2.     parent.framename.document.location.reload(); 
  3.  
Once again, thank you very much for your help, I do appreciate it. :)
Jun 13 '09 #18

P: 20
The only problem I have is that it makes the target frame a bit jumpy when it loads as it has to load twice the first time round (initial load, and refresh).

So is it possible to only run the script when the button is submitted?
I have tried the following but it did not work.
Expand|Select|Wrap|Line Numbers
  1. <input type="submit" value="Go" onSubmit="parent.framename.document.location.reload();">
  2.  
Jun 13 '09 #19

acoder
Expert Mod 15k+
P: 16,027
Use PHP code to decide if the code should exist. Only have the JavaScript code run if the form has been submitted, e.g.
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.     if (isset(...)) {
  3. ?>
  4. <script type="text/javascript">
  5. ...
  6. </script>
  7. <?php
  8.     }
  9. ?>
Jun 14 '09 #20

P: 20
It does not refresh when clicked, what have I done wrong?

This is the code in the form frame.

Expand|Select|Wrap|Line Numbers
  1. <?php  
  2.     if (isset($var)) { 
  3. ?> 
  4. <script type="text/javascript"> 
  5. $var window.onload = function() {  
  6.     parent.frameName.document.location.reload();  
  7. }  
  8. </script> 
  9. <?php 
  10.     } 
  11. ?>
  12.  
Jun 21 '09 #21

acoder
Expert Mod 15k+
P: 16,027
No, it doesn't quite work like that. You need to replace $var with the posted variable in PHP, e.g. $_POST['submit']. Also remove $var on line 5. If you have any more problems on that front, ask in the PHP forum.
Jun 21 '09 #22

Post your reply

Sign in to post your reply or Sign up for a free account.