Solved

Submit form to SELF without refreshing

Posted on 2010-11-25
9
1,151 Views
Last Modified: 2012-05-10
Hi Experts,

A really simple concept. I have looked everywhere for some solution similar to mine but havent really figured a way out unfortunately.

Basically i have a page called form.php in which i have 2 functions being called via php
 <?php if (!isset($_POST['submit'])){?>    
            
       		<?php show_form();?>
         
         <?php } else {?>
         	
           <?php output_form(); ?>
         
         <?php }?>

Open in new window


Basically if form is not submitted it outputs the form function (show_form()) and if it has been submitted then it ouputs a function which outputs the user inputed values (ouput_form()).

All is working fine. But when i submit the form it refreshes the page. I want it submit the form so that the page dosent refresh. Everything is being processed and outputted on the same page.

Any pointers or guidlines will be GREATLY appreciated

Thanks
 
0
Comment
Question by:ACEAFTY
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 12

Expert Comment

by:HugoHiasl
ID: 34212036
If you don't want to refresh the page that you submit to, why do then submit to it?

If you want only some background work done without feedback to the user, you could submit to an invisible frame.
0
 
LVL 1

Author Comment

by:ACEAFTY
ID: 34212103
I would want the user to submit as he will see the result. And the result will be a HTML template with his input showing in a certain way. So the user has to click on submit basically a preview button. But the preview should show up without a refresh..

I might be able to be interested in the frame but how to go about that. If you have a link i would appreciate the resource :)

Thanks
0
 
LVL 2

Accepted Solution

by:
marceloOrigoni earned 250 total points
ID: 34212447
You should use some of the javascript libraries, I personally prefer mootools, but jQuery, Dojo, prototype can do it as well.

 Marcelo
0
 
LVL 13

Assisted Solution

by:darren-w-
darren-w- earned 250 total points
ID: 34212498
Hi,

there are a few simple methods you can used with Jquery, the most simplest would be the load() method, but also there is the ajax() method too, you would simply detect the button being pressed returning false and calling the method then your form, outputting the returned content into a div on the page.

Darren

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34212988
You can create the effect of a page that does not refresh with jQuery.

But I've just got to ask - why would you go to the effort?  The client fills in a form and clicks "submit" - and the HTML form sends the data to the URL in the action= attribute of the <form> tag, and a new page appears.  It's been like that on the WWW for almost 20 years, and it still works well today.  Most importantly, you can get your application working instantly if you use the tried and true methods.
0
 
LVL 2

Expert Comment

by:marceloOrigoni
ID: 34213394
 Yeah, why are we going to use html 5, and css 3, let's go back to plain HTML3, and let's make designs full of tables.
 Because you need to reload a 20KB site, when you can only load a 1KB file.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34213458
Reload a 20KB site?  Sure - why not?  You will have little difference in page load time versus a 1KB file.  It's a lot easier to write code that works when you use techniques that work.  I doubt that there is any harm in reloading a 20KB site, especially when compared to losing days of your life trying to debug something that you don't already understand!

I'm not a luddite, and I don't have any objection to progress - including HTML5 and CSS3.  I use tables for tabular data, but not for design (and I'm not really much of a designer, anyway).  But I do believe in taking the path of least resistance.

Best to all, over and out, ~Ray
0
 
LVL 1

Author Comment

by:ACEAFTY
ID: 34216821
The reason i would really like this feature is because on the form the user will be adding additional input fields to the form using jquery. On a refresh these would dissapear and if the user wanted to come back to RE-EDIT the form then those fields would dissapear due to the refresh.

Maybe i am going it about the wrong way. Which is why i would like to have pointers. The reason i was finding ajax a problem was because on the ajax call every example i have seen is the process being called from an external php file, rather than for a form being submitted to itself.

I have come with a temporary solution. Making the form target set to "_blank" hence output opening in another page without refreshing the current form. Thanks for everyones input
0
 
LVL 1

Author Closing Comment

by:ACEAFTY
ID: 34237890
Was not as simple as expected.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now