public function validate() { // Cerca il token if (isset($this->form_data[self::TOKEN_ID])) { // Trova la sessione $av_token = substr($this->form_data[self::TOKEN_ID], 0, 40); // 40 caratteri massimi if (isset($_SESSION["av_" . $av_token])) { // Prende le regole $rules = $_SESSION["av_" . $av_token]; // Valida if ($this->computeToken($this->form_id, $rules) == $av_token) { // Tutto a posto // Comincia la validazione dei campi $errors = validateFields($this->form_data, $rules); // validation-2.3.3.php if (empty($errors)) { return true; } else { $this->last_error = join("<br/>", $errors); return false; } } else { $this->last_error = "Il token sembra provenire da un'altro form."; } } else { $this->last_error = "Sessione scaduta. Riprova."; } } else { $this->last_error = "Token mancante."; } }
function validate() { $rules = array(); // stores the validation rules // standard form fields $rules[] = "required,userName,This field is required."; $rules[] = "required,userLastName,This field is required."; //$rules[] = "required,email,Please enter your email address."; //$rules[] = "valid_email,email,Please enter a valid email address."; //$rules[] = "is_alpha,userName,Please only enter letters (a-Z) in this field."; $rules[] = "is_alpha,userName,User name alphanumeric field."; $rules[] = "required,password,Please enter a password."; $rules[] = "same_as,password,rePassword,Please ensure the passwords you enter are the same."; $rules[] = "required,agreement,You didnt agree with the conditions of the application."; $errors = validateFields($_POST, $rules); return $errors; // print_r($errors); }
function actionSendMail() { $errorMsg = array("send_error" => "Сервена помилка при запиті: '", "required1" => "Будь-ласка вкажіть ", "required2" => " ", "valid_email" => "Будь-ласка вкажіть email (формат: name@domain.com)", "valid_phone" => "Будь-ласка вкажіть телефон у вірному форматі (формат 0990504455)", "success" => 'Ваш запит успішно оброблений. Ми з вами з\'єднаємось'); //sleep(5000); $responseArr = array(); $validationErrors = array(); $validated = validateFields($validationErrors, $errorMsg); //$validated = true; /* * * if (isset($_REQUEST["name"]) && trim($_REQUEST["name"]!='') && isset($_REQUEST["email"])&& trim($_REQUEST["email"]!='') && isset($_REQUEST["phone"]) && trim($_REQUEST["phone"]!='') && isset($_REQUEST["message"]) && trim($_REQUEST['message'])!='') */ if ($validated) { $name = $_REQUEST["name"]; //$reply_to_email = $_REQUEST["email"]; $reply_to_email = '*****@*****.**'; //$_REQUEST['ajax_request'] = 'on'; $auth_email = '*****@*****.**'; //email that pass auth $phone = $_REQUEST["phone"]; //$message = $_REQUEST["message"]; //var_dump($_REQUEST); //sleep(5); $mail = new PHPMailer(true); // $mail->SMTPDebug = 2; $mail->IsSMTP(); $mail->Host = "localhost"; // $mail->Host = "smtp.gmail.com"; // $mail->Port = Yii::app()->params->smtp_port; // $mail->Port = Yii::app()->params->smtp_port; // $mail->SMTPSecure = "tls";//"ssl"; // $mail->SMTPAuth = true; // $mail->Username = $auth_email; $mail->CharSet = 'UTF-8'; // $mail->Password = '******'; $mail->AddReplyTo($reply_to_email, 'Reply to ' . $name); $mail->Subject = 'Запит від \'' . $name . '\' (' . $phone . ')'; $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; $mail->MsgHTML('<p></p><br/><br/> <p><span style="color:#ccc">Телефон клієнта: </span>' . $phone . '</p>'); $mail->SetFrom($auth_email, $name); $emails = array('*****@*****.**'); //parkovaoselya@ukr.net //adding addresses foreach ($emails as $send_email) { $mail->AddAddress($send_email, ''); } if (isset($_FILES['uploadfile'])) { $validAttachments = array(); foreach ($_FILES['uploadfile']['name'] as $index => $fileName) { $filePath = $_FILES['uploadfile']['tmp_name'][$index]; if (is_uploaded_file($filePath)) { $attachment = new stdClass(); $attachment->fileName = $fileName; $attachment->filePath = $filePath; $validAttachments[] = $attachment; } } foreach ($validAttachments as $attachment) { $mail->AddAttachment($attachment->filePath, $attachment->fileName); } } //$res = true; $send = false; try { $mail->Send(); $send = true; } catch (Exception $ex) { $responseArr['msg'] = $errorMsg['send_error'] . $ex->getMessage(); $responseArr['status'] = 'error'; } if ($send) { $responseArr['msg'] = $errorMsg["success"]; $responseArr['status'] = 'success'; } } else { $responseArr['status'] = 'validation_error'; $responseArr['validation_errors'] = $validationErrors; } if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] === 'on') { echo json_encode($responseArr); } else { //var_dump($responseArr); if ($responseArr['status'] == 'validation_error') { foreach ($responseArr['validation_errors'] as $key => $err) { echo '<p>Помилка вводу: <span style="color:#f46150">' . $err . '</span></p>'; } } else { echo '<p style="color:green">' . $responseArr['msg'] . '</p>'; } ?> <script> function second_passed() { window.location='/'; } setTimeout(second_passed, 1500) ; </script> <?php } }
}); </script> </div> <?php $action = $_POST; if ($action && $_check === TRUE) { $_get_name = $db->select('SELECT name,email FROM trigger.users WHERE name=? OR email=?', $action['username'], $action['email']); // get the username from db $_get_invite = $db->select('SELECT email, userid FROM trigger.invites WHERE code=?', $action['code']); // get the data from db $rules[] = 'length=1-15,username,incorrect username length.'; $rules[] = 'is_alpha,username,incorrect username format. only enter an alphanumeric (0-9 a-Z) string.'; $rules[] = 'length=1-15,password,incorrect password length.'; $rules[] = "reg_exp,^[-\\pL\\pN_]++\$,i,incorrect password format."; $errors = validateFields($action, $rules); foreach ($_get_name as $_value) { if ($_value['name'] === $action['username'] || $_value['email'] === $action['email']) { $errors[] = 'username and email must be unique'; } } if ($_get_invite) { // if data avalaible foreach ($_get_invite as $_value) { $db_email = $_value['email']; $db_userid = $_value['userid']; } } if ($db_email !== $action['email']) { $errors[] = 'something wrong. sure you are use the correct email?'; }
$message = true; $infomessage = MESSAGE_CATEGORY_DELETED . "<br>"; $flag_msg = 'class="msg_success"'; } else { $var_companyid = trim($_POST["cmbCompany"]); $var_departmentid = trim($_POST["cmbDepartment"]); $var_catname = trim($_POST["txtCategoryName"]); $var_parentcatid = $_POST["cmbParentCategory"]; } } elseif ($_POST["postback"] == "U") { $var_catid = $var_id; $var_companyid = trim($_POST["cmbCompany"]); $var_departmentid = trim($_POST["cmbDepartment"]); $var_catname = trim($_POST["txtCategoryName"]); $var_parentcatid = $_POST["cmbParentCategory"]; if (!validateFields()) { $error = true; $errormessage = MESSAGE_REQUIRED_FIELDS_MISSING; } if (isDuplicateCategory($var_parentcatid, $var_catname, $var_departmentid)) { $error = true; $errormessage = MESSAGE_DUPLICATE_CATEGORY . "<br>"; $errormessage .= MESSAGE_RECORD_NOT_UPDATED . "<br>"; } if (categoryInParentRoute($var_catid, $var_parentcatid)) { $error = true; $errormessage = MESSAGE_CATEGORY_CANNOT_BE_MOVED . "<br>"; $errormessage .= MESSAGE_RECORD_NOT_UPDATED . "<br>"; } if (hasEntries($var_parentcatid)) { $error = true;
/** * Process the data from a form when the event is called. * * @param array $context * @return array **/ public function processEventData($context) { // Check whether something should be done at all. if (!in_array('formvalidation', $context['event']->eParamFILTERS)) { return; } // Fetch data for this filter from the form ... $mapping = $_POST['formvalidation']; // ... and check it for completeness. if (!isset($mapping['formname'])) { $context['messages'][] = array('formvalidation', false, 'The name of the form validation ruleset must be given.'); return; } // Load the specified ruleset. $ruleset = $this->fetchRuleset($mapping['formname']); // Continue only if a ruleset was found. $errors = array(); if (is_array($ruleset) && !empty($ruleset)) { // Do the validation using the loaded rules. $errors = validateFields($context['fields'], $ruleset); $result = empty($errors); } else { // Validation impossible and thus failed. $result = false; } // Convert the errors into a XML object. $message = NULL; if (!$result) { $message = new XMLElement('errors'); foreach ($errors as $error) { $message->appendChild(new XMLElement('error', General::sanitize($error))); } } // Return the result. $context['messages'][] = array('formvalidation', $result, $message); }
echo "<p>Only numbers, +, - and space are allowed for Phone Number</p>"; exit; } if (!preg_match($patterns['company'], $fields['company'])) { echo "<p>Only letters and numbers Between 2 and 20 symbols are allowed for Company Name</p>"; exit; } foreach ($fields['lang'] as $value) { if (isset($_POST['lang']) && !preg_match($patterns['name'], $value)) { echo "<p>Only letters Between 2 and 20 symbols are allowed for Language</p>"; exit; } } } $fields = ['fn' => $_POST["first-name"], 'ln' => $_POST["last-name"], 'email' => $_POST["email"], 'tel' => $_POST["tel"], 'gender' => $_POST["gender"], 'bdate' => $_POST["bdate"], 'nationality' => $_POST["nationality"], 'company' => $_POST["company"], 'work-from' => $_POST["work-from"], 'work-to' => $_POST["work-to"], 'pr-lang' => isset($_POST["pr-lang"]) ? $_POST["pr-lang"] : ['-'], 'pr-skill' => isset($_POST["pr-skill"]) ? $_POST["pr-skill"] : ['-'], 'lang' => isset($_POST["lang"]) ? $_POST["lang"] : ['-'], 'comprehension' => isset($_POST["comprehension"]) ? $_POST["comprehension"] : ['-'], 'reading' => isset($_POST["reading"]) ? $_POST["reading"] : ['-'], 'writing' => isset($_POST["writing"]) ? $_POST["writing"] : ['-'], 'driver-license' => isset($_POST["driver-license"]) ? $_POST["driver-license"] : ['no']]; validateFields($fields); ?> <table class="main"> <thead> <tr> <th colspan="2">Personal Information</th> </tr> </thead> <tbody> <tr> <td>First name</td> <td> <?php echo htmlentities($fields['fn']); ?> </td>
$rules[] = "required,location_campus,Location is required"; $rules[] = "if:location_campus=0,required,location_building,Building is required"; // $rules[] = "if:location_campus=1,required,location_room,Room number is required"; $rules[] = "if:location_campus=2,required,location_other,Location cannot be empty"; $rules[] = "if:repeat_freq=1,required,repeat_until_num,Please enter a number of days"; $rules[] = "if:repeat_freq=7,required,repeat_until_num,Please enter a number of weeks"; $rules[] = "if:repeat_freq=30,required,repeat_until_num,Please enter a number of months"; $rules[] = "required,contact_firstname,First name is required"; $rules[] = "letters_only,contact_firstname,First name can only contain letters (a-Z)"; $rules[] = "required,contact_lastname,Last name is required"; $rules[] = "letters_only,contact_lastname,Last name can only contain letters (a-Z)"; $rules[] = "required,contact_phonenumber,Phone number is required"; $rules[] = "length>=10,contact_phonenumber,Phone number must be at least 10 digits long"; $rules[] = "required,contact_email,Email address is required"; $rules[] = "valid_email,contact_email,Email address is invalid"; $errors = validateFields($fields, $rules); if (!empty($errors)) { $result = ''; $result .= '<span class="alertHeader"><span class="fi-alert"></span></span><h2>Submission error!</h2><br> Please correct the following fields: <ul>'; foreach ($errors as $error) { $result .= "<li>{$error}</li>"; } $result .= '</ul>'; } else { // 2.a. Process post values // - - - - - - - - - - - - - - - - - - - - - - - - - // create db query string array $queryString = array(); $queryStringRpt = array();
} } } return !$error; } ?> <!DOCTYPE html> <html> <head> <title>Print Tags</title> <link rel="stylesheet" type="text/css" href="style.css" /> <script type="text/javascript" src="script.js"></script> </head> <body> <?php if ($_POST && validateFields()) { $_SESSION = $_POST; header("location: CVResult.php"); } ?> <form method="post"> <fieldset> <legend>Personal information</legend> <div id="inner-fieldset1-width"> <input type="text" name="fName" required="true" placeholder="First Name"/> <input type="text" name="lName" required="true" placeholder="Last Name"/> <input type="text" name="email" required="true" placeholder="Email"/> <input type="number" name="phoneNumber" required="true" placeholder="Phone number 0..."/> <label for="female">Female</label> <input type="radio" name="gender" value="female" id="female"/> <label for="male">Male</label>
function actionSendMail() { $errorMsg = array("send_error" => "Сервеная ошибка при запросе: '", "required1" => "Пожалуйста, укажите ", "required2" => " ", "valid_email" => "Пожалуйста укажите email (формат: name@domain.com)", "valid_phone" => "Пожалуйста укажите телефон в формате (формат +380990504455)", "success" => 'Message is successfully sent'); //sleep(5000); $responseArr = array(); $validationErrors = array(); //var_dump('request', $_REQUEST); $validated = validateFields($validationErrors, $errorMsg); //$validated = true; if ($validated) { $name = $_REQUEST["name"]; //$reply_to_email = $_REQUEST["email"]; $reply_to_email = '*****@*****.**'; $_REQUEST['ajax_request'] = true; $_REQUEST['message_set'] = true; $auth_email = '*****@*****.**'; //email that pass auth //$phone = $_REQUEST["phone"]; $email = $_REQUEST["email"]; $message = $_REQUEST["question"]; //var_dump($_REQUEST); //sleep(5); $mail = new PHPMailer(true); // $mail->SMTPDebug = 2; $mail->IsSMTP(); $mail->Host = "localhost"; $mail->CharSet = 'UTF-8'; $mail->AddReplyTo($reply_to_email, 'Reply to ' . $name); $mail->Subject = 'Заявка от клиента: \'' . $name . '\' (' . $email . ')'; $mail->AltBody = 'Use email viewer!'; $mail->MsgHTML('<p></p><br/><br/> <span style="color:#eee">Вопрос клиента (опционально):</span> <p>' . $message . ' </span></p> <br> <br> <p>E-mail клиента: <span style="color:#1DB4F7">' . $email . '</span></p> '); $mail->SetFrom($auth_email, $name); $emails = array('*****@*****.**', '*****@*****.**'); //adding addresses foreach ($emails as $send_email) { $mail->AddAddress($send_email, ''); } if (isset($_FILES['uploadfile'])) { $validAttachments = array(); foreach ($_FILES['uploadfile']['name'] as $index => $fileName) { $filePath = $_FILES['uploadfile']['tmp_name'][$index]; if (is_uploaded_file($filePath)) { $attachment = new stdClass(); $attachment->fileName = $fileName; $attachment->filePath = $filePath; $validAttachments[] = $attachment; } } foreach ($validAttachments as $attachment) { $mail->AddAttachment($attachment->filePath, $attachment->fileName); } } //$res = true; $send = false; try { $mail->Send(); $send = true; } catch (Exception $ex) { $responseArr['msg'] = $errorMsg['send_error'] . $ex->getMessage(); $responseArr['status'] = 'error'; } if ($send) { $responseArr['msg'] = $errorMsg["success"]; $responseArr['status'] = 'success'; } } else { $responseArr['status'] = 'validation_error'; $responseArr['validation_errors'] = $validationErrors; } echo json_encode($responseArr); }
<?php require_once 'piute_includes.php'; session_start(); $errors = array(); // Set the errors array to empty, by default $fields = array(); // Stores the field values $rules = array(); // stores the validation rules $rules[] = "required,email,Please enter your email address."; $rules[] = "valid_email,email,That doesn't look like a valid email address."; $rules[] = "required,password,Please enter your password."; $errors = validateFields('login', $_POST, $rules); // var_dump_j("jeff errors", $errors); // exit; // if there were errors, re-populate the form fields if (!empty($errors)) { $fields = $_POST; header("Location: /index.php"); } else { // They have just tried logging in try { $email = $_POST['email']; $password = $_POST['password']; $currentUser = login($email, $password); header("Location: /index.php"); } catch (Exception $e) { // Unsuccessful login //var_dump($e->getMessage()); if ($e->getMessage() == 'no username found') {
require_once 'piute_includes.php'; session_start(); $errors = array(); // Set the errors array to empty, by default $fields = array(); // Stores the field values $rules = array(); // stores the validation rules $rules[] = "required,email,Please enter your email address."; $rules[] = "required,first_name,Please enter your first name."; $rules[] = "required,last_name,Please enter your last name."; $rules[] = "required,password_1,Please enter a password."; $rules[] = "required,password_2,Please re-enter the password."; $rules[] = "valid_email,email,That doesn't look like a valid email address."; $rules[] = "same_as,password_1,password_2,The passwords must be the same."; $errors = validateFields('register', $_POST, $rules); // if there were errors, re-populate the form fields if (!empty($errors)) { $fields = $_POST; header("Location: /register.php"); } else { // Create short variable names $email = $_POST['email']; $firstName = $_POST['first_name']; $lastName = $_POST['last_name']; $password1 = $_POST['password_1']; $password2 = $_POST['password_2']; try { // // email address not valid // if (!valid_email($email)) { // throw new Exception('That is not a valid email address. Please go back and try again.');
$rules[] = "reg_exp,reg_exp_field2,^\\s*(red|orange|yellow|green|blue|indigo|violet|pink|white)\\s*\$,i,Please enter your favourite colour (e.g. \"red\" or \"blue\")"; // Length of field input $rules[] = "length=2,char_length,Please enter a value that is exactly two characters long."; $rules[] = "length=3-5,char_length_range,Please enter a value that is between 3 and 5 characters in length."; $rules[] = "length>5,char_length_greater_than,Please enter a value that is over 5 characters long."; $rules[] = "length>=5,char_length_greater_than_or_equal,Please enter a value that is at least 5 characters long."; $rules[] = "length<5,char_length_less_than,Please enter a value that is less than 5 characters long."; $rules[] = "length<=5,char_length_less_than_or_equal,Please enter a value that is less than or equal to 5 characters."; // password fields $rules[] = "required,password,Please enter a password."; $rules[] = "same_as,password,password_2,Please ensure the passwords you enter are the same."; // conditional (if-else) fields $rules[] = "required,gender,Please enter your gender."; $rules[] = "if:gender=male,required,male_question,Please enter the name of your favourite Care Bear."; $rules[] = "if:gender=female,required,female_question,Please indicate what max weight you can bench."; $errors = validateFields($_POST, $rules); // if there were errors, re-populate the form fields if (!empty($errors)) { $fields = $_POST; } else { $message = "All fields have been validated successfully!"; // here you would either email the form contents to someone or store it in a database. // To redirect to a "thankyou" page, you'd just do this: // header("Location: thanks.php"); } } // don't worry about these. This is just for illustration purposes: it sets a DEFAULT value to some // fields, which is overwritten when the user fills it in if (!isset($fields["custom_alpha_field1"])) { $fields["custom_alpha_field1"] = "BCD-AEI"; }