+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: Submit a form without the page reload

  1. #1
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75

    Submit a form without the page reload

    Hi everybody!

    Are you looking for a such thing? Here is my solution to this problem:

    index.html

    Code:
    <!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&#58; 300px; height&#58; 100px;" frameborder="0" 
    
    name="hidden_frame"></iframe>
    
    </body>
    </html>
    default.html

    Code:
    <!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

    Code:
    <!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&#91;"request"&#93;; ?>"</b>.</p>
    
    </body>
    </html>
    ------------------------------------
    [URL=http://www.dedicatedzone.com]Managed Dedicated Servers[\URL]

  2. #2
    Web Junky Matt is on a distinguished road
    Join Date
    Dec 2003
    Posts
    71
    Very nice, this is a very useful code

    Thanks
    WebmasterLingo.com Team
    Forum Rules

    "Anyone who has never made a mistake has never tried anything new" - Albert Einstein

  3. #3
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75
    Thanks
    ------------------------------------
    [URL=http://www.dedicatedzone.com]Managed Dedicated Servers[\URL]

  4. #4
    Full Member amish_geek is on a distinguished road
    Join Date
    Jan 2004
    Posts
    20
    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)
    Aaron Abramson
    Hosting Made Easy

  5. #5
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75
    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.
    ------------------------------------
    [URL=http://www.dedicatedzone.com]Managed Dedicated Servers[\URL]

  6. #6
    Moderator airnine is on a distinguished road
    Join Date
    Jan 2004
    Posts
    78
    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
    -------------------------------
    Airnine is a developer @
    www.promomedium.com
    -------------------------------

  7. #7
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75
    Hello,

    but iframes aren't really that cool. The best option is to have your data submitted to another page using javacript
    Well, exactly Im 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 dont 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?
    ------------------------------------
    [URL=http://www.dedicatedzone.com]Managed Dedicated Servers[\URL]

  8. #8
    Newbie Woltz is on a distinguished road
    Join Date
    Jan 2004
    Location
    Chase the birds that fly.
    Posts
    3
    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.

  9. #9
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75
    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?

  10. #10
    Newbie Woltz is on a distinguished road
    Join Date
    Jan 2004
    Location
    Chase the birds that fly.
    Posts
    3
    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.

  11. #11
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75
    But since this works almost everywhere (and personally for my website it's 100%) why so do you hate IFRAMEs??

  12. #12
    Full Member Syn is on a distinguished road
    Join Date
    Jan 2004
    Location
    Providence, RI
    Posts
    23
    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.
    Personal
    -- Avalonstar: The Moon of Syn

    Professional
    Avalonstar-Intivex, [Coming Soon] | Starvex

  13. #13
    Full Member AdulteratedJedi is on a distinguished road
    Join Date
    Jan 2004
    Posts
    9
    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

  14. #14
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75
    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...

  15. #15
    Full Member maverik60 is on a distinguished road
    Join Date
    Jan 2004
    Posts
    26
    Iframes are the devil!!!!!!!!!!!!!!!!!!!!!!!! just kidding, very useful on certain things. ill give it a try.

+ Reply to Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts