Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Forms Posting to self
Old 10-21-2008, 08:30 AM Forms Posting to self
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Hey, I was wondering about forms posting to its own page.
Ill try to explain this the best I can.. and still try and make sense...

You have a form which the user fills out. The submit button posts the information to the same page.

On that page there is some php code which takes that information only when it has been sent and inputs it into the database.

But it only puts the information into the database once the person has pressed submit.

Or, is it best to direct the form submitted information to another page, have that deal with the information, then return the user?

Any information would be helpful
Thanks for reading,
Lothop
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-21-2008, 08:38 AM Re: Forms Posting to self
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
As long as you prevent the data collection part running when there is no data, it does not matter in the slightest.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-21-2008, 10:12 AM Re: Forms Posting to self
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
This is normally what I do. A quick shortcut that is sometimes useful (especially if you are running a script that is generating the HTML for you, or using a common include), is the $_SERVER['PHP_SELF'] super-global. This would work like this:
PHP Code:
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<!--bunch of stuff-->
</form>
Just a quick-tip.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 10-22-2008, 08:06 AM Forms Posting to self
Banned

Posts: 3
Name: jackfranklin
Trades: 0
How can it possible with the forms posting to self, could any body give the brief idea about this.
jackfranklin is offline
Reply With Quote
View Public Profile
 
Old 10-22-2008, 09:13 AM Re: Forms Posting to self
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Thankyou for the replies

Quote:
As long as you prevent the data collection part running when there is no data, it does not matter in the slightest.
So for example, just run a simple test in the php code to see whether the posted $variable contains any value? If it does, store it, if not, show the page.

And if it does contain information, store the data, and display the page.

Is it possible to store the information and display the information in the same page? As in, display the information from the database, not the forms posted variables?

If that last bit was confusing It stores the info in the database, then pulls ALL of the previous data including the one just added on the page?
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
Old 10-22-2008, 09:22 AM Re: Forms Posting to self
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
So for example, just run a simple test in the php code to see whether the posted $variable contains any value? If it does, store it, if not, show the page.
Yep or check that the submit button has been clicked
PHP Code:
if (!$_POST["submit_button_name"]) {
//    show page;
} else {
   
// collect and validate the form data
   // insert stuff to database;

Quote:
Is it possible to store the information and display the information in the same page? As in, display the information from the database, not the forms posted variables
Yep, just requery the database after the insert/update.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-23-2008, 09:04 AM Re: Forms Posting to self
Novice Talker

Posts: 8
Name: qammar feroz
Location: Pakistan
Trades: 0
Well,

you should display the user msgs on one page. and there there should also be a form, from where users/visitors submit their comments/msgs.

on the 2nd page you will deal with the submitted data, and after successfuly adding it into DB, users/visitor will be return to the form page/page1.

that is the best choice, I suggest.

Regards,
qammar feroz
__________________
No # 1 FREE Domain Name Low Cast High Quality Web Site Development and Web Hosting
Click Here

Please login or register to view this content. Registration is FREE

Last edited by qammar; 10-23-2008 at 09:05 AM.. Reason: spell mistake
qammar is offline
Reply With Quote
View Public Profile Visit qammar's homepage!
 
Old 10-23-2008, 02:05 PM Re: Forms Posting to self
Experienced Talker

Posts: 41
Name: Jabis Sevon
Location: Tampere, Finland
Trades: 0
Quote:
Originally Posted by qammar View Post
Well,

you should display the user msgs on one page. and there there should also be a form, from where users/visitors submit their comments/msgs.

on the 2nd page you will deal with the submitted data, and after successfuly adding it into DB, users/visitor will be return to the form page/page1.

that is the best choice, I suggest.

Regards,
qammar feroz
This would be the ideal situation, but if you for example, would like to post stuff in your index page and after submission see the results straight away (IE. Polls) you would need to post the stuff to the index page itself, sometimes.
The alternative of course is to use another page and use a header redirect to the original after validating/inputting the data, this would kill the obvious double-posting issue, but it's not always necessary, and would sometimes require even more code lines to achieve the same result as burying the code in the same page

Here's a sample solution, first codeblock to the very top of the file:
PHP Code:
<?php 
if(isset($_POST['submit'])) {
  foreach(
$_POST as $key => $value) {
    
/* we'll just store the results to a cookie and after it do a header refresh to kill the double-posting issue */
    
setcookie($key$value); 
  }
  
header("Location: index.php?showresults");

else if(isset(
$_GET['showresults'])) {
  if(isset(
$_COOKIE)) { 
    
$toEcho "<h2> Your results </h2>";
    foreach(
$_COOKIE as $submission => $value) {
      
$toEcho .=  "<h5>".$submission." posted has value ".$value."</h5>";
    }
    
$toEcho .= "<p>End of results</p>";
  } else { 
    
$toEcho "<strong>No posted data saved or cookies disabled</strong>";
  }

else {
$toEcho = <<< EOD 
<form name="name" method="post" action="index.php">
...
inputfields
<input type="button" id="submit" name="submit">Submit</button>
EOD;
}
?>
and after that your basic html body, to the point where you wish to display the form / result and then just do to display it:
PHP Code:
<?php echo $toEcho?>
Hope I didn't go over too far with this post, but it shows how to evade the doubleposting issue as well as keep track of your submitted data in a cookie, where you could access it later...

Hope it helps :>

PS. Oh and I use input type button instead of type submit, to fix a few issues with IE's enter-key submission issue, and firefox's submit type not posting with the form itself ($_POST['submit'] not always seen in the post-data, so you'd never get to the handling of the post)

Last edited by jabis; 10-23-2008 at 02:10 PM.. Reason: added ps
jabis is offline
Reply With Quote
View Public Profile Visit jabis's homepage!
 
Old 10-23-2008, 08:05 PM Re: Forms Posting to self
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Thankyou for your input.

I will have a crack at the single page and get back to what results from it so people can search for this and get a result in future.

Thanks
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Forms Posting to self
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29181 seconds with 12 queries