E-mail submission page - re-sends data when page reloads/refreshes.
Ok, well ive posted quite a lot of code (excluding the html which is unnessisary for my problem), but this code is for my home page which has a mailing list submission form, which works fine.... nearly.
It all works apart from when you submit a valid e-mail address and then refresh or re-visit the page, where it posts the e-mail adress you submitted again as the page is loading.
- perhaps the form/page needs resetting somehow...??
Its a bit of a challenge but could anyone solve the problem. Any help will be much appriciated, thanks.
<?php
$value = 'Your E-mail address';
if(isset($_POST['B1'])){
$value = $_POST['Email'];
// get posted data into local variables
$EmailTo = "mailinglist@theparoles.co.uk";
$Subject = "Mailing list";
$Email = Trim(stripslashes($_POST['Email']));
// prepare email body text
$Body = "";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
That is not a problem with the script. Rather it is your browser storing the data. Maybe setting a cookie will stop it. Try the following:
PHP Code:
<?php
$value = 'Your E-mail address';
if(isset($_POST['B1'])){
$value = $_POST['Email'];
// get posted data into local variables
$EmailTo = "mailinglist@theparoles.co.uk";
$Subject = "Mailing list";
$Email = Trim(stripslashes($_POST['Email']));
// prepare email body text
$Body = "";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
<script language="javascript"> is invalid. It should be: <script type="text/javascript">. Personally I hate the javascript alert idea. And secondly let me assure you this is very basic code and that I am a complete beginner.
There are a couple of free ones. Crimson Editor and ConText. I like Crimson best. It highlights your code and helps with brackets. When an opening bracket is focused it underlines the closing bracket.
i don't want to keep demanding things of you but i want the form to always 'be there' and you can submit the same e-mail as many times as someone wants and, i like the alerts.
The thing that needs changing is the fact that the form is sent when the code is run (i.e. when the page loads).
You are not making any sense! You keep asking for different things. You said: 'It all works apart from when you submit a valid e-mail address and then refresh or re-visit the page where it posts the e-mail adress you submitted again as the page is loading'. Now you are saying you want that to happen. And why would you want to display the form once the client has done the submission?
What is the point of being able to submit the same email numerous times? And why do you want the form to still be displayed after the submission has been done?
Well i don't nessiseraly want the same person to be able to sign up using the same e-mail address, its just that if more than one person wanted to use the same browser they would not be able to sign up as the other person already has done so (unless they revisit the site, clearing the stored email data)
I want the form to be displayed all the time as it is part of the website layout.
It might be a better idea for the code to write to a txt file creating a list of e-mail addreses when a subscribe radio button is selected. Then if someone signs up with the same email it could cheack the txt file for the same email, also it could delete email address when the person selects a radio button unsubscribe. - might be to hard, i duno
And secondly let me assure you ... that I am a complete beginner.
Ya right LOL aren't we all
As for your form thing. As Bokeh said that is a browser issue. The browser is storing the info.
You could store that info in a txt file, but I believe that if you have access to a database that would be much much much better! txt files can get unwieldly after awhile.
You could also think about setting a session variable so that when the form is submitted it processes it then destroy the session variable upon a successful submission so that when someone refreshes the page or goes back they will only see the original form. This will not stop them from refilling out the form and submitting it though.
Well i have just tried adding echo "history.back()"; tothe javascript sections and it seems to have worked.
This is how the code looks withe the added code:
(this is the webpage with the form on: www.theparoles.co.uk/index2.php)
if($success){
echo "<script language=\"javascript\">\n";
echo "<!--\n";
echo "alert(\"Thank you for singing up to our mailing list.\");";
echo "history.back()";
echo "\n\/\/-->";
echo "</script>";
Bookmarks