954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Posting data behind the scene

Hi,

index.php posts data to process.php

I want users to remain in index.php when they summit their form. I have seen this in some websites but don't know hot it done.
Can anyone help me?

Thanks

veledrom
Master Poster
758 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

You can use AJAX to post form data. Take a look at this link http://www.captain.at/howto-ajax-form-post-request.php

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This is where AJAX comes into play... For basics refer
http://www.w3schools.com/Ajax/Default.Asp

Hi,

index.php posts data to process.php

I want users to remain in index.php when they summit their form. I have seen this in some websites but don't know hot it done. Can anyone help me?

Thanks

venkat0904
Junior Poster
190 posts since Oct 2009
Reputation Points: 13
Solved Threads: 21
 

Hi,

index.php posts data to process.php

I want users to remain in index.php when they summit their form. I have seen this in some websites but don't know hot it done. Can anyone help me?

Thanks

All you need to do is submit the page to itself from the form tag. you will also need to make sure you give your submit button a name attribute. For example.

<form action="index.php" method="post" >
   <!-- your form inputs here -->
   <input type="submit" name="submit" value="Submit" />
</form>


and at the top of your index.php before the header should look something like

<?php
   if(isset($_POST['submit'])) {
      // do stuff here
   }
?>
// continue to display what was intended for the visitors first visit to the page if submit was not detected.


hope that helps

leviathan185
Junior Poster
105 posts since May 2009
Reputation Points: 19
Solved Threads: 15
 

This wont be a solution what he is looking... he wants index.php to submit data to process.php
n btw even if u submit the data to same page, the page gets refreshed which can be avoided only by asynchronous data transfer possible through AJAX.

All you need to do is submit the page to itself from the form tag. you will also need to make sure you give your submit button a name attribute. For example.

<form action="index.php" method="post" >
   <!-- your form inputs here -->
   <input type="submit" name="submit" value="Submit" />
</form>

and at the top of your index.php before the header should look something like

<?php
   if(isset($_POST['submit'])) {
      // do stuff here
   }
?>
// continue to display what was intended for the visitors first visit to the page if submit was not detected.

hope that helps

venkat0904
Junior Poster
190 posts since Oct 2009
Reputation Points: 13
Solved Threads: 21
 
This wont be a solution what he is looking... he wants index.php to submit data to process.php n btw even if u submit the data to same page, the page gets refreshed which can be avoided only by asynchronous data transfer possible through AJAX.

Apologies you are correct, I misread the original post.

leviathan185
Junior Poster
105 posts since May 2009
Reputation Points: 19
Solved Threads: 15
 

Ok guys thanks for your very helpful information. Now i go and read about AJAX.
Thanks

veledrom
Master Poster
758 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

anytime... n do remember to mark the thread as solved wen u r done...
Ok guys thanks for your very helpful information. Now i go and read about AJAX.
Thanks

venkat0904
Junior Poster
190 posts since Oct 2009
Reputation Points: 13
Solved Threads: 21
 

yeah i did this with form="target_blank" and then used php header to close the processing file. its really simple.

SKANK!!!!!
Posting Pro in Training
429 posts since Apr 2009
Reputation Points: 15
Solved Threads: 7
 

sure this will do the trick but i dont feel its a healthy practice as the user will get a window flashed in front n then disappearing....
Also, after closing the process file, how will u update the values in original index.php without refreshing it... I agree u will submit the form but u need to show a success or error message to user regarding it...
so best way to achieve this(AFAIK) is AJAX

yeah i did this with form="target_blank" and then used php header to close the processing file. its really simple.
venkat0904
Junior Poster
190 posts since Oct 2009
Reputation Points: 13
Solved Threads: 21
 

sorry it was for deleting msgs from an inbox. if u have a form u need to take it to the next page.

SKANK!!!!!
Posting Pro in Training
429 posts since Apr 2009
Reputation Points: 15
Solved Threads: 7
 

exactly... u have to submit ur form data to another page(or to same page with phpself) but u can do this without having user know anything abt it (ofcourse with AJAX).
cheers!!
sorry it was for deleting msgs from an inbox. if u have a form u need to take it to the next page.

venkat0904
Junior Poster
190 posts since Oct 2009
Reputation Points: 13
Solved Threads: 21
 

o i meant ajaxx is an unessary fault to use to submit just a form

SKANK!!!!!
Posting Pro in Training
429 posts since Apr 2009
Reputation Points: 15
Solved Threads: 7
 

Thats fine coz i dont know any other way to transfer data asynchronously without user's notice... if u knw den do share ur knowledge.... dats wat this forum is meant for..
o i meant ajaxx is an unessary fault to use to submit just a form

venkat0904
Junior Poster
190 posts since Oct 2009
Reputation Points: 13
Solved Threads: 21
 

Try this: At top of document which calls itself ...
<?php if(isset($_POST['submit'])) { // possibly check params here
include ("process.php"); ?>
User stays in index.php and include file can be in hidden directory.

proftwells
Newbie Poster
1 post since Nov 2009
Reputation Points: 10
Solved Threads: 0
 
Try this: At top of document which calls itself ... <?php if(isset($_POST['submit'])) { // possibly check params here include ("process.php"); ?> User stays in index.php and include file can be in hidden directory.


I think that venkat0904 doesnt want to refresh the page.

Check out these few examples, they should point you in the right direction. I am currently trying to learn AJAX myself these are quite good with good explanation. http://www.w3schools.com/Ajax/ajax_example_suggest.asp

leviathan185
Junior Poster
105 posts since May 2009
Reputation Points: 19
Solved Threads: 15
 

u should just refresh the page. by all means. ajax is an uneccesary step in the web world im astounded why so many sites have implemented it.

SKANK!!!!!
Posting Pro in Training
429 posts since Apr 2009
Reputation Points: 15
Solved Threads: 7
 

m afraid i dont fully agree with u... Its totally absurd to refresh the whole page when all u need is to update a single frame or just to display a message especially when ur page is heavy.. Watch the difference in orkut(old orkut not new one) and facebook itself...
When bandwidth is low, using ajax can make significant difference in being user friendly.

u should just refresh the page. by all means. ajax is an uneccesary step in the web world im astounded why so many sites have implemented it.
venkat0904
Junior Poster
190 posts since Oct 2009
Reputation Points: 13
Solved Threads: 21
 

maybe u should undercut why u are afraid. because im right. orcut is not a good website. i mean. ajax is left for the non forms. in genera. ajax should not be used to submit a form. and well. cant with mysl anyways

SKANK!!!!!
Posting Pro in Training
429 posts since Apr 2009
Reputation Points: 15
Solved Threads: 7
 

Even i believe orkut is not a good website... i mentioned it to compare with facebook(which i believe uses AJAX for most of its operations) and see u can tell the difference.. its way better than orkut...
And correct me if m wrong but I think we can very well use ajax for mysql.. wy wud u say that we cant... if u think it should not be used, its completely ur opinion...

maybe u should undercut why u are afraid. because im right. orcut is not a good website. i mean. ajax is left for the non forms. in genera. ajax should not be used to submit a form. and well. cant with mysl anyways
venkat0904
Junior Poster
190 posts since Oct 2009
Reputation Points: 13
Solved Threads: 21
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You