View Full Version : Submit a form without the page reload
ZYV
December 28th, 2003, 04:42 AM
Hi everybody!
Are you looking for a such thing? Here is my solution to this problem:
index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
</head>
<body>
<p>Hello!</p>
<form action="submit.php" method="post" target="hidden_frame">
<input type="hidden" name="request" value="something cool">
<input type="submit" value="Submit request">
</form>
<iframe src="default.html" style="width: 300px; height: 100px;" frameborder="0"
name="hidden_frame"></iframe>
</body>
</html>
default.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Default</title>
</head>
<body>
<p>Form wasn't submitted.</p>
</body>
</html>
submit.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Submit</title>
</head>
<body>
<p>Form was submitted! The request was
<b>"<?php echo $_POST["request"]; ?>"</b>.</p>
</body>
</html>
Matt
December 28th, 2003, 12:55 PM
Very nice, this is a very useful code :)
Thanks
ZYV
December 29th, 2003, 07:11 AM
Thanks :)
amish_geek
January 14th, 2004, 10:07 PM
Interesting... why wouldnt you want to have a page reload?
I do most of my websites in php, and then call functions to display components depending on what page is being called (i.e. site.com/index.php?go=home or site.com/index.php?go=about)
So a page reload doesnt really affect me (that I can see anyways)
ZYV
January 15th, 2004, 04:23 AM
Hello,
Originally posted by amish_geek
Interesting... why wouldnt you want to have a page reload?
Well, yes indeed, most of times you can live without this, but image that you are writing a voting poll. You have it on every top-level page of your site and you don't want redirect the user that answered to your survey to another page. Why most of users don't like surveys?
1) Most of times they open in the pop-up.
2) Sometimes they take them away from the page they are reading.
Using my code you can't fight all the two problems - let user answer to your survey and show him results instantly without the whole page reload.
That is also handy for the spelling error syst3m.
airnine
January 20th, 2004, 01:54 PM
Everything is true,
but iframes aren't really that cool.
The best option is to have your data submitted to another page using javacript window.open function and collect your data there with a script,
after you do that, you use javascript in the new window and put window.close
so you submit your data in first.php to second.php in new window and close second window after you have got the data submitted
nice and sweet, isn't it?!
Airnine
ZYV
January 21st, 2004, 08:17 AM
Hello,
but iframes aren't really that cool. The best option is to have your data submitted to another page using javacript …
Well, exactly I’m saying that IFRAMEs are way much better than the pop-ups. There are many reasons for this. The first and the biggest is my own preference: I don’t like pop-ups at all under any circumstances :)
Then, many users use pop-up blocking programs which will broke your script. Third, many users disable JavaScript, have a JS-cutting firewall or use a browser without proper JS support, for example in our universitary network we have a JS-cutting firewall... The <form target=”xxx”> will still work as it should.
And finally, IFRAMEs are widely supported, e.g. even in the old NN versions.
Could you please show me the downsides if any?
:beer:
Woltz
January 21st, 2004, 07:16 PM
iframes don't work on all browsers, IE is one of the few that support it, I belive netscape doesn't but not completely sure, and sure that Opera doesn't. Don't know of others.
ZYV
January 22nd, 2004, 10:41 AM
Woltz
You are wrong about Opera, Opera 5+ does support iframes (not sure about older versions). Netscape 4 doesn't and Netscape 6+ does (not sure about 5, never tried it, but most probably it does). Then I guess IE 3+ support iframes as well.
Is that few??? 99% of currently used browsers?
Woltz
January 22nd, 2004, 03:43 PM
True, I still hate frames..., and also there is never a 100% way of making sure something works, so even if you use javascript, or iframes, it won't always work.
ZYV
January 23rd, 2004, 12:10 PM
But since this works almost everywhere (and personally for my website it's 100%) why so do you hate IFRAMEs??
Syn
January 23rd, 2004, 12:31 PM
This is a useful system. I was thinking something along the lines of iFrames when I saw the title of the thread. But pretty damn good. :D
AdulteratedJedi
January 27th, 2004, 08:13 PM
I-Frames arn't going to be supported by the XHTML 2 standards .. theres one of many reasons not to use them :P
I must admit though i still use them, but only for one reason. The WYSIWYG editor ive been working on needs to use them, partly because its probably the best way to do this sort of thing.
AJ
ZYV
January 28th, 2004, 07:18 AM
AdulteratedJedi
And yes, that's one of the reasons too... I am currently porting everything to <div>'s combined with innerHTML JS function, but that's less supported than IFRAMES though...
maverik60
January 28th, 2004, 05:42 PM
Iframes are the devil!!!!!!!!!!!!!!!!!!!!!!!! just kidding, very useful on certain things. ill give it a try.
vBulletin v3.0.5, Copyright ©2000-2008, Jelsoft Enterprises Ltd.