Hi!
I have done a mailing list using the mailing list tutorial,
but now I want to do so you just fill in the email address in the form and then once you have clicked on "submit" you should come to another form where you must fill in the first name, last name, etc.
In order to be sent to the form number 2, I use $ _SESSION [ 'email'] = $ _POST [ 'email'].
I made a email_exists () function on page 1 instead of add_user () function to check if the email is already in the database before it is sent on to the Form 2, and then I sat add_user () function in the document where other form is.
Then I laggt to email argument there, so that the email address will be added to the database when you click on "submit" on the second form.
But when I enter the first name, etc., then stored only the first name, last name, country, year, month, day and postcode, but the email address column is empty. How should I do to even the email address will be stored in the database.
Please, help me and thanks for support.
Take care!
//Tiaz
Multiple forms to mailing list
Re: Multiple forms to mailing list
I can't help you without seeing your code. I can only imagine how your code looks.
Post every relevant document inside codetags and I'll look at it.
Post every relevant document inside codetags and I'll look at it.
Re: Multiple forms to mailing list
Followig code is the start page with the emal form:
[syntax=php] <?php
require "core/init.inc.php";
$errors = array();
echo 'email-post='.$_POST['email'].'\n';
if(isset($_POST['email']))
{
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false)
{
$errors[] = "<span class='errors'>The email address you gave does not appear to be valid.</span>";
}
if(empty($errors))
{
if(email_exists($_POST['email']) === true)
{
$errors[] = "<span class='errors'>Something went wrong, you may already subscribed.</span>";
}
}
if(empty($errors))
{
echo '<form id="subscribeForm" method="Post" action="func/newsletter/signupForm2.php">';
echo '<input type="hidden" name="email" id="email" value="'.$_POST['email'].'">';
echo '</form>';
echo '<script type="text/javascript">document.getElementById("subscribeForm").submit();</script>';
}
}
?>[/syntax]
This code is paste in <body> tag 'cause of the javascript code.
I want to replace the javascript with header() session function instead to redirect to the second form.
Following code is the second page there you will fill in your firstname lastname etc. Before you submitting.
[syntax=php]
<?php
require "core/init.inc.php";
$errors = array();
$thanksMsg = array();
$countries = array(
'Afghanistan','Aland Islands','Albania','Algeria','American Samoa',
'Andorra','Angola','Anguilla','Antarctica','Antigua and Barbuda',
'Argentina','Armenia','Aruba','Australia','Austria',
'Azerbaijan','Bahamas','Bahrain','Bangladesh','Barbados',
'Belarus','Belgium','Belize','Benin','Bermuda',
'Bhutan','Bolivia','Bosnia and Herzegovina','Botswana',
'Bouvet Island','Brazil','British Virgin Islands','British Indian Ocean Territory',
'Brunei Darussalam','Bulgaria','Burkina Faso','Burundi','Cambodia',
'Cameroon','Canada','Cape Verde','Cayman Islands','Central African Republic',
'Chad','Chile','China','Hong Kong, Region of China','Hong Kong, Region of China',
'Christmas Island','Cocos (Keeling) Islands','Colombia','Comoros','Congo (Brazzaville)',
'Congo, Democratic Republic of the','Cook Islands','Costa Rica','Côte d`Ivoire', 'Croatia',
'Cuba','Cyprus','Czech Republic','Denmark','Djibouti',
'Dominica','Dominican Republic','Ecuador','Egypt','El Salvador',
'Equatorial Guinea','Eritrea','Estonia','Ethiopia','Falkland Islands (Malvinas)',
'Faroe Islands','Fiji','Finland','France','French Guiana',
'French Polynesia','French Southern Territories','Gabon','Gambia','Georgia',
'Germany','Ghana','Gibraltar','Greece','Greenland',
'Grenada','Guadeloupe','Guam','Guatemala','Guernsey',
'Guinea','Guinea-Bissau','Guyana Haiti','Heard Island and Mcdonald Islands','Holy See (Vatican City State)',
'Honduras','Hungary','Iceland','India','Indonesia',
'Iran, Islamic Republic of Iraq','Ireland','Isle of Man', 'Israel',
'Italy','Jamaica','Japan','Jersey','Jordan',
'Kenya','Kiribati','Korea, Democratic People`s Republic of','Korea, Republic of','Kuwait',
'Kyrgyzstan','Lao PDR','Latvia','Lebanon','Lesotho',
'Liberia','Libya','Liechtenstein','Lithuania','Luxembourg',
'Macedonia, Republic of','Madagascar','Malawi','Malaysia','Maldives',
'Mali','Malta','Marshall Islands','Martinique','Mauritania',
'Mauritius','Mayotte','Mexico','Micronesia, Federated States of','Moldova',
'Monaco','Mongolia','Montenegro','Montserrat','Morocco',
'Mozambique','Myanmar','Nauru','Nepal','Netherlands',
'Netherlands Antilles','New Caledonia','New Zealand','Nicaragua','Niger',
'Nigeria','Niue','Norfolk Island','Northern Mariana Islands','Norway',
'Oman','Pakistan','Palau','Palestinian Territory, Occupied','Panama',
'Papua New Guinea','Paraguay','Peru','Philippines','Pitcairn',
'Poland','Portugal','Puerto Rico','Qatar','Réunion',
'Romania','Russian Federation','Rwanda','Saint-Barthélemy','Saint Helena',
'Saint Kitts and Nevis','Saint Lucia','Saint-Martin (French part)','Saint Pierre and Miquelon','Saint Vincent and Grenadines',
'Samoa','San Marino','Sao Tome and Principe','Saudi Arabia','Senegal',
'Serbia','Seychelles','Sierra Leone','Singapore','Slovakia',
'Slovenia','Solomon Islands','Somalia','South Africa','South Georgia and the South Sandwich Islands',
'South Sudan','Spain','Sri Lanka','Sudan','Suriname',
'Svalbard and Jan Mayen Islands','Swaziland','Sweden','Switzerland','Syrian Arab Republic (Syria)',
'Taiwan, Republic of China','Tajikistan','Tanzania, United Republic of','Thailand','Timor-Leste',
'Togo','Tokelau','Tonga','Trinidad and Tobago','Tunisia',
'Turkey','Turkmenistan','Turks and Caicos Islands','Tuvalu','Uganda',
'Ukraine','United Arab Emirates','United Kingdom','United States of America','United States Minor Outlying Islands',
'Uruguay','Uzbekistan','Vanuatu','Venezuela (Bolivarian Republic of)','Viet Nam',
'Virgin Islands, US','Wallis and Futuna Islands','Western Sahara','Yemen','Zambia',
'Zimbabwe'
);
$months = array(
'January', 'February', 'March', 'April',
'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'
);
$days = array(
'1', '2', '3', '4', '5', '6', '7', '8', '9', '10',
'11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
'21', '22', '23', '24', '25', '26', '27', '28', '29', '30',
'31'
);
if(isset($_POST['firstName'], $_POST['lastName'], $_POST['country'], $_POST['year'], $_POST['month'], $_POST['day'], $_POST['postCode']))
{
if(empty($_POST['firstName']))
{
$errors[] = "<span class='errors'>You must enter your firstname.</span>";
}
if(empty($_POST['lastName']))
{
$errors[] = "<span class='errors'>You must enter your lastname.</span>";
}
if($_POST['country'] === 'COUNTRY')
{
$errors[] = "<span class='errors'>Please, select a country.</span>";
}
if($_POST['year'] === 'YEAR' && $_POST['month'] === 'MONTH' && $_POST['day'] === 'DAY')
{
$errors[] = "<span class='errors'>Please, enter your birthdate.</span>";
}
if($_POST['year'] === 'YEAR')
{
$errors[] = "<span class='errors'>You have to select a year.</span>";
}
if($_POST['month'] === 'MONTH')
{
$errors[] = "<span class='errors'>You have to select a month.</span>";
}
if($_POST['day'] === 'DAY')
{
$errors[] = "<span class='errors'>You have to select a day.</span>";
}
if(empty($_POST['postCode']))
{
$errors[] = "<span class='errors'>You need to enter your postal code.</span>";
}
if(empty($errors))
{
if(add_user($_POST['email'], $_POST['firstName'], $_POST['lastName'], $_POST['country'], $_POST['year'], $_POST['month'], $_POST['day'], $_POST['postCode']) === true)
{
$thanksMsg[] = "<span class='thanksText'>thanks for subscribing, <br /> now you are the first to find out the latest. <br /> By mail address you entered.</span>";
}
}
}
?>
[/syntax]
My problem is when I redirect to second form using session header() It store all the data form the second form in the database, but the email column still empty. How should I make the email adress the user entered to be stored when you locating to the other form so when I click on submit on the second form, it will store all the data into the database?
Thanks for helping!
Take care!
//Tiaz
[syntax=php] <?php
require "core/init.inc.php";
$errors = array();
echo 'email-post='.$_POST['email'].'\n';
if(isset($_POST['email']))
{
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false)
{
$errors[] = "<span class='errors'>The email address you gave does not appear to be valid.</span>";
}
if(empty($errors))
{
if(email_exists($_POST['email']) === true)
{
$errors[] = "<span class='errors'>Something went wrong, you may already subscribed.</span>";
}
}
if(empty($errors))
{
echo '<form id="subscribeForm" method="Post" action="func/newsletter/signupForm2.php">';
echo '<input type="hidden" name="email" id="email" value="'.$_POST['email'].'">';
echo '</form>';
echo '<script type="text/javascript">document.getElementById("subscribeForm").submit();</script>';
}
}
?>[/syntax]
This code is paste in <body> tag 'cause of the javascript code.
I want to replace the javascript with header() session function instead to redirect to the second form.
Following code is the second page there you will fill in your firstname lastname etc. Before you submitting.
[syntax=php]
<?php
require "core/init.inc.php";
$errors = array();
$thanksMsg = array();
$countries = array(
'Afghanistan','Aland Islands','Albania','Algeria','American Samoa',
'Andorra','Angola','Anguilla','Antarctica','Antigua and Barbuda',
'Argentina','Armenia','Aruba','Australia','Austria',
'Azerbaijan','Bahamas','Bahrain','Bangladesh','Barbados',
'Belarus','Belgium','Belize','Benin','Bermuda',
'Bhutan','Bolivia','Bosnia and Herzegovina','Botswana',
'Bouvet Island','Brazil','British Virgin Islands','British Indian Ocean Territory',
'Brunei Darussalam','Bulgaria','Burkina Faso','Burundi','Cambodia',
'Cameroon','Canada','Cape Verde','Cayman Islands','Central African Republic',
'Chad','Chile','China','Hong Kong, Region of China','Hong Kong, Region of China',
'Christmas Island','Cocos (Keeling) Islands','Colombia','Comoros','Congo (Brazzaville)',
'Congo, Democratic Republic of the','Cook Islands','Costa Rica','Côte d`Ivoire', 'Croatia',
'Cuba','Cyprus','Czech Republic','Denmark','Djibouti',
'Dominica','Dominican Republic','Ecuador','Egypt','El Salvador',
'Equatorial Guinea','Eritrea','Estonia','Ethiopia','Falkland Islands (Malvinas)',
'Faroe Islands','Fiji','Finland','France','French Guiana',
'French Polynesia','French Southern Territories','Gabon','Gambia','Georgia',
'Germany','Ghana','Gibraltar','Greece','Greenland',
'Grenada','Guadeloupe','Guam','Guatemala','Guernsey',
'Guinea','Guinea-Bissau','Guyana Haiti','Heard Island and Mcdonald Islands','Holy See (Vatican City State)',
'Honduras','Hungary','Iceland','India','Indonesia',
'Iran, Islamic Republic of Iraq','Ireland','Isle of Man', 'Israel',
'Italy','Jamaica','Japan','Jersey','Jordan',
'Kenya','Kiribati','Korea, Democratic People`s Republic of','Korea, Republic of','Kuwait',
'Kyrgyzstan','Lao PDR','Latvia','Lebanon','Lesotho',
'Liberia','Libya','Liechtenstein','Lithuania','Luxembourg',
'Macedonia, Republic of','Madagascar','Malawi','Malaysia','Maldives',
'Mali','Malta','Marshall Islands','Martinique','Mauritania',
'Mauritius','Mayotte','Mexico','Micronesia, Federated States of','Moldova',
'Monaco','Mongolia','Montenegro','Montserrat','Morocco',
'Mozambique','Myanmar','Nauru','Nepal','Netherlands',
'Netherlands Antilles','New Caledonia','New Zealand','Nicaragua','Niger',
'Nigeria','Niue','Norfolk Island','Northern Mariana Islands','Norway',
'Oman','Pakistan','Palau','Palestinian Territory, Occupied','Panama',
'Papua New Guinea','Paraguay','Peru','Philippines','Pitcairn',
'Poland','Portugal','Puerto Rico','Qatar','Réunion',
'Romania','Russian Federation','Rwanda','Saint-Barthélemy','Saint Helena',
'Saint Kitts and Nevis','Saint Lucia','Saint-Martin (French part)','Saint Pierre and Miquelon','Saint Vincent and Grenadines',
'Samoa','San Marino','Sao Tome and Principe','Saudi Arabia','Senegal',
'Serbia','Seychelles','Sierra Leone','Singapore','Slovakia',
'Slovenia','Solomon Islands','Somalia','South Africa','South Georgia and the South Sandwich Islands',
'South Sudan','Spain','Sri Lanka','Sudan','Suriname',
'Svalbard and Jan Mayen Islands','Swaziland','Sweden','Switzerland','Syrian Arab Republic (Syria)',
'Taiwan, Republic of China','Tajikistan','Tanzania, United Republic of','Thailand','Timor-Leste',
'Togo','Tokelau','Tonga','Trinidad and Tobago','Tunisia',
'Turkey','Turkmenistan','Turks and Caicos Islands','Tuvalu','Uganda',
'Ukraine','United Arab Emirates','United Kingdom','United States of America','United States Minor Outlying Islands',
'Uruguay','Uzbekistan','Vanuatu','Venezuela (Bolivarian Republic of)','Viet Nam',
'Virgin Islands, US','Wallis and Futuna Islands','Western Sahara','Yemen','Zambia',
'Zimbabwe'
);
$months = array(
'January', 'February', 'March', 'April',
'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'
);
$days = array(
'1', '2', '3', '4', '5', '6', '7', '8', '9', '10',
'11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
'21', '22', '23', '24', '25', '26', '27', '28', '29', '30',
'31'
);
if(isset($_POST['firstName'], $_POST['lastName'], $_POST['country'], $_POST['year'], $_POST['month'], $_POST['day'], $_POST['postCode']))
{
if(empty($_POST['firstName']))
{
$errors[] = "<span class='errors'>You must enter your firstname.</span>";
}
if(empty($_POST['lastName']))
{
$errors[] = "<span class='errors'>You must enter your lastname.</span>";
}
if($_POST['country'] === 'COUNTRY')
{
$errors[] = "<span class='errors'>Please, select a country.</span>";
}
if($_POST['year'] === 'YEAR' && $_POST['month'] === 'MONTH' && $_POST['day'] === 'DAY')
{
$errors[] = "<span class='errors'>Please, enter your birthdate.</span>";
}
if($_POST['year'] === 'YEAR')
{
$errors[] = "<span class='errors'>You have to select a year.</span>";
}
if($_POST['month'] === 'MONTH')
{
$errors[] = "<span class='errors'>You have to select a month.</span>";
}
if($_POST['day'] === 'DAY')
{
$errors[] = "<span class='errors'>You have to select a day.</span>";
}
if(empty($_POST['postCode']))
{
$errors[] = "<span class='errors'>You need to enter your postal code.</span>";
}
if(empty($errors))
{
if(add_user($_POST['email'], $_POST['firstName'], $_POST['lastName'], $_POST['country'], $_POST['year'], $_POST['month'], $_POST['day'], $_POST['postCode']) === true)
{
$thanksMsg[] = "<span class='thanksText'>thanks for subscribing, <br /> now you are the first to find out the latest. <br /> By mail address you entered.</span>";
}
}
}
?>
[/syntax]
My problem is when I redirect to second form using session header() It store all the data form the second form in the database, but the email column still empty. How should I make the email adress the user entered to be stored when you locating to the other form so when I click on submit on the second form, it will store all the data into the database?
Thanks for helping!
Take care!
//Tiaz
Re: Multiple forms to mailing list
What does the second form look like? I don't see where all your $_POST variables get their values from.
You said in your first post you store the value of $_POST['email'] inside $_SESSION['email'] so you can use it in the second form, but you still add_user with $_POST['email'] instead of $_SESSION['email']. Are you sure you're giving the post variable a value?
You said in your first post you store the value of $_POST['email'] inside $_SESSION['email'] so you can use it in the second form, but you still add_user with $_POST['email'] instead of $_SESSION['email']. Are you sure you're giving the post variable a value?
Re: Multiple forms to mailing list
Hey,
It looks like your using a two step form but trying to use the data from both of them at the last step.
$_POST doesn't work the same way as $_SESSION, it's only there for one page load unlike $_SESSION which will stay until the user leaves.
You can pass the email address through to the form on the second page but then to use it you need to send it again with the second form. You can do that using a hidden input that gets filled in with the first value. e.g.
[syntax=php]
<div>
<input type="hidden" name="email" value="<?php echo htmlentities($_POST['email']); ?>" />
</div>
[/syntax]
Note the htmlentities() there, you need that to prevent XSS attacks
It looks like your using a two step form but trying to use the data from both of them at the last step.
$_POST doesn't work the same way as $_SESSION, it's only there for one page load unlike $_SESSION which will stay until the user leaves.
You can pass the email address through to the form on the second page but then to use it you need to send it again with the second form. You can do that using a hidden input that gets filled in with the first value. e.g.
[syntax=php]
<div>
<input type="hidden" name="email" value="<?php echo htmlentities($_POST['email']); ?>" />
</div>
[/syntax]
Note the htmlentities() there, you need that to prevent XSS attacks