Login Retreive lost passwordRegister
Search

Forum Index / General / Form disappears on submit

[ This topic is solved ]

  Steve R 01 March 09 / 16:36  
Hello,

When I fill out my form and hit submit, the form executes properly, but then it disappears from the page. My code opens an alert box thanking the user for their email when the form is submitted. If I go away from the page then come back, for instance by clicking the browser Back button, the alert displays again as if I had submitted the form. And if I try to refresh the page it asks if I want to resend the information. So I have two questions, 1) how do I make it so the form does not disappear but stays available on the page, ready to use, and 2)how can I clear the information from the submission?

Here's my code:

<?
// include the class
include("../FormHandler/class.FormHandler.php");

// create a new FormHandler object
$form =& new FormHandler(); 

$form -> setMask
  
"  <tr><td><b>%title%</b></td></tr>\n"
  
"  <tr><td>%field% %error%</td></tr>\n"
  
true  # repeat this mask! 
); 
$form->textArea"Email Us""comment","","25");
$form -> hiddenField("site""mydomain.org");
 
// button for submitting
$form->submitButton();

// set the 'commit-after-form' function
$form->onCorrect('doRun');

// display the form
$form->flush();

// the 'commit-after-form' function
function doRun$data 
{
    echo 
"<script language='javascript'>alert('Thank you for your email')</script>";
    
$recipient "stever@mydomain.org"//recipient
    
$mail_body "Comment:".$data['comment'].
    
"\nSite:".$data['site'].
    
"\nDate Sent:"date("d/m/y,  g:i A"time()) ; //mail body
    
$subject "Email from ".$data['site']; //subject
    
$header "From: "$data['site'] . " <>\r\n"//optional headerfields

    
mail($recipient$subject$mail_body$header); //mail command :)
}
?>


Thanks for any help.

Steve Ralston

  Johan Wiegel (Admin) 01 March 09 / 18:12  
add a header command to the dorum function to header to teh form:

<?php
header
'location:/form.php' );
?>

  Steve R 08 March 09 / 03:42  
I've tried the php header call and it doesn't seem to work at all. I put it in the save to database function, I tried it in the function that creates the email and neither works. To test I set the header function to take me to twitter so I knew the function was working. If I put the header function right at the top of my file, it takes me to twitter, so I know the code is right.

  Johan Wiegel (Admin) 08 March 09 / 08:27  
Changed at 08 March 09 / 08:27
is error reporting on on your server?

I think you have a headers already send problem.

Try putting the onsaved function on the top of the file and let it redirect.

  Steve R 09 March 09 / 04:44  
I was trying to do the header function in php, but it turns out I had to use echo to write it as a javascript function, then it worked fine.

  Top


powered by PHP-GLOBE   © 2004 - 2012 FormHandler. All rights reserved.   -   Open source license