本文整理汇总了PHP中validateForm函数的典型用法代码示例。如果您正苦于以下问题:PHP validateForm函数的具体用法?PHP validateForm怎么用?PHP validateForm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validateForm函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerDiver
function registerDiver()
{
global $db, $first, $last, $phone, $address, $city, $state, $zip, $email;
if (validateForm($first, $last, $email)) {
$SQLstring = "INSERT INTO divers VALUES (NULL, '{$first}', '{$last}', '{$phone}', '{$address}', '{$city}', '{$state}', '{$zip}', '{$email}')";
$result = $db->exec($SQLstring);
if ($result < 1) {
$errors = $db->errorInfo();
$error = $errors[2];
include 'error.php';
exit;
}
} else {
die("<p>You must supply a first name, last name and email address to register! Click your browser's Back button to return to the previous page.</p>");
}
}
示例2: add
public static function add($title, $content)
{
try {
// После окончания процедуры валидации проверяем были ли занесены какие-то сообщения об ошибках. Если да то «бросаем» подготовленный объект исключения.
// Для отлова исключения используем два блока catch: для FormFieldsListException и для всех остальных исключений. Это позволяет задать различные виды действий при возникновении различных типов исключений.
function validateForm($title, $content)
{
$e = new FormFieldsListException();
if (strlen($title) < 5) {
$e[] = 'Слишком короткий заголовок!';
}
if (strlen($content) < 100) {
$e[] = 'Слишком короткое содержание!';
}
if ((bool) $e->current()) {
throw $e;
}
}
try {
validateForm($title, $content);
} catch (FormFieldsListException $error) {
echo '<b>Что-то пошло не так...</b>:<br />';
foreach ($error as $e) {
echo $e . '<br />';
$error::logWriter($e);
}
die('<a href="?ctrl=Articles&action=new">Попробуйте заново, сэр!</a>');
} catch (Exception $error) {
echo 'Not validation error! ' . $error->getMessage();
}
$sth = self::getDbh()->prepare('INSERT INTO ' . static::$table . ' (`title`, `content`) VALUES (:title, :content)');
$sth->bindParam(':title', $title);
$sth->bindParam(':content', $content);
$sth->execute();
} catch (PDOException $e) {
echo $e->getMessage();
}
}
示例3: validateForm
$problems = false;
$error_message = "";
$errorCounter = 0;
function validateForm($form_element, $errorMessage)
{
if (empty($form_element)) {
$problems = true;
$errorCounter++;
return "<li class='error'>{$errorMessage}</li>";
}
return "";
}
//Check if any required fields are empty
$error_message .= validateForm($_POST['project_name'], "Please give your project a name.");
$error_message .= validateForm($_POST['project_description'], "Please give your project a description.");
$error_message .= validateForm($_POST['project_loc'], "Please give your project a location.");
if ($_POST['hidden_loc_lat'] == 0) {
$problems = true;
$errorCounter++;
$error_message .= "<li class='error'>Please provide a valid location.</li>";
}
//Validate date
if (isset($_POST['project_date'])) {
$dateRegExp = '/^((((0[13578])|([13578])|(1[02]))[\\/](([1-9])|([0-2][0-9])|(3[01])))|(((0[469])|([469])|(11))[\\/](([1-9])|([0-2][0-9])|(30)))|((2|02)[\\/](([1-9])|([0-2][0-9]))))[\\/]\\d{4}$|^\\d{4}$/';
if (empty($_POST['project_date'])) {
$problems = true;
$error_message .= '<li class="error">Please enter a date for your project.</li>';
} elseif (!preg_match($dateRegExp, $_POST['project_date'])) {
$problems = true;
$error_message .= '<li class="error">Please enter a valid date for your project (mm/dd/yyyy).</li>';
}
示例4: validateForm
$error_message = "";
$errorCounter = 0;
function validateForm($form_element, $errorMessage)
{
if (empty($form_element)) {
$problems = true;
$errorCounter++;
return "<li class='error'>{$errorMessage}</li>";
}
return "";
}
//Check if any required fields are empty
$error_message .= validateForm($_POST['story_topic'], "Please give your story a topic.");
$error_message .= validateForm($_POST['story_headline'], "Please give your story a headline.");
$error_message .= validateForm($_POST['story_text'], "Please provide a story to go with your headline.");
$error_message .= validateForm($_POST['story_loc'], "Please give your story a location.");
if ($_POST['hidden_loc_lat'] == 0) {
$problems = true;
$errorCounter++;
$error_message .= "<li class='error'>Please provide a valid location.</li>";
}
/*/Validate date
$dateRegExp = '/^((((0[13578])|([13578])|(1[02]))[\/](([1-9])|([0-2][0-9])|(3[01])))|(((0[469])|([469])|(11))[\/](([1-9])|([0-2][0-9])|(30)))|((2|02)[\/](([1-9])|([0-2][0-9]))))[\/]\d{4}$|^\d{4}$/';
if (empty($_POST['story_date'])) {
$problems = true;
$error_message .= '<li>Please enter a date for your story.</li>';
} elseif (!preg_match($dateRegExp, $_POST['story_date'])) {
$problems = true;
$error_message .= '<li>Please enter a valid date for your story (mm/dd/yyyy).</li>';
}*/
/*************************If no problems execute query*****************/
示例5: array
<?php
require_once "lib/common.php";
$defaults = array('name' => '', 'text' => '');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$errors = validateForm();
if (count($errors)) {
if (isset($_POST['name'])) {
$defaults['name'] = $_POST['name'];
}
if (isset($_POST['text'])) {
$defaults['text'] = $_POST['text'];
}
} else {
if (!file_exists(FILES_FOLDER . DIRECTORY_SEPARATOR . $_POST['name'] . "." . $_POST['type'])) {
$fh = fopen(FILES_FOLDER . DIRECTORY_SEPARATOR . $_POST['name'] . "." . $_POST['type'], 'w');
fwrite($fh, $_POST['text']);
fclose($fh);
header("Location: index.php");
exit;
} else {
if (isset($_POST['file'])) {
$fh = fopen(FILES_FOLDER . DIRECTORY_SEPARATOR . $_POST['file'], 'w');
fwrite($fh, $_POST['text']);
fclose($fh);
header("Location: index.php");
exit;
}
}
}
} else {
示例6: validateForm
$errorFields[] = 'email';
}
if (strstr($question, 'http:') != false || strstr($question, 'href=') != false) {
$errorFound = true;
$errorFields[] = 'question';
}
// If any errors were found, then return false. Othwerwise, return true.
if ($errorFound) {
return false;
}
return true;
}
// Check to see if the form has been submitted
if (isset($_POST['submitted'])) {
// Check to see if the form is valid
validateForm();
if (!$errorFound) {
// If the form passes validation, then email the form to the appropriate address.
// Create variables necessary for sending the form information and fill the body of the eamil with the appropriate information.
$body .= "\nThe information provided in this email was submitted from bevello.com.\n";
$body .= "A visitor has a question about the following product:\n\n\n";
$body .= "PRODUCT NAME: " . $product_name . "\n";
$body .= "PRODUCT URL: " . urldecode($product_url) . "\n\n";
$body .= "VISITOR'S NAME: " . $user_name . "\n";
$body .= "EMAIL: " . $email . "\n\n";
$body .= "QUESTION:\n" . $question;
$body .= "\n\n\n";
$body .= "-- End of Message.";
// Create variables necessary for sending the form information and fill the body of the email with the appropriate information.
$toAddress = "bevelloemail@gmail.com";
$bccToAddress = "trimarkwebdesign@gmail.com";
示例7: array_merge
// on a eu un probleme de recuperation des champs on initialise une erreur
$erreur = "Aucune données n a été envoyez ressayez svp!";
}
} else {
// et enfin la dernière erreur possible le format n est pas valide
// le format est aussi verifier coter client avec javascript il y a donc peut de chance d arriver
// dans se cas
$erreur = "Attention les lien videos doivent etres au format embed recommencer!";
}
}
} else {
//ici pas de value dans l input cacher on en est en creation !!
// si on a quelque chose en post on le recupere et crée un tableau contenant $_FILES et $_POST
$valeurTableau = array_merge($_POST, $_FILES);
// maintenant qu on a un seul tableau on l envoie avec celui de regle a la fonction de validation
$validationFormulaire = validateForm($valeurTableau, $regles);
/*la on envoie pour verification*/
// on place les differne éléments du tableau retourne dans des variables
$erreur = $validationFormulaire['erreur'];
$erreurChampsForms = $validationFormulaire['erreursChamps'];
$valeursTableauForm = $validationFormulaire['valeursNettoyees'];
// je reformate mes données apres les avoir verifier afin quelle soit en accord avec
// ce qui est attendu en bdd
$valeursTableauForm['duree-min'] = modifStringToInt($valeursTableauForm['duree-min']);
$valeursTableauForm['sortie'] = modifStringToInt($valeursTableauForm['sortie']);
$valeursTableauForm['titre'] = modifTitreForAjout($valeursTableauForm['titre']);
// la j initialise un tableau contenant les valeurs dites "bonnes" qui me serviront
// pour le pre remplissage des inputs en cas d erreurs
if (count($erreurChampsForms > 0)) {
$_SESSION['erreurInsert'] = creaTabForInput($valeursTableauForm, $erreurChampsForms);
$_SESSION['erreurInsert']['affiche'] = '';
示例8: validateForm
$resultValidateForm;
$result = '';
function validateForm(&$error)
{
global $number, $numbersArray;
$error = [];
if (!validateRequired($number)) {
$error['number'][] = 'Number can not be null.';
}
if (count($numbersArray) > 10) {
$error['count'][] = 'Number must be 10';
}
return empty($error);
}
if (!empty($_POST)) {
$resultValidateForm = validateForm($validationErrors);
if ($resultValidateForm) {
$result .= $number . ' ' . $resultContainer;
$numberCounter--;
} else {
$result = $resultContainer;
}
if ($numberCounter == 0) {
$result = trim($result);
$numbersArray = preg_split('/\\s/', $result);
$result = 'Sorted Array: ';
sort($numbersArray);
foreach ($numbersArray as $value) {
$result .= $value . ' ';
}
$result .= ' ' . 'Min: ' . $numbersArray[0] . ' ' . 'Max: ' . $numbersArray[9];
示例9: array_push
array_push($return_values, "false");
return $return_values;
}
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["event_name"];
$price = $_POST["event_price"];
$description = $_POST["event_description"];
$event_images = $_FILES["event_images"]["name"];
if (validateForm($event, $name, $price, $description)[1] == "true") {
echo "<div class='alert alert-danger'>";
echo "<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>";
echo "<ul>";
$errors_length = count(validateForm($event, $name, $price, $description)[0]);
for ($x = 0; $x < $errors_length; $x++) {
echo "<li>" . validateForm($event, $name, $price, $description)[0][$x] . "</li>";
}
echo "</ul>";
echo "</div>";
} else {
$result_for_event = $event->create_event($name, $description, $price);
if ($result_for_event == true) {
$event_id = $event->get_last_id();
for ($i = 0; $i < count($event_images); $i++) {
$img_tmp_name = addslashes($_FILES['event_images']['tmp_name'][$i]);
$img_name = addslashes($event_images[$i]);
if ($img_tmp_name == "") {
$remove_inserted_event = $event->remove_event($event_id["id"]);
if ($remove_inserted_event == true) {
setcookie("flash_danger", "Please Select Images", time() + 3600);
header("Location: new_event.php");
示例10: array_push
array_push($return_values, "false");
return $return_values;
}
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["event_name"];
$price = $_POST["event_price"];
$description = $_POST["event_description"];
$event_images = $_FILES["event_images"]["name"];
if (validateForm($event, $name, $price, $description, $event_field["name"])[1] == "true") {
echo "<div class='alert alert-danger'>";
echo "<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>";
echo "<ul>";
$errors_length = count(validateForm($event, $name, $price, $description, $event_field["name"])[0]);
for ($x = 0; $x < $errors_length; $x++) {
echo "<li>" . validateForm($event, $name, $price, $description, $event_field["name"])[0][$x] . "</li>";
}
echo "</ul>";
echo "</div>";
} else {
// Updating Event
$result_for_event = $event->update_event($name, $description, $price);
if ($result_for_event == true) {
if (!empty($_FILES["event_images"]["name"][0])) {
for ($i = 0; $i < count($event_images); $i++) {
$img_tmp_name = addslashes($_FILES['event_images']['tmp_name'][$i]);
$img_name = addslashes($event_images[$i]);
$img_tmp_name = file_get_contents($img_tmp_name);
$img_tmp_name = base64_encode($img_tmp_name);
$result_for_event_images = $event->save_event_images($img_tmp_name, $img_name, $event_id);
if ($result_for_event_images == false) {
示例11: validateForm
$result .= '℉';
} else {
if ($op == 2) {
$result .= '℃';
}
}
} else {
$result = false;
}
## return ##
return $result;
}
$errors = [];
$result = false;
if ($_POST) {
$result = validateForm($errors);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/index.css">
</head>
<body>
<div>
<form action="index.php" method="post">
<div>
<label for="num1">Temperature:</label>
<input type="number" id="num1" name="num1" class="<?php
示例12: md5
if (!validatePassword($password2)) {
$errors['password2'][] = "Password need to consist of one of the three of Capital, \nSmall letters, Digits and Special characters";
}
if (validateRequired($password1)) {
if (!validateMatchingPasswords($password1, $password2)) {
$errors['password2'][] = "Password do not match!";
} else {
$password = md5($password1);
}
}
} else {
$errors['password2'][] = 'Password needs to be filled!';
}
}
if ($_POST) {
validateForm($username, $password1, $password2);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Task2</title>
<style type="text/css">
label {
display: block;
}
.error input {
border-color: #ff0000;
}
.error p {
示例13: sanitize
<?php
require_once 'functions.inc';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$myEmail = "jessica.lm15@yahoo.no";
// Sanitize received values
$name = sanitize($name);
$email = sanitize($email);
$message = sanitize($message);
// Validate the form
if (validateForm($name, $email, $message)) {
// Send the email
$success = mail($myEmail, "{$name} ({$email})", $message);
if ($success) {
sendReply(200, "Email sent");
} else {
sendReply(500, "Failed to send email, please try again later");
}
} else {
// The form validation failed
sendReply(400, "Some fields are empty or contain wrong values");
}
示例14: define
//define use of this page to process post action
define('THIS_PAGE', basename($_SERVER['PHP_SELF']));
//include statements
include 'Item.php';
include 'functions.php';
include 'Topping.php';
include 'Order.php';
//object instantiation
$newOrder = new Order();
$items["burrito"] = new Item("Burrito", "Includes awesome sauce!", 7.95, $addOns = ["chips", "rice", "jalapeno"]);
$items["taco"] = new Item("Taco", "Includes cheese and lettuce!", 3.99, $addOns = ["tomato", "cream", "beans"]);
$items["icecream"] = new Item("Fried icecream", "Includes free sprinkles!", 5.0);
$items["milkshake"] = new Item("Milkshake", "Three different flavors", 6.0);
$toppings["tomato"] = new Topping("tomatos", 0.5);
$toppings["cream"] = new Topping("sour cream", 0.99);
$toppings["jalapeno"] = new Topping("jalapeno", 0.5);
$toppings["chips"] = new Topping("potato chips", 3.5);
$toppings["rice"] = new Topping("mexican rice", 0.5);
$toppings["beans"] = new Topping("refried beans", 0.5);
$toppings["syrup"] = new Topping("chocolate syrup", 0.5);
$toppings["double-icecream"] = new Topping("double icecream", 0.5);
/*check for values stored on $_POST and runs the appropiate command*/
if (isset($_POST['next'])) {
validateForm($_POST, $items, $toppings, $newOrder);
} elseif (isset($_POST['place-order'])) {
$newOrder->orderSummary($_POST, $items, $toppings);
} elseif (isset($_POST['reset'])) {
$newOrder->displayOrderForm(' ', $items, $toppings);
} else {
$newOrder->displayOrderForm(' ', $items, $toppings);
}
示例15: count
return $return_values;
}
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$email = $_POST["email"];
$password = $_POST["password"];
$confirm_password = $_POST["confirm_password"];
if (validateForm($user, $email, $password, $confirm_password)[1] == "true") {
echo "<div class='alert alert-danger'>";
echo "<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>";
echo "<ul>";
$errors_length = count(validateForm($user, $email, $password, $confirm_password)[0]);
for ($x = 0; $x < $errors_length; $x++) {
echo "<li>" . validateForm($user, $email, $password, $confirm_password)[0][$x] . "</li>";
}
echo "</ul>";
echo "</div>";
} else {
$pw = str_replace(' ', '', $password);
// file_get_contents() //SQL Injection defence!
$image = addslashes($_FILES['profile_image']['tmp_name']);
$image_name = addslashes($_FILES['profile_image']['name']);
$image = file_get_contents($image);
$image = base64_encode($image);
$current_user_email = $_SESSION["login_user"];
$result = $user->update_user($first_name, $last_name, $email, $pw, $image, $image_name);
if ($result == true) {
$_SESSION["login_user"] = $email;
setcookie("flash_success", "Profile Updated.", time() + 3600);