本文整理汇总了PHP中validation::validate_max_lengths方法的典型用法代码示例。如果您正苦于以下问题:PHP validation::validate_max_lengths方法的具体用法?PHP validation::validate_max_lengths怎么用?PHP validation::validate_max_lengths使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类validation
的用法示例。
在下文中一共展示了validation::validate_max_lengths方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate_admin
public static function validate_admin()
{
if (isset($_POST['submit'])) {
$required_fields = array("username", "password");
validation::validate_presentces($required_fields);
$fields_with_max_lengths = array("password" => 30);
validation::validate_max_lengths($fields_with_max_lengths);
return empty(validation::$errors) ? true : false;
} else {
return false;
}
}
示例2: edit_page
/**
* edit page according the passed page id
* @param string $page_id
* update session message
*/
public static function edit_page($page_id)
{
global $dbo;
if (isset($_POST['submit'])) {
// validations
$required_fields = array("menu_name", "position", "visible", "content");
validation::validate_presentces($required_fields);
$fields_with_max_lengths = array("menu_name" => 200, "description" => 500, "content" => 2000);
validation::validate_max_lengths($fields_with_max_lengths);
if (empty(validation::$errors)) {
// process form perform update
$id = $page_id;
$subject_id = (int) $_POST["belong_subject"];
$menu_name = $dbo->mysql_prep($_POST["menu_name"]);
// Escape all strings
$position = (int) $_POST["position"];
$visible = (int) $_POST["visible"];
$home_page = (int) $_POST["home_display"];
$archive = (int) $_POST["archive_display"];
$description = $dbo->mysql_prep($_POST["description"]);
//$content = str_replace(" ", "", );
$content = $dbo->mysql_prep($_POST["content"]);
// perform database query
$query = "UPDATE pages SET ";
$query .= "subject_id = '{$subject_id}', ";
$query .= "menu_name = '{$menu_name}', ";
$query .= "position = {$position}, ";
$query .= "visible = {$visible}, ";
$query .= "home_page = {$home_page}, ";
$query .= "archive = {$archive}, ";
$query .= "description = '{$description}', ";
$query .= "content = '{$content}' ";
$query .= "WHERE id = {$id}";
$query .= " LIMIT 1";
$result = self::find_by_sql($query);
}
if (isset($result) && $dbo->affected_rows($result) >= 0) {
// success
$_SESSION["message"] = "Page Updated.";
utility::redirect_to("manage_content.php?page={$id}");
} else {
// failure
$_SESSION["message"] = "Page update failed.";
}
} else {
// This is probably a GET request
}
}
示例3: create_comment
/**
* Create a comment
* no return value, update $_SESSION message
*/
public static function create_comment()
{
global $dbo;
global $current_page;
if (isset($_POST['submit'])) {
// validations
$required_fields = array("author", "body");
validation::validate_presentces($required_fields);
$fields_with_max_lengths = array("body" => 200);
validation::validate_max_lengths($fields_with_max_lengths);
if (empty(validation::$errors)) {
// process form
$page_id = $current_page['id'];
$created = strftime("%Y-%m-%d %H-%M-%S", time());
// $created = time(); // store time stam or string
$author = $dbo->mysql_prep($_POST["author"]);
$body = $dbo->mysql_prep($_POST["body"]);
// perform database query
$query = "INSERT INTO comments (";
$query .= " page_id, created, author, body";
$query .= ") VALUES (";
$query .= " {$page_id}, '{$created}', '{$author}', '{$body}'";
$query .= ")";
$result = $dbo->query($query);
$dbo->confirm_query($result);
}
if (isset($result) && $dbo->affected_rows($result) >= 0) {
// success
$_SESSION["message"] = "comment created.";
//utility::redirect_to("manage_admins.php");
} else {
// failure
$_SESSION["message"] = "comment creation failed.";
}
} else {
$_SESSION["message"] = "There is some problem.";
// not a post submit
}
}
示例4: edit_subject
/**
* edit subject according to form submit
* @param string $subject_id A field provide by user click edit button
*
*/
public static function edit_subject($subject_id)
{
global $dbo;
if (isset($_POST['submit'])) {
// validations
$required_fields = array("menu_name", "position", "visible");
validation::validate_presentces($required_fields);
$fields_with_max_lengths = array("menu_name" => 30);
validation::validate_max_lengths($fields_with_max_lengths);
if (empty(validation::$errors)) {
// process form perform update
$id = $subject_id;
$menu_name = $dbo->mysql_prep($_POST["menu_name"]);
// Escape all strings
$position = (int) $_POST["position"];
$visible = (int) $_POST["visible"];
// perform database query
$query = "UPDATE subjects SET ";
$query .= "menu_name = '{$menu_name}', ";
$query .= "position = {$position}, ";
$query .= "visible = {$visible} ";
$query .= "WHERE id = {$id}";
$query .= " LIMIT 1";
$result = $dbo->query($query);
}
if (isset($result) && $dbo->affected_rows($result) >= 0) {
// success
$_SESSION["message"] = "Subject Updated.";
utility::redirect_to("manage_content.php");
} else {
// failure
$_SESSION["message"] = "Subject updit failed.";
}
} else {
// This is probably a GET request
}
// end: if(isset($_POST['submit']))
}