本文整理汇总了PHP中validateForm函数的典型用法代码示例。如果您正苦于以下问题:PHP validateForm函数的具体用法?PHP validateForm怎么用?PHP validateForm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validateForm函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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>");
}
}
开发者ID:keeis2coo,项目名称:php-examples,代码行数:16,代码来源:dive-shop-model.php
示例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();
}
}
开发者ID:GonikDaniel,项目名称:php_study_project,代码行数:38,代码来源:AbstractModel.php
示例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>';
}
开发者ID:centaurustech,项目名称:TreeBox,代码行数:31,代码来源:edit_project.php
示例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*****************/
开发者ID:jthefang,项目名称:Maptap,代码行数:31,代码来源:add_story.php
示例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 {
开发者ID:elessarelfstone,项目名称:LoftPhpDZ3,代码行数:31,代码来源:add.php
示例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 = "[email protected]";
$bccToAddress = "[email protected]";
开发者ID:bevello,项目名称:bevello,代码行数:31,代码来源:ask-about-product.php
示例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'] = '';
开发者ID:jfrax023,项目名称:site-video,代码行数:31,代码来源:ajout.php
示例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];
开发者ID:tuty,项目名称:IT-Talents,代码行数:31,代码来源:task_04.php
示例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");
开发者ID:sameerf3,项目名称:Event-Management-System,代码行数:31,代码来源:create_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) {
开发者ID:sameerf3,项目名称:Event-Management-System,代码行数:31,代码来源:update_event.php
示例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
开发者ID:Khdoop,项目名称:Lecture20_Homework_PHPWEB,代码行数:31,代码来源:index.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 {
开发者ID:LakyLak,项目名称:IT_Talents,代码行数:31,代码来源:task2.php
示例13: sanitize
<?php
require_once 'functions.inc';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$myEmail = "[email protected]";
// 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");
}
开发者ID:Jexica,项目名称:my_website_v2,代码行数:24,代码来源:send-mail.php
示例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);
}
开发者ID:NeoAzareth,项目名称:ITC250P2EC,代码行数:31,代码来源:index.php
示例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);
开发者ID:sameerf3,项目名称:Event-Management-System,代码行数:31,代码来源:update_profile.php
示例16: exportUserData
return false;
}
}
return true;
}
function exportUserData($data_arr)
{
$path = 'resource/users.txt';
$mode = "a";
$data = implode("\t", $data_arr);
$data .= "\r\n";
$myfile = file_put_contents($path, $data, FILE_APPEND);
if ($myfile === FALSE) {
return false;
}
}
$isDataValid = validateForm($data_err_arr);
if ($isDataValid) {
$isSaved = true;
$isSaved = exportUserData($data_arr);
if ($isSaved === true) {
header('Location:http://localhost/05_Working_with_users_input/index.php');
} else {
echo "try again!!!";
header('Location:http://localhost/05_Working_with_users_input/register.php');
}
}
}
?>
</body>
</html>
开发者ID:kicata,项目名称:php,代码行数:31,代码来源:01_register.php
示例17: password_hash
$errors['password'][] = 'You must enter the same password twice.';
} else {
$password = password_hash($password, PASSWORD_DEFAULT);
}
}
function correctForm($errors)
{
global $username, $password;
$html = '';
if (empty($errors)) {
$html = "<p>Your username is: {$username}</p> \n\t\t\t\t<p>and your hashed password is: {$password}</p>";
}
return $html;
}
if ($_POST) {
validateForm($errors);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Task 2</title>
<style>
.error {
color: red;
}
.error input {
border: 1px solid red;
开发者ID:pdimanov,项目名称:ITTalents-PHP_and_the_Web,代码行数:31,代码来源:Task2.php
示例18: empty
$errors['password2'][] = 'Password must contain at least 1 non-alphanumeric character.';
} else {
if (!validateIdentical($password1, $password2)) {
$errors['password2'][] = 'Passwords don\'t match.';
}
}
}
}
## return ##
return empty($errors) ? true : false;
}
$errors = [];
$check = false;
$encrypted = '';
if ($_POST) {
$check = validateForm($errors);
$encrypted = password_hash($password1, PASSWORD_DEFAULT);
}
?>
<!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="username">username:</label>
开发者ID:Khdoop,项目名称:Lecture20_Homework_PHPWEB,代码行数:31,代码来源:index.php
示例19: header
header('Pragma: public');
header('Content-Length: ' . (string) strlen($data));
echo $data;
exit(0);
}
ob_start();
include "form.html.inc";
$html = ob_get_contents();
ob_end_clean();
$request = get_magic_quotes_gpc() ? array_map('stripslashes', $_REQUEST) : $_REQUEST;
$validationData['address1'] = array('isRequired', 'type' => 'btcdestination');
$validationData['amount1'] = array('isRequired', 'type' => 'btcamount');
$validationData['address2'] = array('type' => 'btcdestination');
$validationData['amount2'] = array('type' => 'btcamount');
$validationData['address3'] = array('type' => 'btcdestination');
$validationData['amount3'] = array('type' => 'btcamount');
if (isset($request['submit'])) {
$formErrors = validateForm($request, $validationData);
if (count($formErrors) == 0) {
$info = createPaymentRequest($request, $formErrors);
}
if (count($formErrors) == 0) {
$html = preg_replace('/<span class="result">[^<]*/', '<span class="result">' . $info, $html);
// Normally there would be code here to process the form
// and redirect to a thank you page...
// ... but for this example, we just always re-display the form.
}
} else {
$formErrors = array();
}
echo fillInFormValues($html, $request, $formErrors);
开发者ID:soitun,项目名称:paymentrequest,代码行数:31,代码来源:createpaymentrequest.php
示例20: validateForm
}
echo "</td></tr></table>\n";
$lastDate = $evtDate;
}
}
}
} else {
echo $xx['sch_no_results'] . "\n";
}
echo "</div>\n";
}
//control logic
$msg = '';
//init
if (isset($_POST["search"])) {
$msg = validateForm();
}
echo "<p class='error'>{$msg}</p>\n";
if (isset($_POST["search"]) and !$msg) {
searchText();
//search
echo "<div class='scrollBoxSh'>\n";
showMatches();
//show results
echo "</div>\n";
} else {
echo "<div class='scrollBoxAd'>\n\t\t<aside class='aside'>\n{$xx['sch_instructions']}\n</aside>\n\t\t<div class='centerBox'>\n";
searchForm();
//define search
echo "</div>\n</div>\n";
}
开发者ID:krievley,项目名称:schedule,代码行数:31,代码来源:search.php
注:本文中的validateForm函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论