/** * validate form * @return boolean */ private function validateForm() { $this->load->model('Admin_model'); $id = id_auth_user(); $post = $this->input->post(); $err = ''; if ($post['name'] == '') { $err .= 'Please insert Name.<br/>'; } else { if (strlen($post['name']) < 1 || strlen($post['name']) > 32) { $err .= 'Please insert Name.<br/>'; } } if ($post['email'] == '') { $err .= 'Please insert Email.<br/>'; } else { if (!mycheck_email($post['email'])) { $err .= 'Please insert correct Email.<br/>'; } else { if (!$this->Admin_model->checkExistsEmail($post['email'], $id)) { $err .= 'Email already exists, please input different Email.<br/>'; } } } if ($post['phone'] != '' && !ctype_digit($post['phone'])) { $err .= 'Please insert correct Phone.<br/>'; } $post_image = $_FILES; if (!empty($post_image['image']['tmp_name'])) { $check_picture = validatePicture('image'); if (!empty($check_picture)) { $err .= $check_picture . '<br/>'; } } if ($err) { $this->error = $err; return false; } else { return true; } }
/** * validate form * @param int $id * @return boolean */ private function validateForm($id = 0) { $post = $this->input->post(); $config = array(array('field' => 'username', 'label' => 'Username', 'rules' => 'required|min_length[3]|max_length[32]|alpha_dash|callback_check_username_exists[' . $id . ']'), array('field' => 'id_auth_group', 'label' => 'Group', 'rules' => 'required|is_natural_no_zero'), array('field' => 'name', 'label' => 'Name', 'rules' => 'required|alpha_numeric_spaces'), array('field' => 'email', 'label' => 'Email', 'rules' => 'required|valid_email|callback_check_email_exists[' . $id . ']'), array('field' => 'id_auth_group', 'label' => 'Group', 'rules' => 'required|is_natural_no_zero')); $this->form_validation->set_rules($config); if ($this->form_validation->run() === FALSE) { $this->error = alert_box(validation_errors(), 'danger'); return FALSE; } else { $post_image = $_FILES; if (!$id) { if ($post['password'] == '') { $this->error = 'Please insert Password.<br/>'; } else { if (strlen($post['password']) <= 6) { $this->error = 'Please input Password more than 6 characters.<br/>'; } else { if ($post['conf_password'] != $post['password']) { $this->error = 'Your Confirmation Password is not same with Your Password.<br/>'; } } } } else { if (strlen($post['password']) > 0) { if (strlen($post['password']) <= 6) { $this->error = 'Please input Password more than 6 characters.<br/>'; } else { if ($post['conf_password'] != $post['password']) { $this->error = 'Your Confirmation Password is not same with Your Password.<br/>'; } } } } if (!$this->error) { if (!empty($post_image['image']['tmp_name'])) { $check_picture = validatePicture('image'); if (!empty($check_picture)) { $this->error = alert_box($check_picture, 'danger'); return FALSE; } } return TRUE; } else { $this->error = alert_box($this->error, 'danger'); return FALSE; } } }
echo "Image not uploaded, please try again."; } $data = elements(array('title', 'galleryOption'), $_POST); $allGood = true; foreach ($data as $value) { if ($value === null || empty($value)) { $allGood = false; break; } } $data['description'] = element('description', $_POST, ''); foreach ($data as $key => $value) { $data[$key] = htmlentities($value); } if ($allGood) { if (validatePicture($_FILES['file']['tmp_name'])) { storePicture($_FILES['file']['tmp_name'], $data['title'], $data['description'], $_SESSION['user_id'], $data['galleryOption']); header('Location: mypictures.php'); exit; } else { echo "Image not valid. Please try again."; } } else { echo "Not all required fields are filled.."; } } $galleries = getGalleries($_SESSION['user_id']); //ako nema ni jednu galeriju dosad - nek ju napravi if (empty($galleries)) { header('Location: new_gallery.php'); exit;
/** * validate form * @param int $id * @return boolean */ private function validateForm($id = 0) { $config = array(array('field' => 'site_name', 'label' => 'Site Name', 'rules' => 'required'), array('field' => 'site_url', 'label' => 'Site URL', 'rules' => 'required')); $this->form_validation->set_rules($config); if ($this->form_validation->run() === FALSE) { $this->error = alert_box(validation_errors(), 'danger'); return FALSE; } else { $post_image = $_FILES; if (!empty($post_image['site_logo']['tmp_name'])) { $check_picture = validatePicture('site_logo'); if (!empty($check_picture)) { $this->error = alert_box($check_picture, 'danger'); return FALSE; } } return TRUE; } }
header('Location: login.php'); exit; } //obrada forme if (!empty($_POST['submitted'])) { if (empty($_FILES['file'])) { echo "Image not uploaded, please try again."; exit; } $formValidation = new \validation_library\FormValidation(); $rules = array(); $rules['name'] = 'length[100]'; $rules['description'] = 'length[500]'; $rules['img_tag'] = 'length[500]'; $formValidation->set_rules($rules); if ($formValidation->validate() && validatePicture($_FILES['file']['tmp_name'])) { \models\ImgTag::validateTags($_POST['img_tag']); $tags = \models\ImgTag::validateTags($_POST['img_tag']); if ($tags === false) { echo "Every tag must be <= 50 characters"; header("Refresh: 1"); exit; } //add image $query = \db\DAO::getInstance()->prepare("INSERT INTO Images(title, user_id,\n gallery_id, description) VALUES (?,?,?,?)"); $query->execute([trim(htmlentities($_POST['name'])), $_SESSION['user_id'], trim(htmlentities($_POST['galleryOption'])), trim(htmlentities($_POST['description']))]); $id = \db\DAO::getInstance()->lastInsertId(); //add tags $query = \db\DAO::getInstance()->prepare("INSERT INTO Tags(image_id, tag) VALUES ({$id},?)"); if (!empty($tags)) { foreach ($tags as $tag) {