Всякий раз, когда я отправляю свою форму, только первый символ отправляется между классом php и скриптом, обрабатывающим отправку. Другие символы как $ _post, так и переменных теряются.
Например, если я отправлю Нигерию в качестве страны в раскрывающемся меню страны, он выберет только N в Нигерии. и методы класса возвращают только первый символ того, что он должен был вернуть.
Это код для скрипта, обрабатывающего отправку формы
<?php
include('../modules/connection.php');
include('../modules/signup.php');
$signUpHandler = new Signup();
$sub = 0;
if (isset($_POST['sign_up']) == 1) {
$sub = 1;
$signed = $signUpHandler->validateSignUp($_POST['fulname'], $_POST['username'], $_POST['email'], $_POST['phone'],
$_POST['address'], $_POST['city'], $_POST['state'], $_POST['country'], $_POST['biz_type'], $_POST['biz_name'],
$_POST['mailer_use'], $_POST['website'], $_POST['password']);
}
?>
<?php if ($sub == 1) {
echo @$signed['regReport'];
} else { ?>
<small class="small alert alert-info">All fields with asterik (*) are required</small><?php } ?>
<br>
<h3>Personal & Contact Detail</h3>
<form method="post" enctype="multipart/form-data" name="signup">
<div class="form-group">
<input name="fulname" class="form-control" type="text" placeholder="Fulname* (Lastname Firstname)" required>
<?php echo @$signed['fulname']; ?>
</div>
<br>
<div class="form-group">
<input name="email" class="form-control" type="email" placeholder="Email*" required>
<?php echo @$signed['email']; ?>
</div>
<br>
<div class="form-group">
<input name="phone" class="form-control" type="tel" placeholder="Phone*" required>
<?php echo @$signed['phone']; ?>
</div>
<br>
<div class="form-group">
<input name="address" class="form-control" type="text" placeholder="Address*" required border="1">
</div>
<br>
<div class="form-group">
<input name="city" class="form-control" type="text" placeholder="City*" required border="1">
</div>
<br>
<div class="form-group">
<input name="state" class="form-control" type="text" placeholder="State*" required border="1">
</div>
<br>
<div class="form-group">
<select name="country" id="country" required="required" class="form-control col-md-7 col-xs-12">
<option value="<?php echo $data['nwcountry']; ?>"selected="selected"><?php echo $data['nwcountry']; ?></option>
<option value="Afghanistan" title="Afghanistan">Afghanistan</option>
<option value="Åland Islands" title="Åland Islands">Åland Islands</option>
<option value="Albania" title="Albania">Albania</option>
<option value="Algeria" title="Algeria">Algeria</option>
<option value="American Samoa" title="American Samoa">American Samoa</option>
<option value="Andorra" title="Andorra">Andorra</option>
<option value="Angola" title="Angola">Angola</option>
<option value="Anguilla" title="Anguilla">Anguilla</option>
<option value="Antarctica" title="Antarctica">Antarctica</option>
<option value="Antigua and Barbuda" title="Antigua and Barbuda">Antigua and Barbuda</option>
<option value="Argentina" title="Argentina">Argentina</option>
<option value="Armenia" title="Armenia">Armenia</option>
<option value="Aruba" title="Aruba">Aruba</option>
<option value="Australia" title="Australia">Australia</option>
<option value="Austria" title="Austria">Austria</option>
<option value="Azerbaijan" title="Azerbaijan">Azerbaijan</option>
<option value="Bahamas" title="Bahamas">Bahamas</option>
<option value="Bahrain" title="Bahrain">Bahrain</option>
<option value="Bangladesh" title="Bangladesh">Bangladesh</option>
<option value="Barbados" title="Barbados">Barbados</option>
<option value="Belarus" title="Belarus">Belarus</option>
<option value="Belgium" title="Belgium">Belgium</option>
<option value="Belize" title="Belize">Belize</option>
<option value="Benin" title="Benin">Benin</option>
<option value="Bermuda" title="Bermuda">Bermuda</option>
<option value="Bhutan" title="Bhutan">Bhutan</option>
<option value="Bolivia, Plurinational State of" title="Bolivia, Plurinational State of">Bolivia,
Plurinational State of
</option>
<option value="Bonaire, Sint Eustatius and Saba" title="Bonaire, Sint Eustatius and Saba">Bonaire, Sint
Eustatius and Saba
</option>
<option value="Bosnia and Herzegovina" title="Bosnia and Herzegovina">Bosnia and Herzegovina</option>
<option value="Botswana" title="Botswana">Botswana</option>
<option value="Bouvet Island" title="Bouvet Island">Bouvet Island</option>
<option value="Brazil" title="Brazil">Brazil</option>
<option value="British Indian Ocean Territory" title="British Indian Ocean Territory">British Indian Ocean
Territory
</option>
<option value="Brunei Darussalam" title="Brunei Darussalam">Brunei Darussalam</option>
<option value="Bulgaria" title="Bulgaria">Bulgaria</option>
<option value="Martinique" title="Martinique">Martinique</option>
<option value="Mauritania" title="Mauritania">Mauritania</option>
<option value="Mauritius" title="Mauritius">Mauritius</option>
<option value="Mayotte" title="Mayotte">Mayotte</option>
<option value="Mexico" title="Mexico">Mexico</option>
<option value="Micronesia, Federated States of" title="Micronesia, Federated States of">Micronesia,
Federated States of
</option>
<option value="Moldova, Republic of" title="Moldova, Republic of">Moldova, Republic of</option>
<option value="Monaco" title="Monaco">Monaco</option>
<option value="Mongolia" title="Mongolia">Mongolia</option>
<option value="Montenegro" title="Montenegro">Montenegro</option>
<option value="Montserrat" title="Montserrat">Montserrat</option>
<option value="Morocco" title="Morocco">Morocco</option>
<option value="Mozambique" title="Mozambique">Mozambique</option>
<option value="Myanmar" title="Myanmar">Myanmar</option>
<option value="Namibia" title="Namibia">Namibia</option>
<option value="Nauru" title="Nauru">Nauru</option>
<option value="Nepal" title="Nepal">Nepal</option>
<option value="Netherlands" title="Netherlands">Netherlands</option>
<option value="New Caledonia" title="New Caledonia">New Caledonia</option>
<option value="New Zealand" title="New Zealand">New Zealand</option>
<option value="Nicaragua" title="Nicaragua">Nicaragua</option>
<option value="Niger" title="Niger">Niger</option>
<option value="Nigeria" title="Nigeria" selected="selected">Nigeria</option>
<option value="Niue" title="Niue">Niue</option>
<option value="Norfolk Island" title="Norfolk Island">Norfolk Island</option>
<option value="Northern Mariana Islands" title="Northern Mariana Islands">Northern Mariana Islands</option>
<option value="Norway" title="Norway">Norway</option>
<option value="Oman" title="Oman">Oman</option>
<option value="Pakistan" title="Pakistan">Pakistan</option>
<option value="Palau" title="Palau">Palau</option>
<option value="Palestinian Territory, Occupied" title="Palestinian Territory, Occupied">Palestinian
Territory, Occupied
</option>
<option value="Panama" title="Panama">Panama</option>
<option value="Papua New Guinea" title="Papua New Guinea">Papua New Guinea</option>
<option value="Paraguay" title="Paraguay">Paraguay</option>
<option value="Peru" title="Peru">Peru</option>
<option value="Philippines" title="Philippines">Philippines</option>
<option value="Pitcairn" title="Pitcairn">Pitcairn</option>
<option value="Poland" title="Poland">Poland</option>
<option value="Portugal" title="Portugal">Portugal</option>
<option value="Puerto Rico" title="Puerto Rico">Puerto Rico</option>
<option value="Qatar" title="Qatar">Qatar</option>
<option value="Réunion" title="Réunion">Réunion</option>
<option value="Romania" title="Romania">Romania</option>
<option value="Russian Federation" title="Russian Federation">Russian Federation</option>
<option value="Rwanda" title="Rwanda">Rwanda</option>
<option value="Saint Barthélemy" title="Saint Barthélemy">Saint Barthélemy</option>
<option value="Saint Helena, Ascension and Tristan da Cunha"title="Saint Helena, Ascension and Tristan da Cunha">Saint Helena, Ascension and Tristan da Cunha
</option>
<option value="Saint Kitts and Nevis" title="Saint Kitts and Nevis">Saint Kitts and Nevis</option>
<option value="Saint Lucia" title="Saint Lucia">Saint Lucia</option>
<option value="Saint Martin (French part)" title="Saint Martin (French part)">Saint Martin (French part)
</option>
<option value="Saint Pierre and Miquelon" title="Saint Pierre and Miquelon">Saint Pierre and Miquelon
</option>
<option value="Saint Vincent and the Grenadines" title="Saint Vincent and the Grenadines">Saint Vincent and
the Grenadines
</option>
<option value="Samoa" title="Samoa">Samoa</option>
<option value="San Marino" title="San Marino">San Marino</option>
<option value="Sao Tome and Principe" title="Sao Tome and Principe">Sao Tome and Principe</option>
<option value="Saudi Arabia" title="Saudi Arabia">Saudi Arabia</option>
<option value="Senegal" title="Senegal">Senegal</option>
<option value="Serbia" title="Serbia">Serbia</option>
<option value="Seychelles" title="Seychelles">Seychelles</option>
<option value="Sierra Leone" title="Sierra Leone">Sierra Leone</option>
<option value="Singapore" title="Singapore">Singapore</option>
<option value="Sint Maarten (Dutch part)" title="Sint Maarten (Dutch part)">Sint Maarten (Dutch part)
</option>
<option value="Slovakia" title="Slovakia">Slovakia</option>
<option value="Slovenia" title="Slovenia">Slovenia</option>
<option value="Solomon Islands" title="Solomon Islands">Solomon Islands</option>
<option value="Somalia" title="Somalia">Somalia</option>
<option value="South Africa" title="South Africa">South Africa</option>
<option value="South Georgia and the South Sandwich Islands"title="South Georgia and the South Sandwich Islands">South Georgia and the South Sandwich Islands
</option>
<option value="South Sudan" title="South Sudan">South Sudan</option>
<option value="Spain" title="Spain">Spain</option>
<option value="Sri Lanka" title="Sri Lanka">Sri Lanka</option>
<option value="Sudan" title="Sudan">Sudan</option>
<option value="Suriname" title="Suriname">Suriname</option>
<option value="Svalbard and Jan Mayen" title="Svalbard and Jan Mayen">Svalbard and Jan Mayen</option>
<option value="Swaziland" title="Swaziland">Swaziland</option>
<option value="Sweden" title="Sweden">Sweden</option>
<option value="Switzerland" title="Switzerland">Switzerland</option>
<option value="Syrian Arab Republic" title="Syrian Arab Republic">Syrian Arab Republic</option>
<option value="Taiwan, Province of China" title="Taiwan, Province of China">Taiwan, Province of China
</option>
<option value="Tajikistan" title="Tajikistan">Tajikistan</option>
<option value="Tanzania, United Republic of" title="Tanzania, United Republic of">Tanzania, United Republic
of
</option>
<option value="Thailand" title="Thailand">Thailand</option>
<option value="Timor-Leste" title="Timor-Leste">Timor-Leste</option>
<option value="Togo" title="Togo">Togo</option>
<option value="Tokelau" title="Tokelau">Tokelau</option>
<option value="Tonga" title="Tonga">Tonga</option>
<option value="Trinidad and Tobago" title="Trinidad and Tobago">Trinidad and Tobago</option>
<option value="Tunisia" title="Tunisia">Tunisia</option>
<option value="Turkey" title="Turkey">Turkey</option>
<option value="Turkmenistan" title="Turkmenistan">Turkmenistan</option>
<option value="Turks and Caicos Islands" title="Turks and Caicos Islands">Turks and Caicos Islands</option>
<option value="Tuvalu" title="Tuvalu">Tuvalu</option>
<option value="Uganda" title="Uganda">Uganda</option>
<option value="Ukraine" title="Ukraine">Ukraine</option>
<option value="United Arab Emirates" title="United Arab Emirates">United Arab Emirates</option>
<option value="United Kingdom" title="United Kingdom">United Kingdom</option>
<option value="United States" title="United States">United States</option>
<option value="United States Minor Outlying Islands" title="United States Minor Outlying Islands">United
States Minor Outlying Islands
</option>
<option value="Uruguay" title="Uruguay">Uruguay</option>
<option value="Uzbekistan" title="Uzbekistan">Uzbekistan</option>
<option value="Vanuatu" title="Vanuatu">Vanuatu</option>
<option value="Venezuela, Bolivarian Republic of" title="Venezuela, Bolivarian Republic of">Venezuela,
Bolivarian Republic of
</option>
<option value="Viet Nam" title="Viet Nam">Viet Nam</option>
<option value="Virgin Islands, British" title="Virgin Islands, British">Virgin Islands, British</option>
<option value="Virgin Islands, U.S." title="Virgin Islands, U.S.">Virgin Islands, U.S.</option>
<option value="Wallis and Futuna" title="Wallis and Futuna">Wallis and Futuna</option>
<option value="Western Sahara" title="Western Sahara">Western Sahara</option>
<option value="Yemen" title="Yemen">Yemen</option>
<option value="Zambia" title="Zambia">Zambia</option>
<option value="Zimbabwe" title="Zimbabwe">Zimbabwe</option>
</select>
</div>
<hr>
<h4>Login Details</h4>
<div class="form-group">
<input name="username" class="form-control" type="text" placeholder="Username*" required border="1" max="16"min="6"><?php if ($sub == 1) {
echo @$signed['username'];
} else { ?>
<small class="small text-info">6-16 characters of upper, lower alphabets & numbers or combinations
</small><?php } ?>
</div>
<div class="form-group">
<input name="password" class="form-control" type="password" placeholder="Password*" required border="1">
</div>
<hr>
<h4>Business Detail</h4>
<div class="form-group">
<input name="biz_name" class="form-control" type="text" placeholder="Business Name*" required border="1">
</div>
<br>
<div class="form-group">
<input name="biz_type" class="form-control" type="text" placeholder="Business Type*" required border="1">
</div>
<br>
<div class="form-group">
<select name="mailer_use" class="form-control">
<option selected value="">What do you need MBC MailBlast for?</option>
<option value="Send Newsletter">Send Newsletter</option>
<option value="Market Products/Services">Market Products/Services</option>
<option value="Send Trasactional Emails">Send Transactional emails</option>
<option value="Send Routine Emails">Send Routine/Reminders</option>
</select>
</div>
<br>
<div class="form-group">
<input name="website" class="form-control" type="url" placeholder="Business Website (Ex. http://website.com)"border="1"><?php echo @$signed['website']; ?>
</div>
<br>
<div class="form-group">
<button class="btn btn-block btn-success" type="submit" name="sign_up" value="sign up"><i
class="fa fa-login"></i> Sign Up
</button>
</div>
</form>
Ниже приведен скрипт класса PHP в другом файле
<?php
class Signup extends Connection
{
private $fulname, $email, $phone, $address, $city, $state, $country, $bizType, $bizName, $mailerUse, $biz_website, $username, $password, $con;
private $err = array();
public function validateSignUp(
$fulname,
$username,
$email,
$phone,
$address,
$city,
$state,
$country,
$bizType,
$bizName,
$mailerUse,
$biz_website,
$password
) {
$this->con = Connection::connect();
$this->fulname = mysqli_real_escape_string($this->con, trim(stripslashes(strip_tags(ucfirst($fulname)))));
$this->email = mysqli_real_escape_string($this->con, trim(stripslashes(strip_tags($email))));
$this->username = mysqli_real_escape_string($this->con, trim(stripslashes(strip_tags($username))));
$this->phone = mysqli_real_escape_string($this->con, trim(stripslashes(strip_tags($phone))));
$this->address = mysqli_real_escape_string($this->con, trim(stripslashes(strip_tags(ucfirst($address)))));
$this->city = mysqli_real_escape_string($this->con, trim(stripslashes(strip_tags(ucfirst($city)))));
$this->state = mysqli_real_escape_string($this->con, trim(stripslashes(strip_tags(ucfirst($state)))));
$this->country = mysqli_real_escape_string($this->con, trim(stripslashes(strip_tags(ucfirst($country)))));
$this->bizType = mysqli_real_escape_string($this->con, trim(stripslashes(strip_tags(ucfirst($bizType)))));
$this->bizName = mysqli_real_escape_string($this->con, trim(stripslashes(strip_tags(ucfirst($bizName)))));
$this->mailerUse = mysqli_real_escape_string($this->con, trim(stripslashes(strip_tags($mailerUse))));
$this->biz_website = mysqli_real_escape_string($this->con,
trim(stripslashes(strip_tags(strtolower($biz_website)))));
$this->password = hash("SHA512", $password);
$this->err['count'] = 0;
if (!preg_match("/^[A-Za-z\s.\-]+$/", $this->fulname)) {
$this->err['fulname'] = '<p class="small alert alert-danger">Name contains invalid characters, please check entry again!</p>';
$this->err['count']++;
}
if (!filter_var($this->email, FILTER_VALIDATE_EMAIL)) {
$this->err['email'] = '<p class="alert alert-danger small">Invalid Email address please, verify!</p>';
$this->err['count']++;
}
if (!ctype_digit($this->phone)) {
$this->err['phone'] = '<p class="alert alert-danger small">Invalid phone number supplied! Only digits are accepted</p>';
$this->err['count']++;
}
if (strlen($this->phone) != 11 && $this->country == 'Nigeria') {
$this->err['phone'] = '<p class="alert alert-danger small">Phone number for Nigerian subscriber must be 11 digits!</p>';
$this->err['count']++;
}
if (!filter_var($this->biz_website, FILTER_VALIDATE_URL) && $this->biz_website != "") {
$this->err['website'] = '<p class="alert alert-danger small">Invalid website address submitted! Please, enter a valid website address example http://website.com</p>';
$this->err['count']++;
}
if (!preg_match("/^[A-Za-z]||[A-Za-z][0-9]$/", $this->username)) {
$this->err['username'] = '<p class="alert alert-danger small">Username can only have Uppercase, lowercase, digits or a mixture!</p>';
$this->err['count']++;
}
if (strlen($this->username) < 6 || strlen($this->username) > 16) {
$this->err['username'] = '<p class="alert alert-danger small">Username should have between 6 to 16 characters</p>';
$this->err['count']++;
}
if ($this->err['count'] == 0) {
$this->err['regReport'] = $this->regUser();
return $this->err['regReport'];
} else {
$this->err['regReport'] = '<div class="alert alert-danger">One or more field submitted contains invalid data. Correct and re-submit to continue</div>';
return $this->err;
}
}
private function regUser()
{
$dateReg = date("Y-m-d H:i:s");
$regUser = mysqli_query($this->con,
"INSERT INTO `mailer-account`(`email`,`username`,`password`,`phone`,`address`,`city`,`state`,`country`,`business_name`,`business_type`,`mailer-use`,`business_website`,`date_reg`) VALUES('$this->email','$this->username','$this->password','$this->phone','$this->address','$this->city','$this->state','$this->country','$this->bizName','$this->bizType','$this->mailerUse','$this->biz_website','$dateReg')");
if (mysqli_affected_rows($this->con) == 1) {
header("Location:../confirmation?suc=" . base64_encode("Registration Successful! A confirmation email has been sent to $this->email. Check email to activate your account!"));
} else {
return '<div class="alert alert-danger">Unable to complete registration at the moment! Err: SGN79</div>';
}
}
}
?>
После опробования других решений, найденных через онлайн-форумы и статьи. Позже я нашел решение проблемы.
if(isset($_POST['sign_up'])==1){
$signUpHandler = new Signup($_POST);
$sub=1;
$signed = $signUpHandler->validateSignUp();
}
Класс изменился на:
<?php
class Signup extends Connection{
private $_data = array(), $_con;
private $_err = array();
//Class constructor for Signing up
public function __construct($data = array()){
$this->_con = Connection::connect();
$this->_data['fulname'] = mysqli_real_escape_string($this->_con, trim(stripslashes(strip_tags(ucfirst($data['fulname'])))));
$this->_data['email'] = mysqli_real_escape_string($this->_con, trim(stripslashes(strip_tags($data['email']))));
$this->_data['username'] = mysqli_real_escape_string($this->_con, trim(stripslashes(strip_tags($data['username']))));
$this->_data['phone'] = mysqli_real_escape_string($this->_con, trim(stripslashes(strip_tags($data['phone']))));
$this->_data['address'] = mysqli_real_escape_string($this->_con, trim(stripslashes(strip_tags(ucfirst($data['address'])))));
$this->_data['city'] = mysqli_real_escape_string($this->_con, trim(stripslashes(strip_tags(ucfirst($data['city'])))));
$this->_data['state'] = mysqli_real_escape_string($this->_con, trim(stripslashes(strip_tags(ucfirst($data['state'])))));
$this->_data['country'] = mysqli_real_escape_string($this->_con, trim(stripslashes(strip_tags(ucfirst($data['country'])))));
$this->_data['bizType'] = mysqli_real_escape_string($this->_con, trim(stripslashes(strip_tags(ucfirst($data['biz_type'])))));
$this->_data['bizName'] = mysqli_real_escape_string($this->_con, trim(stripslashes(strip_tags(ucfirst($data['biz_name'])))));
$this->_data['mailerUse'] = mysqli_real_escape_string($this->_con, trim(stripslashes(strip_tags($data['mailer_use']))));
$this->_data['biz_website'] = mysqli_real_escape_string($this->_con, trim(stripslashes(strip_tags(strtolower($data['website'])))));
$this->_data['password'] = hash("SHA512",$data['password']);
}
//Validate User details
public function validateSignUp(){
$this->_err['count']=0;
if(!preg_match("/^[A-Za-z\s.\-]+$/",$this->_data['fulname'])){
$this->_err['fulname'] = '<p class="small alert alert-danger">Name contains invalid characters, please check entry again!</p>';
$this->_err['count']++;
}
if(!filter_var($this->_data['email'], FILTER_VALIDATE_EMAIL)){
$this->_err['email']='<p class="alert alert-danger small">Invalid Email address please, verify!</p>';
$this->_err['count']++;
}
if(!ctype_digit($this->_data['phone'])){
$this->_err['phone']='<p class="alert alert-danger small">Invalid phone number supplied! Only digits are accepted</p>';
$this->_err['count']++;
}
if(strlen($this->_data['phone'])!=11 && $this->_data['country']=='Nigeria'){
$this->_err['phone']='<p class="alert alert-danger small">Phone number for Nigerian subscriber must be 11 digits!</p>';
$this->_err['count']++;
}
if(!filter_var($this->_data['biz_website'],FILTER_VALIDATE_URL) && $this->_data['biz_website']!=""){
$this->_err['website']='<p class="alert alert-danger small">Invalid website address submitted! Please, enter a valid website address example http://website.com</p>';
$this->_err['count']++;
}
if(!preg_match("/^[A-Za-z]||[A-Za-z][0-9]$/",$this->_data['username'])){
$this->_err['username']='<p class="alert alert-danger small">Username can only have Uppercase, lowercase, digits or a mixture!</p>';
$this->_err['count']++;
}
if(strlen($this->_data['username'])<6 || strlen($this->_data['username'])>16){
$this->_err['username']='<p class="alert alert-danger small">Username should have between 6 to 16 characters</p>';
$this->_err['count']++;
}
if($this->_err['count']==0){
$this->_err['regReport'] = $this->regUser();
return $this->_err;
}else{
$this->_err['regReport'] = '<div class="alert alert-danger">One or more field submitted contains invalid data. Correct and re-submit to continue</div>';
return $this->_err;
}
}
private function regUser(){
$dateReg = date("Y-m-d H:i:s");
$regUser = mysqli_query($this->_con, "INSERT INTO `mailer-account`(`email`,`username`,`password`,`phone`,`address`,`city`,`state`,`country`,`business_name`,`business_type`,`mailer_use`,`business_website`,`date_reg`) VALUES('{$this->_data['email']}','{$this->_data['username']}','{$this->_data['password']}','{$this->_data['phone']}','{$this->_data['address']}','{$this->_data['city']}','{$this->_data['state']}','{$this->_data['country']}','{$this->_data['bizName']}','{$this->_data['bizType']}','{$this->_data['mailerUse']}','{$this->_data['biz_website']}','$dateReg')");
if(mysqli_affected_rows($this->_con)==1){
header("Location:../confirmation?suc=".base64_encode("Registration Successful! A confirmation email has been sent to ".$this->_data['email'].". Check email to activate your account!"));
}else{
return '<div class="alert alert-danger">Unable to complete registration at the moment! Err: SGN84</div>';
}
}
}
?>
Других решений пока нет …