/    Sign up×
Community /Pin to ProfileBookmark

Form Question

I have a question regarding form submission. If someone fills the form and by mistake if he leaves one field blank. then If he click the BACK button of Internet Explorer then the form becomes blank. Is there any way to solve this problem. I want the filled entries remain there when the user click the BACK button. I always use OPERA and I get all the entries in the form when I click the BACK button.

My site [url]http://www.virginmaryexports.com/index.php?page=form[/url]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@temp_user123Jul 05.2007 — To me, the best way to manage for submission is to use what is called "post-back" and redirect. You make the form post to the same page where the form is defined -- until all form fields have been validated as correct. At that point, the PHP code redirects to whatever page comes next in the processing. If the post values need to be carried to that next page, then you use $_SESSION variables to manage that part. Thus, of course, the form page must initiate the session using the following as the first line in the document (including a rough outline of the entire document):

[code=php]
<?php
session_start();
...etc...
if ($_SERVER['REQUEST_METHOD'] != 'POST')
{
...etc...
}
else
{
...etc...
}
...etc...
?>
<!DOCTYPE ...
<html>
...etc...
</html>[/code]
Copy linkTweet thisAlerts:
@tcaJul 05.2007 — I think you want Sticky Forms.

One example: http://www.informit.com/articles/article.asp?p=412930&seqNum=3&rl=1

Google up "Stick Forms" for more.

TC
Copy linkTweet thisAlerts:
@saudauthorJul 05.2007 — Thanks for your replies. After doing some changes I found that If I remove this code

<?php

ob_start("ob_gzhandler");

header("Content-Encoding: gzip");

then the form stays filled if I press the back button in MSIE.

But I also want to use gzip function because this makes my site faster.

Is there any solution to this ?
Copy linkTweet thisAlerts:
@saudauthorJul 07.2007 — I found the problem in my website. It is session_start() and it is included in the counter file. Is it possible to count the session without using this function.

Here is the code
[code=php]
<?php

if (!headers_sent()) session_start();

// COOKIE COUNTER

$file = "counter.txt"; // Path to counter.txt file
$print = 1; // Set to 0 if you don't need
// the script to print out the count
// in your HTML page

$blockedip = ""; // Blocked IP addresses,
// seperate with a comma


//////// Customize the output to your HTML
//////// Edit if you have a knowledge of PHP and HTML

function output($count) { return "


$count



";}

//////// PHP Magic

$block = false;

$fhandle = fopen($file, "r");
$count = explode(",",fread($fhandle, filesize($file)));
$pcount = $count[0];
fclose($fhandle);

if (!$_SESSION['hello']) {

$_SESSION['hello'] = true;
$count[0] = $count[0] + 1;
}

if ($count[0] != $pcount) {

$wcount = $count[0];
$fhandle = fopen($file, "w");
flock($fhandle, LOCK_EX);
fwrite($fhandle, $wcount);
flock($fhandle, LOCK_UN);
fclose($fhandle);
}

if ($print) echo trim(output($count[0]));

?>
[/code]
Copy linkTweet thisAlerts:
@knowjJul 07.2007 — or just have php/javascript validation within the form page and have the values set to $_POST['field_name']

e.g

<input type="text" name="first_name" value="<?=$_POST['first_name']?>"/>

just keep all your form processing within the same file and echo the form if $_POST is not set or if $error is set (load all validation errors into a list $error .= "<li>The first name field was not filled in!<li>nr"?
×

Success!

Help @saud spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...