本文整理汇总了PHP中GUMP::validation_rules方法的典型用法代码示例。如果您正苦于以下问题:PHP GUMP::validation_rules方法的具体用法?PHP GUMP::validation_rules怎么用?PHP GUMP::validation_rules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GUMP
的用法示例。
在下文中一共展示了GUMP::validation_rules方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: diy_compile
function diy_compile($payload, $storage)
{
global $app;
$result["controller"] = __FUNCTION__;
$result["function"] = substr($app->request()->getPathInfo(), 1);
$result["method"] = $app->request()->getMethod();
$params = loadParameters();
$result->function = substr($app->request()->getPathInfo(), 1);
$result->method = $app->request()->getMethod();
$params = loadParameters();
$srcfile = OAuth2\Request::createFromGlobals()->request["srcfile"];
$srclib = OAuth2\Request::createFromGlobals()->request["srclib"];
$device = OAuth2\Request::createFromGlobals()->request["device"];
$comp = OAuth2\Request::createFromGlobals()->request["comp"];
$filename = OAuth2\Request::createFromGlobals()->request["filename"];
$writedevice = OAuth2\Request::createFromGlobals()->request["writedevice"];
$up = json_decode(base64_decode($payload));
$client_id = $up->client_id;
$diy_error["post"]["device"] = $device;
$post["srcfile"] = $srcfile;
//organisation oauth_devices
$post["device"] = $device;
//organisation oauth_devices
$post["comp"] = $comp;
//organisation oauth_devices
$post["filename"] = $filename;
//organisation oauth_devices
$post["writedevice"] = $writedevice;
//organisation oauth_devices
$gump = new GUMP();
$gump->validation_rules(array('device' => 'required|alpha_numeric', 'filename' => 'required|alpha_numeric', 'comp' => 'required|alpha_numeric', 'writedevice' => 'required|alpha_numeric'));
$gump->filter_rules(array('device' => 'trim|sanitize_string', 'filename' => 'trim|sanitize_string', 'comp' => 'trim|sanitize_string', 'writedevice' => 'trim|sanitize_string'));
$validated = $gump->run($post);
if ($validated === false) {
$result["parse_errors"] = $gump->get_readable_errors(true);
$result["message"] = "[" . $result["method"] . "][" . $result["function"] . "]:" . $gump->get_readable_errors(true);
} else {
try {
$sourceWriteDir = __DIR__ . '/../../../data/sketches/' . $client_id . '/' . $device . '/' . $filename;
if (file_exists($sourceWriteDir)) {
throw new \Exception('Filename ' . $filename . ' for user ' . $client_id . ' and device ' . $device . ' already exists');
}
$stmt2 = $storage->prepare('SELECT * FROM oauth_devices WHERE device = :device');
$stmt2->execute(array('device' => trim($device)));
$row2 = $stmt2->fetch(PDO::FETCH_ASSOC);
if ($row2["organisation"]) {
$org = trim($row2["organisation"]);
}
if ($row2["mode"]) {
$mode = trim($row2["mode"]);
}
if ($row2["status"]) {
$status = trim($row2["status"]);
}
if ($row2["client_id"]) {
$devclient_id = trim($row2["client_id"]);
}
$orgscopeadmin = "no";
$orgscopedevel = "no";
if ($mode == "devel" && $status == "org") {
$userscopes = explode(' ', trim($userscope));
$adminscope = $org . "_admin";
$develscope = $org . "_admin";
// o user aniki sto scope
for ($i = 0; $i <= count($userscopes); $i++) {
if (trim($userscopes[$i]) == $adminscope) {
$orgscopeadmin = "yes";
}
if (trim($userscopes[$i]) == $develscope) {
$orgscopedevel = "yes";
}
}
// einai o owner
if ($devclient_id == $client_id) {
$orgscopeadmin = "yes";
}
}
// einmai o owner
if ($mode == "devel" && $status == "private" && $devclient_id == $client_id) {
$orgscopeadmin = "yes";
}
$result["result"]["sketch1"] = $orgscopeadmin;
if ($orgscopeadmin == "yes" || $orgscopedevel == "yes") {
try {
$stmt2 = $storage->prepare('SELECT * FROM oauth_clients WHERE client_id = :device');
$stmt2->execute(array('device' => trim($device)));
$row2 = $stmt2->fetch(PDO::FETCH_ASSOC);
if ($row2["apiport"]) {
// *************************************** compiler *********************************
// srcfile echeis se base64 ton kodika
// compiler echeis ton compiler pou thelei o user mechri stigmis echoume gcc, ino
// filename to filename pou edosse o user
// o poros compilesketch
// afou kanei compile
// epistrefei
// error ta lathi h noerrors
// binfile to hex file
$compilerserver = diyConfig::read("compiler.host");
$compilerserver .= ":" . diyConfig::read("compiler.port");
$data1 = 'filename=' . $filename;
//.........这里部分代码省略.........
示例2: edit
public function edit()
{
$gump = new GUMP();
$gump->validation_rules(array('id' => 'required|integer|min_len,1', 'user' => 'required|integer', 'enabled' => 'required|integer', 'mins' => 'required', 'hours' => 'required', 'days' => 'required', 'months' => 'required', 'DoW' => 'required'));
$gump->filter_rules(array('id' => 'trim|whole_number'));
$valid_data = $gump->run($_POST);
if ($valid_data === false) {
return new ActionResult($this, '/admin/core/cron_view', 0, 'Failed to edit cron job!<br />Error: <code>Please check you have completed all fields as instructed.</code>', B_T_FAIL);
}
foreach (array('mins', 'hours', 'days', 'months', 'DoW') as $var) {
if ($valid_data[$var] === '*') {
$valid_data[$var] = NULL;
}
}
$update_query = $this->mySQL_w->prepare("UPDATE `core_cron` SET `enable`=?, `mins`=?, `hours`=?, `days`=?, `month`=?, `dow`=?, `user_id`=? WHERE `ID`=?");
if ($update_query === false) {
return new ActionResult($this, '/admin/core/cron_view', 0, 'Failed to edit cron job.<br/>Error: <code>Update query failed</code>', B_T_FAIL);
}
$update_query->bind_param('iiiiiiii', $valid_data['enabled'], $valid_data['mins'], $valid_data['hours'], $valid_data['days'], $valid_data['months'], $valid_data['DoW'], $valid_data['user'], $valid_data['id']);
$update_query->execute();
if ($update_query->affected_rows == 1) {
return new ActionResult($this, '/admin/core/cron_view', 1, 'Succeesfully edited cron job!', B_T_SUCCESS);
} else {
return new ActionResult($this, '/admin/core/cron_view', 1, 'Tried to edit cron job, but there was nothing to change!', B_T_INFO);
}
}
示例3: validate
public static function validate(\RedBeanPHP\OODBBean $bean)
{
$data = $bean->export();
$model = $bean->box() !== null ? $bean->box() : null;
if (!$model) {
throw new ModelValidation_Exception('This bean does not have a model!');
}
$rules = isset($model::$rules) ? $model::$rules : null;
if (!$rules) {
throw new ModelValidation_Exception('This bean does not have any established rules!');
}
$validations = [];
$filters = [];
$labels = [];
$messages = [];
foreach ($rules as $field => $rule) {
if (isset($rule['filter'])) {
$filters[$field] = $rule['filter'];
}
if (isset($rule['label'])) {
$labels[$field] = $rule['label'];
}
if (isset($rule['validation'])) {
$validations[$field] = $rule['validation'];
}
if (isset($rule['message'])) {
$field = isset($rule['label']) ? $rule['label'] : ucwords(str_replace(array('_', '-'), chr(32), $field));
$messages[$field] = $rule['message'];
}
}
$gump = new \GUMP();
if (!empty($filters)) {
$gump->filter_rules($filters);
}
if (!empty($validations)) {
$gump->validation_rules($validations);
}
if (!empty($labels)) {
$gump->set_field_names($labels);
}
$validated_data = $gump->run($data);
if ($validated_data === false) {
return self::default2custom_errors($gump->get_errors_array(), $messages);
} else {
$bean->import($validated_data);
return true;
}
}
示例4: GUMP
/**
*
* Processes the request from the user
* The main engine of the class
*
* @param object $post WP_Post Object
* returns nothing
*
*/
function process_article()
{
require_once CPT_PLUGIN_DIR . 'assets/php/gump/gump.class.php';
$gump = new GUMP();
$_POST = $gump->sanitize($_POST); // You don't have to sanitize, but it's safest to do so.
$gump->validation_rules(array(
'email' => 'required|valid_email',
));
$gump->filter_rules(array(
'email' => 'trim|sanitize_email',
));
$validated_data = $gump->run($_POST);
if($validated_data === false) {
$this->message_type = 'error';
$this->message = $gump->get_readable_errors(true);
} else {
// Get the article data
$this->post = get_post($validated_data['post_id'], OBJECT, 'edit');
//build the html
$email_html = $this->build_html();
// If article is sent
if($this->send_email($validated_data['email']))
{
$this->message_type = 'success';
$this->message = 'The article link has been emailed';
}
else
{
$this->message_type = 'error';
$this->message = 'The article has not been sent. Please try again';
}
}
// Finally send the response to user
$this->response_message();
}
示例5: edit
public function edit()
{
$gump = new GUMP();
$gump->validation_rules(array('id' => 'required|integer|min_len,1', 'ip' => 'required|valid_ipv4', 'length' => 'required|integer', 'reason' => 'required'));
$gump->filter_rules(array('id' => 'trim|whole_number', 'ip' => 'trim', 'length' => 'trim|whole_number', 'reason' => 'trim|sanitize_string'));
$valid_data = $gump->run($_POST);
if ($valid_data === false) {
return new ActionResult($this, '/admin/core/ipblock_view', 0, 'Failed to edit block!<br />Error: <code>Please check you have completed all fields as instructed.</code>', B_T_FAIL);
}
$update_query = $this->mySQL_w->prepare("UPDATE `core_ip` SET `length`=?, `reason`=? WHERE `id`=? AND `ip`=INET_ATON(?)");
if ($update_query === false) {
return new ActionResult($this, '/admin/core/ipblock_view', 0, 'Failed to edit block.<br/>Error: <code>Update query failed</code>', B_T_FAIL);
}
$update_query->bind_param('isis', $valid_data['length'], $valid_data['reason'], $valid_data['id'], $valid_data['ip']);
$update_query->execute();
if ($update_query->affected_rows == 1) {
return new ActionResult($this, '/admin/core/ipblock_view', 1, 'Succeesfully edited block!', B_T_SUCCESS);
} else {
return new ActionResult($this, '/admin/core/ipblock_view', 1, 'Tried to edit block, but there was nothing to change!', B_T_INFO);
}
}
示例6: edit
public function edit()
{
$gump = new GUMP();
$gump->validation_rules(array('id' => 'required|integer|min_len,1', 'name' => 'required', 'value' => 'required'));
$gump->filter_rules(array('id' => 'trim|whole_number', 'name' => 'trim|sanitize_string', 'value' => 'trim', 'desc' => 'trim|sanitize_string'));
$valid_data = $gump->run($_POST);
if ($valid_data === false) {
return new ActionResult($this, '/admin/core/option_edit', 0, 'Failed to edit option!<br />Error: <code>Please check you have completed all fields as instructed.</code>', B_T_FAIL);
}
$update_query = $this->mySQL_w->prepare("UPDATE `core_options` SET `value`=?, `desc`=? WHERE `id`=? AND `name`=?");
if ($update_query === false) {
return new ActionResult($this, '/admin/core/option_view', 0, 'Failed to edit option.<br/>Error: <code>Update query failed</code>', B_T_FAIL);
}
$update_query->bind_param('ssis', $valid_data['value'], $valid_data['desc'], $valid_data['id'], $valid_data['name']);
$update_query->execute();
if ($update_query->affected_rows == 1) {
return new ActionResult($this, '/admin/core/option_view', 1, 'Succeesfully edited option!', B_T_SUCCESS);
} else {
return new ActionResult($this, '/admin/core/option_view', 1, 'Tried to edit option, but there was nothing to change!', B_T_INFO);
}
}
示例7: register_post
public function register_post()
{
$gump = new GUMP();
$form = $gump->sanitize($_POST);
$gump->validation_rules(array("firstname" => "required|valid_name", "lastname" => "required|valid_name", "street" => "required|street_address", "zip" => "required|numeric,min_len=4", "city" => "required", "country" => "required", "email" => "required|valid_email", "password" => "required", "password_verify" => "required"));
$validation = $gump->run($form);
if ($validation === false) {
$errors = $gump->errors();
for ($i = 0; $i < count($errors); $i++) {
$this->form[$errors[$i]["field"]]["error"] = true;
}
} else {
if ($user = (new Login())->createLogin($form["email"], $form["password"], $form["company"], $form["firstname"], $form["lastname"], $form["street"], $form["zip"], $form["city"], $form["country"])) {
$session = new \Base\Session();
$session->set("user_id", $user->getId());
(new Request())->redirect("dashboard");
}
}
$this->assign("error_message", "E-Mail oder Passwort falsch.");
$this->register();
}
示例8: addSub
public function addSub()
{
$gump = new GUMP();
$gump->validation_rules(array('module' => 'required|integer|min_len,1', 'PID' => 'required|integer', 'parent' => 'required|integer'));
$gump->filter_rules(array('module' => 'trim|whole_number', 'PID' => 'trim|whole_number', 'parent' => 'trim|whole_number'));
$valid_data = $gump->run($_POST);
if ($valid_data === false) {
return new ActionResult($this, '/admin/core/menu_add', 0, 'Failed to add menu sub menu item.<br />Error: <code>Please check you have completed all fields as instructed.</code>', B_T_FAIL);
}
$max_query = $this->mySQL_r->query("SELECT MAX(`position`) FROM `core_menu`");
$parent_query = $this->mySQL_r->prepare("SELECT `MID` FROM `core_menu` WHERE `MID`=?");
if (!$parent_query) {
return new ActionResult($this, '/admin/core/menu_add', 0, 'Failed to add sub menu item.<br/>Error: <code>Query to check parent item exists failed</code>', B_T_FAIL);
}
if (!$max_query) {
return new ActionResult($this, '/admin/core/menu_add', 0, 'Failed to add sub menu item.<br/>Error: <code>Failed to get next free position</code>', B_T_FAIL);
}
$parent_query->bind_param('i', $valid_data['parent']);
$parent_query->execute();
$parent_query->store_result();
if ($parent_query->num_rows != 1) {
return new ActionResult($this, '/admin/core/menu_add', 0, 'Failed to add sub menu item.<br/>Error: <code>Failed to check parent exists</code>', B_T_FAIL);
}
$max = $max_query->fetch_row();
$max = $max[0] + 1;
$add_query = $this->mySQL_w->prepare("INSERT INTO `core_menu` (`position`, `parent`, `PID`, `dropdown`, `divider` ) VALUES (?, ?, ?, 0, 0)");
if (!$add_query) {
return new ActionResult($this, '/admin/core/menu_add', 0, 'Failed to add menu.<br/>Error: <code>Insert query failed</code>', B_T_FAIL);
}
$add_query->bind_param('iii', $max, $valid_data['parent'], $valid_data['PID']);
$add_query->execute();
if ($add_query->affected_rows == 1) {
return new ActionResult($this, '/admin/core/menu_edit/' . $valid_data['parent'] . '/?tp=dropdown', 1, 'Succeesfully add sub menu item!', B_T_SUCCESS);
} else {
return new ActionResult($this, '/admin/core/menu_addsub/' . $valid_data['parent'], 0, 'Tried to add sub menu item, but failed!', B_T_FAIL);
}
}
示例9: save
public function save()
{
if (WebApp::post('mysql_r_pass') === '') {
WebApp::post('mysql_r_pass', $this->parent->parent->config->config['mysql']['r']['pass']);
}
if (WebApp::post('mysql_w_pass') === '') {
WebApp::post('mysql_r_pass', $this->parent->parent->config->config['mysql']['w']['pass']);
}
$gump = new GUMP();
$gump->validation_rules(array('core_errors' => 'required|boolean', 'core_maintenance' => 'required|boolean', 'core_debug' => 'required|boolean', 'core_https_a' => 'required|boolean', 'core_https_f' => 'required|boolean', 'core_cdn' => 'required', 'mysql_db' => 'required', 'mysql_r_user' => 'required', 'mysql_r_host' => 'required', 'mysql_r_port' => 'required|integer', 'mysql_w_user' => 'required', 'mysql_w_host' => 'required', 'mysql_w_port' => 'required|integer', 'reCAPTCHA_pub' => 'required|alpha_dash', 'reCAPTCHA_priv' => 'required|alpha_dash'));
$gump->filter_rules(array('core_cdn' => 'trim|urlencode'));
$valid_data = $gump->run($_POST);
if ($valid_data === false) {
return new ActionResult($this, '/admin/core/config_edit', 0, 'Failed to save config!<br />Error: <code>Please check you have completed all fields as instructed.</code>', B_T_FAIL);
}
$configFile = fopen(__LIBDIR__ . '/config.inc.php', 'w');
if (fwrite($configFile, $this->getFile($valid_data))) {
fclose($configFile);
return new ActionResult($this, '/admin/core/config_view', 1, 'Succeesfully saved config!', B_T_SUCCESS);
} else {
fclose($configFile);
return new ActionResult($this, '/admin/core/config_edit', 0, 'Failed to save config!', B_T_SFAIL);
}
}
示例10: activity_form
function activity_form($activity_id = 0)
{
global $mysqli;
global $backend;
if ($activity_id) {
$activity = new Activity($activity_id);
$form_type = 'update';
} else {
$activity = new Activity();
$form_type = 'insert';
}
$html = '';
$fields = array('title' => array('var' => 'title', 'label' => 'Activity Title', 'desc' => 'Required. This is the public title of the activity. You may change this later.', 'type' => 'text', 'std' => $activity->title, 'validate' => 'required', 'filter' => 'trim|sanitize_string', 'param' => 's'), 'folder' => array('var' => 'folder', 'label' => 'Activity folder', 'desc' => 'Required. Name of the folder to create on the ASHP server. Just enter the name of the folder <strong>without any slashes</strong>.', 'type' => 'text', 'std' => $activity->folder, 'validate' => 'required|alpha_dash', 'filter' => 'trim|sanitize_string', 'param' => 's'), 'url' => array('var' => 'url', 'label' => 'Live Activity URL', 'desc' => 'The full URL of the activity, including <strong>http://</strong><br />You can leave blank to default to http://ashpadvantagemedia.com/ActivityFolder.<br /><span class="text-danger">Remember to use <strong>http://www.ashpadvantagemedia.com</strong> instead of <strong>http://www.ashpadvantage.com</strong>.</span>', 'type' => 'text', 'std' => $activity->url, 'validate' => 'valid_url', 'filter' => 'trim|sanitize_string', 'param' => 's'), 'sponsor' => array('var' => 'sponsor', 'label' => 'Activity Sponsor', 'desc' => 'The sponsor of the activity.', 'type' => 'text', 'std' => $activity->sponsor, 'validate' => '', 'filter' => 'trim|sanitize_string', 'param' => 's'), 'type_id' => array('var' => 'type_id', 'label' => 'Activity Type', 'desc' => 'Select the type of activity.', 'type' => 'select', 'options' => $backend->activity_types, 'std' => $activity->type_id, 'validate' => 'required', 'filter' => 'trim|sanitize_string', 'param' => 'i'), 'live_website' => array('var' => 'live_website', 'label' => 'Live Website Template', 'desc' => 'Choose which template to display on the live site..', 'type' => 'select', 'options' => $backend->website_types, 'std' => $activity->live_website, 'validate' => 'required', 'filter' => 'trim|sanitize_string', 'param' => 's'), 'has_live' => array('var' => 'has_live', 'label' => 'Has Live Component', 'desc' => 'Select the live component this activity has.', 'type' => 'radio', 'options' => array('none', 'webcast', 'webinar'), 'std' => $activity->has_live, 'validate' => 'required', 'filter' => 'trim|sanitize_string', 'param' => 's'), 'director_id' => array('var' => 'director_id', 'label' => 'Scientific Project Director', 'desc' => '', 'type' => 'select', 'options' => $backend->directors, 'std' => $activity->director_id, 'validate' => 'required', 'filter' => 'trim|sanitize_string', 'param' => 'i'), 'manager_id' => array('var' => 'manager_id', 'label' => 'Project Manager', 'desc' => '', 'type' => 'select', 'options' => $backend->managers, 'std' => $activity->manager_id, 'validate' => 'required', 'filter' => 'trim|sanitize_string', 'param' => 'i'), 'vendor_id' => array('var' => 'vendor_id', 'label' => 'Web Vendor', 'desc' => '', 'type' => 'select', 'options' => $backend->vendors, 'std' => $activity->vendor_id, 'validate' => 'required', 'filter' => 'trim|sanitize_string', 'param' => 'i'));
if (isset($_POST['submit'])) {
$gump = new GUMP();
foreach ($_POST['form'] as $k => $v) {
//update the std value for form output below
$fields[$k]['std'] = $v;
if (!empty($fields[$k]['validate'])) {
$validate[$k] = $fields[$k]['validate'];
}
if (!empty($fields[$k]['filter'])) {
$filter[$k] = $fields[$k]['filter'];
}
}
$error_text = '';
$gump->validation_rules($validate);
$gump->filter_rules($filter);
$validated_data = $gump->run($_POST['form']);
if ($form_type == 'insert' && activity_folder_exists($validated_data['folder'])) {
$validated_data = false;
$error_text .= 'Folder already exists. Please choose another folder name.<br />';
}
if ($validated_data === false) {
$errors = $gump->get_readable_errors(false);
foreach ($errors as $error) {
$error_text .= $error . '<br />';
}
echo edgimo_error($error_text);
} else {
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit;
}
if ($validated_data['url'] == '') {
$validated_data['url'] = 'http://ashpadvantagemedia.com/' . $validated_data['folder'];
}
if ($form_type == 'update') {
$query = $mysqli->prepare("UPDATE ashp_activities SET title=?, url=?, folder=?, sponsor=?, type_id=?, director_id=?, manager_id=?, vendor_id=?, live_website=?, has_live=? WHERE activity_id=?");
$query->bind_param('ssssiiiiiss', $validated_data['title'], $validated_data['url'], $validated_data['folder'], $validated_data['sponsor'], $validated_data['type_id'], $validated_data['director_id'], $validated_data['manager_id'], $validated_data['vendor_id'], $validated_data['live_website'], $validated_data['has_live'], $activity_id);
echo edgimo_success('Activity details have been updated.');
$query->execute();
$query->close();
echo '<script>edgimo_redirect("edit.php?table=ashp_activities&id=' . $activity_id . '");</script>';
}
if ($form_type == 'insert') {
$query = $mysqli->prepare("INSERT INTO ashp_activities (title, url, folder, sponsor, type_id, director_id, manager_id, vendor_id, live_website, has_live) VALUES (?,?,?,?,?,?,?,?,?,?)");
$query->bind_param('ssssiiiiss', $validated_data['title'], $validated_data['url'], $validated_data['folder'], $validated_data['sponsor'], $validated_data['type_id'], $validated_data['director_id'], $validated_data['manager_id'], $validated_data['vendor_id'], $validated_data['live_website'], $validated_data['has_live']);
$query->execute();
$query->close();
$activity_id = $mysqli->query("SELECT activity_id FROM ashp_activities WHERE title = '{$validated_data['title']}'");
$vars = $activity_id->fetch_array(MYSQLI_ASSOC);
$activity_id = $vars['activity_id'];
$insert_fields = array_merge($backend->get_fields(0, $validated_data['has_live']), $backend->get_fields($validated_data['type_id'], $validated_data['has_live']));
foreach ($insert_fields as $field) {
if (strstr($field['copy'], '{{LIVE_OPTIONS}}')) {
$field['copy'] = live_options_replace($field['copy'], $validated_data['has_live']);
}
$query = $mysqli->prepare("INSERT INTO ashp_activity_content (activity_id, field_id, heading, copy, field_type, hook_name) VALUES (?,?,?,?,?,?)");
$query->bind_param('iissss', $activity_id, $field['field_id'], $field['heading'], $field['copy'], $field['field_type'], $field['hook_name']);
$query->execute();
$query->close();
}
create_site($validated_data['folder'], $activity_id);
echo edgimo_success('New activity created.');
echo '<script>edgimo_redirect("edit.php?table=ashp_activities&id=' . $activity_id . '");</script>';
}
}
}
$html .= '<form class="form-horizontal" role="form" method="post">';
foreach ($fields as $field) {
isset($errors) && array_key_exists($field['var'], $errors) ? $error = 'has-error' : ($error = '');
$html .= '<div class="form-group ' . $error . '">';
switch ($field['type']) {
case 'text':
if (!isset($type)) {
$type = 'text';
}
$html .= '
<label class="col-lg-2 control-label" for="form[' . $field['var'] . ']">' . $field['label'] . '</label>
<div class="col-lg-6">
<input class="form-control" type="' . $type . '" name="form[' . $field['var'] . ']" value="' . $field['std'] . '">
</div>';
break;
case 'select':
$html .= '
<label class="col-lg-2 control-label" for="form[' . $field['var'] . ']">' . $field['label'] . '</label>
<div class="col-lg-6">
<select class="form-control" name="form[' . $field['var'] . ']">';
foreach ($field['options'] as $option) {
//.........这里部分代码省略.........
示例11: process_submission
public static function process_submission()
{
require_once 'gump.class.php';
$gump = new GUMP();
$_POST = $gump->sanitize($_POST);
global $a;
$a = AC::load_current_activity();
if (isset($_POST['waitlist-submit'])) {
AC::generate_waitlist_fields();
require_once 'wp-content/themes/vetri-master/lib/ReCaptcha/autoload.php';
$recaptcha = new \ReCaptcha\ReCaptcha('6LendQoTAAAAABQzKPl_3sLPQQkTKMW4DBnIP37R', new \ReCaptcha\RequestMethod\Curl());
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$resp->isSuccess()) {
AC::$errors['recaptcha'] = 'Please verify using the ReCaptcha widget';
return false;
}
} else {
if (AC::is_active_timer_expired()) {
AC::$errors[] = 'Your timer has expired. Please start over.';
AC::reset_all();
return false;
}
AC::generate_fields();
$step = $_POST['step'];
foreach ($_POST['form'] as $k => $v) {
$_SESSION['edgimo-reservation-form']['step-' . $step][$k] = $v;
}
}
if (isset($_POST['activity-center-back'])) {
$_SESSION['edgimo-reservation-form']['current-step']--;
if (AC::get_current_step() === 1) {
AC::reset_timer();
}
return true;
}
$validation = array();
$filter = array();
foreach ($_POST['form'] as $field_name => $field_value) {
if (isset(AC::$fields[$field_name]['validate'])) {
$validation[$field_name] = AC::$fields[$field_name]['validate'];
}
if (isset(AC::$fields[$field_name]['filter'])) {
$filter[$field_name] = AC::$fields[$field_name]['filter'];
}
}
$gump->validation_rules($validation);
$gump->filter_rules($filter);
$validated_data = $gump->run($_POST['form']);
if (isset($step) && $step == 1 && !isset($validated_data['terms'])) {
AC::$errors['terms'] = 'You must agree to the terms of registration in order to register for an event. If you have questions about the terms, please feel free to contact us at <a href="mailto:' . $a->service_email . '">' . $a->service_email . '</a>';
return false;
}
if ($validated_data === false) {
$temp = $gump->get_readable_errors();
$i = 0;
foreach ($gump->validate($_POST['form'], $validation) as $error) {
AC::$errors[$error['field']] = $temp[$i];
$i++;
}
return false;
}
if (isset($_POST['waitlist-submit'])) {
$new_waitlist = wp_insert_post(array('post_name' => $validated_data['name'], 'post_title' => $validated_data['name'], 'post_type' => 'waitlist', 'post_status' => 'publish'));
$meta = array('_waitlist_activity' => $validated_data['activity_id'], '_waitlist_created' => time(), '_waitlist_name' => $validated_data['name'], '_waitlist_desired_seats' => $validated_data['desired_seats'], '_waitlist_phone' => $validated_data['phone_1'] . $validated_data['phone_2'] . $validated_data['phone_3'], '_waitlist_email' => $validated_data['email'], '_waitlist_code' => md5(time() . rand() . $validated_data['name']), '_waitlist_redeemed' => 'false');
foreach ($meta as $k => $v) {
add_post_meta($new_waitlist, $k, $v, true);
}
require_once 'wp-content/themes/vetri-master/lib/phpmailer/PHPMailerAutoload.php';
AC::send_admin_waitlist_email($new_waitlist);
AC::send_waitlist_confirmation_email($new_waitlist);
$_SESSION['edgimo-reservation-form']['waitlist-success'] = $new_waitlist;
wp_redirect(AC::get_redirect_url());
exit;
}
switch ($step) {
case 1:
//check to see if the capacity went down after submitting registrant count
if ($a->seats_available < AC::load_saved_data('number_of_registrants') && !AC::current_user_has_pending_reservation() && !AC::valid_waitlist_code()) {
AC::$errors['number_of_registrants'] = 'The number of registrants you selected is no longer available. Please select again.';
return false;
}
$_SESSION['edgimo-reservation-form']['current-step'] = 2;
//in case user clicked back using browser and not button, pending data will still exist. delete it
if (AC::current_user_has_pending_reservation()) {
AC::reset_timer();
}
//by now any old pending data should be gone
//always initiate a new timer when step 1 is submitted
AC::init_timer();
break;
case 2:
$_SESSION['edgimo-reservation-form']['current-step'] = 3;
break;
case 3:
$values = AC::get_all_final_values();
$result = AC::process_transaction($values);
if ($result['success']) {
$new_reservation = wp_insert_post(array('post_name' => $values['registrant_1_last_name'] . ', ' . $values['registrant_1_first_name'], 'post_title' => $values['registrant_1_last_name'] . ', ' . $values['registrant_1_first_name'], 'post_type' => 'reservation', 'post_status' => 'publish'));
isset($values['donation']) ? $values['donation'] = $values['donation'] : ($values['donation'] = 0);
$meta = array('_reservation_activity' => $a->ID, '_reservation_created' => time(), '_reservation_total' => AC::get_total(), '_reservation_fee' => $a->fee * $values['number_of_registrants'], '_reservation_gratuity' => AC::calculate_gratuity(), '_reservation_tax' => AC::calculate_tax(), '_reservation_donation' => $values['donation'], '_reservation_registrant_count' => $values['number_of_registrants'], '_reservation_optin' => $values['optin'], '_reservation_billing_first_name' => $values['billing_first_name'], '_reservation_billing_last_name' => $values['billing_last_name'], '_reservation_billing_address' => $values['billing_address'], '_reservation_billing_phone' => $values['billing_phone'], '_reservation_billing_city' => $values['billing_city'], '_reservation_billing_state' => $values['billing_state'], '_reservation_billing_zip' => $values['billing_zip'], '_reservation_transaction_id' => $result['RefNum'], '_reservation_auth_code' => $result['AuthCode'], '_reservation_card_type' => AC::card_type($values['cc_number']), '_reservation_last4' => $result['Last4']);
//.........这里部分代码省略.........
示例12: user_form
function user_form($user_id = 0)
{
global $mysqli;
global $user;
if ($user_id) {
$form_user = new User(get_user_email_by_id($user_id));
$form_type = 'update';
if ($form_user->email != $_SESSION['email'] && !$user->is_allowed('edit_ashp_users')) {
echo edgimo_error('Your user role (' . $user->role . ') is not allowed to make edits on this page.');
return;
}
} else {
if (!$user->is_allowed('add_user')) {
echo edgimo_error('Your user role (' . $user->role . ') is not allowed to add users.');
return;
}
$form_user = new User();
$form_type = 'insert';
}
$html = '';
$fields = array('first_name' => array('var' => 'first_name', 'label' => 'First Name', 'type' => 'text', 'std' => $form_user->first_name, 'validate' => 'required|valid_name', 'filter' => 'trim|sanitize_string', 'param' => 's', 'desc' => ''), 'last_name' => array('var' => 'last_name', 'label' => 'Last Name', 'type' => 'text', 'std' => $form_user->last_name, 'validate' => 'required|valid_name', 'filter' => 'trim|sanitize_string', 'param' => 's', 'desc' => ''), 'email' => array('var' => 'email', 'label' => 'Email', 'type' => 'text', 'std' => $form_user->email, 'validate' => 'required|valid_email', 'filter' => 'trim|sanitize_string', 'param' => 's', 'desc' => ''), 'password' => array('var' => 'password', 'label' => 'Password', 'type' => 'password', 'std' => '', 'validate' => 'required', 'filter' => '', 'param' => 's', 'desc' => ''));
if ($user->is_allowed('change_roles')) {
$fields['role'] = array('var' => 'role', 'label' => 'Role', 'type' => 'select', 'options' => unserialize(ROLES), 'std' => $form_user->role, 'validate' => 'required', 'filter' => 'trim|sanitize_string', 'param' => 's', 'desc' => '');
}
//special instructions for updating password
if ($form_type == 'update') {
$fields['password']['desc'] = 'Only enter a new password here if you wish to update the existing password';
}
if (isset($_POST['submit'])) {
$gump = new GUMP();
//password can be left blank when updating account. If it is, just plug in the saved value
if ($form_type == 'update') {
if ($_POST['form']['password'] === '') {
$_POST['form']['password'] = $form_user->password;
}
}
//add values to the validate and filter gump arrays
foreach ($_POST['form'] as $k => $v) {
//update the std value for form output below
$fields[$k]['std'] = $v;
if (!empty($fields[$k]['validate'])) {
$validate[$k] = $fields[$k]['validate'];
}
if (!empty($fields[$k]['filter'])) {
$filter[$k] = $fields[$k]['filter'];
}
}
//run gump
$gump->validation_rules($validate);
$gump->filter_rules($filter);
//get validated data
$validated_data = $gump->run($_POST['form']);
if (empty($validated_data['role'])) {
$validated_data['role'] = $form_user->role;
}
if ($validated_data === false) {
$errors = $gump->get_readable_errors(false);
$error_text = '';
foreach ($errors as $error) {
$error_text .= $error . '<br />';
}
echo edgimo_error($error_text);
} else {
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit;
}
if ($form_type == 'update') {
$query = $mysqli->prepare("UPDATE ashp_users SET first_name=?, last_name=?, email=?, role=?, password=? WHERE user_id=?");
$password = sha1($validated_data['password']);
$query->bind_param('sssssi', $validated_data['first_name'], $validated_data['last_name'], $validated_data['email'], $validated_data['role'], $password, $form_user->user_id);
echo edgimo_success('Account details have been updated.');
}
if ($form_type == 'insert') {
$query = $mysqli->prepare("INSERT INTO ashp_users (email, first_name, last_name, password, role, status) VALUES (?,?,?,?,?,?)");
$password = sha1($validated_data['password']);
$status = 'active';
$query->bind_param('ssssss', $validated_data['email'], $validated_data['first_name'], $validated_data['last_name'], $password, $validated_data['role'], $status);
echo edgimo_success('New user created.');
}
$query->execute();
$query->close();
$new_user = new User($validated_data['email']);
$user_vars = get_object_vars($new_user);
echo '<script>table_insert(' . json_encode($user_vars) . ');</script>';
}
}
$html .= '<form class="form-horizontal" role="form" method="post">';
foreach ($fields as $field) {
isset($errors) && array_key_exists($field['var'], $errors) ? $error = 'has-error' : ($error = '');
$html .= '<div class="form-group ' . $error . '">';
switch ($field['type']) {
case 'password':
$type = 'password';
$field['std'] = '';
case 'text':
if (!isset($type)) {
$type = 'text';
}
$html .= '
//.........这里部分代码省略.........
示例13: array
# https://youtu.be/sRfYgco3xo4?t=1758
$sql = 'SELECT name FROM users WHERE name=:name OR email=:name';
$user = $app->db->prepare($sql);
/*** bind the paramaters ***/
$user->bindParam(':name', $input[$field], PDO::PARAM_STR);
/*** execute the prepared statement ***/
$user->execute();
$user = $user->fetch(PDO::FETCH_ASSOC);
if (is_array($user)) {
return false;
}
}
});
$validation_rules_1 = array('username' => 'required|min_len,6|alpha_space|istaken', 'email' => 'required|valid_email|istaken', 'password' => 'required', 'password_confirm' => 'required');
$validation_rules_2 = array('username' => 'required|min_len,6|alpha_space', 'email' => 'required|valid_email', 'password' => 'required', 'password_confirm' => 'required');
$gump->validation_rules($validation_rules_1);
$filter_array = array('username' => 'trim|sanitize_string|rmpunctuation', 'email' => 'trim|sanitize_string|sanitize_email', 'password' => 'trim', 'password_confirm' => 'trim');
$gump->filter_rules($filter_array);
$validated_data = $gump->run($app->request->post());
if ($validated_data !== false) {
//
if ($app->request->post('password') !== $app->request->post('password_confirm')) {
$validated_data = false;
}
}
/*
if (is_array($validated_data)) {
foreach($validated_data as $key => $val)
{
$validated_data[$key] = htmlentities($val);
}
示例14: array
$fields = array('first_name' => array('var' => 'first_name', 'label' => 'First Name', 'desc' => '', 'type' => 'text', 'std' => $saved->first_name, 'validate' => 'required|valid_name', 'filter' => 'trim|sanitize_string', 'param' => 's'), 'last_name' => array('var' => 'last_name', 'label' => 'Last Name', 'desc' => '', 'type' => 'text', 'std' => $saved->last_name, 'validate' => 'required|valid_name', 'filter' => 'trim|sanitize_string', 'param' => 's'), 'email' => array('var' => 'email', 'label' => 'Email Address', 'desc' => '', 'type' => 'text', 'std' => $saved->email, 'validate' => 'required|valid_email', 'filter' => 'trim|sanitize_string', 'param' => 's'), 'city' => array('var' => 'city', 'label' => 'City', 'desc' => '', 'type' => 'text', 'std' => $saved->city, 'validate' => 'required', 'filter' => 'trim|sanitize_string', 'param' => 's'), 'state' => array('var' => 'state', 'label' => 'State', 'desc' => '', 'type' => 'select', 'std' => $saved->state, 'options' => $states, 'validate' => 'required', 'filter' => 'trim|sanitize_string', 'param' => 's'));
$form_saved = false;
if (isset($_POST['submit'])) {
$gump = new GUMP();
foreach ($_POST['form'] as $k => $v) {
//update the std value for form output below
$fields[$k]['std'] = $v;
$saved->{$k} = $v;
if (!empty($fields[$k]['validate'])) {
$validate[$k] = $fields[$k]['validate'];
}
if (!empty($fields[$k]['filter'])) {
$filter[$k] = $fields[$k]['filter'];
}
}
$gump->validation_rules($validate);
$gump->filter_rules($filter);
$validated_data = $gump->run($_POST['form']);
$error_text = '';
$privatekey = "6Lepf-gSAAAAAEE3oZNbZJE0FvuD4gtkQ04gZkAL";
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$validated_data = false;
$error_text .= $resp->error . '<br />';
}
if ($validated_data === false) {
$errors = $gump->get_readable_errors(false);
foreach ($errors as $error) {
$error_text .= $error . '<br />';
}
$html .= '<div class="alert alert-danger"><p>' . $error_text . '</p></div>';
示例15: diy_addorg
function diy_addorg($payload, $storage)
{
global $app;
$result["controller"] = __FUNCTION__;
$result["function"] = substr($app->request()->getPathInfo(), 1);
$result["method"] = $app->request()->getMethod();
$params = loadParameters();
$result->function = substr($app->request()->getPathInfo(), 1);
$result->method = $app->request()->getMethod();
//$params = loadParameters();
$up = json_decode(base64_decode($payload));
$client_id = $up->client_id;
$org = OAuth2\Request::createFromGlobals()->request["org"];
$org_desc = OAuth2\Request::createFromGlobals()->request["org_desc"];
$diy_error["post"]["org"] = $org;
$diy_error["post"]["org_desc"] = $org_desc;
$post["org"] = $org;
//organisation oauth_devices
$post["org_desc"] = $org_desc;
//mia perigrafi oti thelei o christis oauth_devices
$gump = new GUMP();
$gump->validation_rules(array('org' => 'required|alpha_numeric', 'org_desc' => 'required|max_len,100'));
$gump->filter_rules(array('org' => 'trim|sanitize_string', 'org_desc' => 'trim|sanitize_string'));
$validated = $gump->run($post);
if ($validated === false) {
$result["parse_errors"] = $gump->get_readable_errors(true);
$result["message"] = "[" . $result["method"] . "][" . $result["function"] . "]:" . $gump->get_readable_errors(true);
} else {
//check if device name exists
$stmt = $storage->prepare('SELECT * FROM oauth_organisations WHERE organisation = :org');
$stmt->execute(array('org' => trim($org)));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row) {
$result["result"]["error"] = ExceptionMessages::OrgExist . " , " . ExceptionCodes::OrgExist;
} else {
try {
// oauth_organisation table
$stmt2 = $storage->prepare('INSERT INTO oauth_organisations (organisation, client_id, desc) VALUES (:org, :client_id, :desc)');
$stmt2->execute(array('client_id' => $client_id, 'org' => $org, 'desc' => $org_desc));
// scopes gia devices
$scope = $org;
$is_default = 0;
$stmt3 = $storage->prepare('INSERT INTO oauth_scopes (scope, is_default) VALUES (:scope, :is_default)');
$stmt3->execute(array('scope' => $scope, 'is_default' => $is_default));
$scope = $org . "_dev";
$is_default = 0;
$stmt3 = $storage->prepare('INSERT INTO oauth_scopes (scope, is_default) VALUES (:scope, :is_default)');
$stmt3->execute(array('scope' => $scope, 'is_default' => $is_default));
$scope = $org . "_dpri";
$is_default = 0;
$stmt3 = $storage->prepare('INSERT INTO oauth_scopes (scope, is_default) VALUES (:scope, :is_default)');
$stmt3->execute(array('scope' => $scope, 'is_default' => $is_default));
$scope = $org . "_org";
$is_default = 0;
$stmt3 = $storage->prepare('INSERT INTO oauth_scopes (scope, is_default) VALUES (:scope, :is_default)');
$stmt3->execute(array('scope' => $scope, 'is_default' => $is_default));
$scope = $org . "_dpub";
$is_default = 0;
$stmt3 = $storage->prepare('INSERT INTO oauth_scopes (scope, is_default) VALUES (:scope, :is_default)');
$stmt3->execute(array('scope' => $scope, 'is_default' => $is_default));
// scopes gia users
$scope = $org . "_view";
$is_default = 0;
$stmt3 = $storage->prepare('INSERT INTO oauth_scopes (scope, is_default) VALUES (:scope, :is_default)');
$stmt3->execute(array('scope' => $scope, 'is_default' => $is_default));
$scope = $org . "_devel";
$is_default = 0;
$stmt3 = $storage->prepare('INSERT INTO oauth_scopes (scope, is_default) VALUES (:scope, :is_default)');
$stmt3->execute(array('scope' => $scope, 'is_default' => $is_default));
$scope = $org . "_admin";
$is_default = 0;
$stmt3 = $storage->prepare('INSERT INTO oauth_scopes (scope, is_default) VALUES (:scope, :is_default)');
$stmt3->execute(array('scope' => $scope, 'is_default' => $is_default));
$stmt6 = $storage->prepare('SELECT * FROM oauth_clients WHERE client_id = :client_id');
$stmt6->execute(array('client_id' => trim($client_id)));
$row6 = $stmt6->fetch(PDO::FETCH_ASSOC);
if ($row6) {
$scope6 = $row6["scope"];
$scope6 .= " " . $org . "_admin";
$scope6 .= " " . $org . "_view";
$stmt5 = $storage->prepare('UPDATE oauth_clients set scope = :scope6 where client_id = :client_id');
$stmt5->execute(array('scope6' => $scope6, 'client_id' => $client_id));
}
//result_messages===============================================================
$result["result"]["result"] = $post;
$result["result"]["session"] = $session;
$result["error"] = $error;
$result["status"] = "200";
$result["message"] = "[" . $result["method"] . "][" . $result["function"] . "]: NoErrors";
} catch (Exception $e) {
$result["status"] = $e->getCode();
$result["message"] = "[" . $result["method"] . "][" . $result["function"] . "]:" . $e->getMessage();
}
}
}
if (diyConfig::read('debug') == 1) {
$result["debug"] = $diy_error;
}
return $result;
}