Re: Multiple forms to mailing list
Posted: Sun Mar 06, 2016 11:37 pm
by tiaz1988
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