当前位置: 首页>>代码示例>>PHP>>正文


PHP Web::validate方法代码示例

本文整理汇总了PHP中Web::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Web::validate方法的具体用法?PHP Web::validate怎么用?PHP Web::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Web的用法示例。


在下文中一共展示了Web::validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: useredit_POST

/**
 * Handle User Edit form submission
 *
 * @param <type> $w
 */
function useredit_POST(Web &$w)
{
    $w->pathMatch("id");
    $errors = $w->validate(array(array("login", ".+", "Login is mandatory")));
    if ($_REQUEST['password'] && $_REQUEST['password'] != $_REQUEST['password2']) {
        $error[] = "Passwords don't match";
    }
    $user = $w->Auth->getObject("User", $w->ctx('id'));
    if (!$user) {
        $errors[] = "User does not exist";
    }
    if (sizeof($errors) != 0) {
        $w->error(implode("<br/>\n", $errors), "/admin/useredit/" . $w->ctx("id"));
    }
    $user->login = $_REQUEST['login'];
    $user->fill($_REQUEST);
    if ($_REQUEST['password']) {
        $user->setPassword($_REQUEST['password']);
    } else {
        $user->password = null;
    }
    $user->is_admin = isset($_REQUEST['is_admin']) ? 1 : 0;
    $user->is_active = isset($_REQUEST['is_active']) ? 1 : 0;
    $user->update();
    $contact = $user->getContact();
    if ($contact) {
        $contact->fill($_REQUEST);
        $contact->private_to_user_id = null;
        $contact->update();
    }
    $w->callHook("admin", "account_changed", $user);
    $w->msg("User " . $user->login . " updated.", "/admin/users");
}
开发者ID:itillawarra,项目名称:cmfive,代码行数:38,代码来源:useredit.php

示例2: useradd_POST

/**
 * Handle User Edit form submission
 *
 * @param <type> $w
 */
function useradd_POST(Web &$w)
{
    $errors = $w->validate(array(array("login", ".+", "Login is mandatory"), array("password", ".+", "Password is mandatory"), array("password2", ".+", "Password2 is mandatory")));
    if ($_REQUEST['password2'] != $_REQUEST['password']) {
        $errors[] = "Passwords don't match";
    }
    if (sizeof($errors) != 0) {
        $w->error(implode("<br/>\n", $errors), "/admin/useradd");
    }
    // first saving basic contact info
    $contact = new Contact($w);
    $contact->fill($_REQUEST);
    $contact->dt_created = time();
    $contact->private_to_user_id = null;
    $contact->insert();
    // now saving the user
    $user = new User($w);
    $user->login = $_REQUEST['login'];
    $user->setPassword($_REQUEST['password']);
    $user->is_active = !empty($_REQUEST['is_active']) ? $_REQUEST['is_active'] : 0;
    $user->is_admin = !empty($_REQUEST['is_admin']) ? $_REQUEST['is_admin'] : 0;
    $user->is_group = 0;
    $user->dt_created = time();
    $user->contact_id = $contact->id;
    $user->insert();
    $w->ctx("user", $user);
    // now saving the roles
    $roles = $w->Auth->getAllRoles();
    foreach ($roles as $r) {
        if (!empty($_REQUEST["check_" . $r])) {
            if ($_REQUEST["check_" . $r] == 1) {
                $user->addRole($r);
            }
        }
    }
    $w->callHook("admin", "account_changed", $user);
    $w->msg("User " . $user->login . " added", "/admin/users");
}
开发者ID:itillawarra,项目名称:cmfive,代码行数:43,代码来源:useradd.php

示例3: profile_POST

function profile_POST(Web &$w)
{
    $w->pathMatch("id");
    $errors = $w->validate(array(array("homephone", "^[0-9+\\- ]*\$", "Not a valid home phone number"), array("workphone", "^[0-9+\\- ]*\$", "Not a valid work phone number"), array("mobile", "^[0-9+\\- ]*\$", "Not a valid  mobile phone number"), array("priv_mobile", "^[0-9+\\- ]*\$", "Not a valid  mobile phone number"), array("fax", "^[0-9+\\- ]*\$", "Not a valid fax number")));
    if ($_REQUEST['password'] && $_REQUEST['password'] != $_REQUEST['password2']) {
        $errors[] = "Passwords don't match";
    }
    $user = $w->Auth->user();
    if (!$user) {
        $errors[] = "Not Logged In";
    }
    if (sizeof($errors) != 0) {
        $w->error(implode("<br/>\n", $errors), "/auth/profile");
    }
    $user->fill($_REQUEST);
    // Filter out everything except the path so that users cant make redirect urls out of cmfive
    $parse_url = parse_url($user->redirect_url);
    $redirect_url = $parse_url["path"];
    // Menu link doesnt like a leading slash
    if ($redirect_url[0] == "/") {
        $redirect_url = substr($redirect_url, 1);
    }
    $user->redirect_url = $redirect_url;
    if ($_REQUEST['password']) {
        $user->setPassword($_REQUEST['password']);
    } else {
        $user->password = null;
    }
    $user->update();
    $contact = $user->getContact();
    if ($contact) {
        $contact->fill($_REQUEST);
        $contact->private_to_user_id = null;
        $contact->update();
    }
    $w->msg("Profile updated.");
}
开发者ID:itillawarra,项目名称:cmfive,代码行数:37,代码来源:profile.php


注:本文中的Web::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。