コード例 #1
0
 /**
  * @param string $url
  * @return \FormValidator
  */
 private function getSearchForm($url)
 {
     $form = new \FormValidator('search-form', 'get', $url, null, array('class' => 'form-inline'));
     $form->addElement('text', 'keyword');
     $form->addElement('button', 'submit', get_lang('Search'));
     return $form;
 }
コード例 #2
0
ファイル: Photo_model.php プロジェクト: sbadi/shareatrip
 function addPhotoModel($photoForm, $albumId)
 {
     $formObjRaw = new FormDTO(ADD_PHOTO_FORM, $photoForm);
     $responseDTO = new ResponseDTO(ADD_PHOTO_FORM);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $validator = new FormValidator(ADD_PHOTO_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         if (sizeof($validationError) == 0) {
             $uploadedPhoto = FileUtils::uploadPhotoModel($formDataObj[ADD_PHOTO_FORM . PHOTO], $albumId, ADD_PHOTO_FORM, $formDataObj[ADD_PHOTO_FORM . LATITUDE], $formDataObj[ADD_PHOTO_FORM . LONGITUDE]);
             if (get_class($uploadedPhoto) === PHOTODTO) {
                 DataModelUtils::notifyAction($uploadedPhoto->getPhotoId() . SEPARATOR . $uploadedPhoto->getPhotoUrl() . SEPARATOR . $albumId, ADD_PHOTO_FORM);
                 return $uploadedPhoto;
             } else {
                 $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'inserimento della foto");
             }
         } else {
             if (array_key_exists(PHOTO, $validationError)) {
                 $responseDTO->setErrField(PHOTO, $validationError[PHOTO]);
             }
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
コード例 #3
0
ファイル: login.php プロジェクト: omaoibrahim/chamilo-lms
function openid_form()
{
    $form = new FormValidator('openid_login', 'post', null, null, array('class' => 'form-vertical form_login'));
    $form->addElement('text', 'openid_url', array(get_lang('OpenIDURL'), Display::url(get_lang('OpenIDWhatIs'), 'main/auth/openid/whatis.php')), array('class' => 'openid_input'));
    $form->addElement('button', 'submit', get_lang('Login'));
    return $form->return_form();
}
コード例 #4
0
 /**
  * Controls direction of inbound POST data by intercepting it and sending it
  * to the correct model and then loads the correct views
  *
  * Note - need a way to determine the amount of input fields and their types, 
  * 		which will help in determing what error checking needs to be done.
  * 		This should be a model that parses out the POST array
  * 
  * @return [type] [description]
  */
 public function redirectPostRequest()
 {
     // send form data to the model
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         // invoke form validator model
         $FormValidator = new FormValidator();
         $FormValidator->validateFormData($_POST);
         // get errors array
         $errorsArray = $FormValidator->getErrorsArray();
         // determine if an error was flagged due to illegal user input
         if (filter_by_value($errorsArray, 'error', '1')) {
             // debug
             // print_var($errorsArray);
             // echo "Error exists";
             // render errors to client
             require 'application/views/view.render_form_errors.php';
             echo "HERE IS THE VIEW" . "<br>";
         } else {
             // require APP_PATH . 'controller/' . $this->url_controller . '.php';
             // $this->url_controller = new $this->url_controller();
             // redirect user to a success page
             // header('Location: success_page.php');
         }
     }
 }
コード例 #5
0
 /**
  * Handles requested "/" route
  */
 public function indexAction()
 {
     // handle contact form
     if (!empty($_POST['form_submit'])) {
         $formValidator = new FormValidator($_POST['form'], $this->view);
         // if there were no errors
         if ($formValidator->isValid()) {
             // format user submitted data
             $data = array();
             $data[] = '<table>';
             foreach ($_POST['form'] as $field => $value) {
                 $data[] = '<tr><th>' . ucwords(str_replace(array('-', '_'), ' ', $field)) . '</th><td>' . nl2br($value) . '</td></tr>';
             }
             $data[] = '</table>';
             // send message
             $mailer = new Mailer();
             $result = $mailer->sendSystemMessage(implode("\n", $data), $_POST['form_submit']);
             if ($result) {
                 $this->router->redirect('/thanks');
                 die;
             }
         } else {
             $this->errorMessages = $formValidator->getFormattedErrors();
         }
     }
 }
コード例 #6
0
ファイル: ch_dropdown.php プロジェクト: KRCM13/chamilo-lms
 /**
  * @param FormValidator $form
  * @param array $questionData
  * @param array $answers
  */
 public function render(FormValidator $form, $questionData = array(), $answers = '')
 {
     $name = 'question' . $questionData['question_id'];
     $form->addSelect($name, null, $questionData['options']);
     if (!empty($answers)) {
         $form->setDefaults([$name => $answers]);
     }
 }
コード例 #7
0
 /**
  * @return FormValidator
  */
 private function getSearchForm()
 {
     $form = new FormValidator('form-search', 'post', api_get_self() . '?action=subscribe&amp;hidden_links=0', null, array('class' => 'form-search'));
     $form->addElement('hidden', 'search_course', '1');
     $form->addElement('text', 'search_term');
     $form->addElement('button', 'submit', get_lang('Search'));
     return $form;
 }
コード例 #8
0
 /** @test */
 public function バリデーション違反があれば、違反したルールを返すこと()
 {
     $validator = new FormValidator();
     $validator->addRule(FormValidator::ZIP_CODE, 'xxx-1111', '郵便番号に誤りがあります')->addRule(FormValidator::DATE, '2015-11-11', '日付に誤りがあります');
     $errors = $validator->valid();
     $expected = [];
     $expected[] = new ValidateRule(FormValidator::ZIP_CODE, 'xxx-1111', '郵便番号に誤りがあります');
     // objectの比較のためassertEquals
     $this->assertEquals($expected, $errors);
 }
コード例 #9
0
ファイル: FormValidatorTest.php プロジェクト: lmcro/fcms
 public function testInteger()
 {
     $profile = array('constraints' => array('field1' => array('required' => 1, 'integer' => 1), 'field2' => array('integer' => 1), 'field3' => array('integer' => 1), 'field4' => array('integer' => 1), 'field5' => array('integer' => 1)));
     $data = array('field1' => '5', 'field2' => 10, 'field3' => 'asdf', 'field4' => '5.1', 'field5' => 5.1);
     $validator = new FormValidator();
     $errors = $validator->validate($data, $profile);
     $this->assertEquals($errors, array('field3 is invalid.', 'field4 is invalid.', 'field5 is invalid.'));
     $this->assertEquals($validator->valid, array('field1', 'field2'));
     $this->assertEquals($validator->invalid, array('field3', 'field4', 'field5'));
     $this->assertEquals($validator->missing, array());
 }
コード例 #10
0
 /**
  * @param FormValidator $form
  * @param array $questionData
  * @param string $answers
  */
 public function render(FormValidator $form, $questionData = array(), $answers = '')
 {
     if (is_array($answers)) {
         $content = implode('', $answers);
     } else {
         $content = $answers;
     }
     $name = 'question' . $questionData['question_id'];
     $form->addTextarea($name, null);
     $form->setDefaults([$name => $answers]);
 }
コード例 #11
0
 /**
  * @param FormValidator $form
  * @param array $questionData
  * @param array $answers
  */
 public function render(FormValidator $form, $questionData = array(), $answers = '')
 {
     $options = array('--' => '--');
     foreach ($questionData['options'] as $key => &$value) {
         $options[$key] = $value;
     }
     $name = 'question' . $questionData['question_id'];
     $form->addSelect($name, null, $options);
     if (!empty($answers)) {
         $form->setDefaults([$name => $answers]);
     }
 }
コード例 #12
0
ファイル: Validate.php プロジェクト: phucdnict/cbcc_05062015
 public function formTochuc()
 {
     $validator = new FormValidator();
     $valid = array();
     $valid['NAME'] = array('req' => "Please fill in Name");
     $valid['LOAIHINHBIENCHE'] = array('req' => "Please fill in Name");
     foreach ($valid as $input => $aRow) {
         foreach ($aRow as $key => $value) {
             $validator->addValidation($input, $key, $value);
         }
     }
     return $validator;
 }
コード例 #13
0
ファイル: qti2.php プロジェクト: KRCM13/chamilo-lms
/**
 * This function displays the form for import of the zip file with qti2
 */
function ch_qti2_display_form()
{
    $name_tools = get_lang('ImportQtiQuiz');
    $form = '<div class="actions">';
    $form .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'exercice/exercise.php?show=test&' . api_get_cidreq() . '">' . Display::return_icon('back.png', get_lang('BackToExercisesList'), '', ICON_SIZE_MEDIUM) . '</a>';
    $form .= '</div>';
    $formValidator = new FormValidator('qti_upload', 'post', api_get_self() . "?" . api_get_cidreq(), null, array('enctype' => 'multipart/form-data'));
    $formValidator->addElement('header', $name_tools);
    $formValidator->addElement('file', 'userFile', get_lang('DownloadFile'));
    $formValidator->addButtonImport(get_lang('Upload'));
    $form .= $formValidator->returnForm();
    echo $form;
}
コード例 #14
0
 /**
  * function which redefine Question::createAnswersForm
  * @param FormValidator $form
  */
 function createAnswersForm($form)
 {
     $form->addElement('text', 'weighting', get_lang('Weighting'), array('class' => 'span1'));
     global $text, $class;
     // setting the save button here and not in the question class.php
     $form->addButtonSave($text, 'submitQuestion');
     if (!empty($this->id)) {
         $form->setDefaults(array('weighting' => float_format($this->weighting, 1)));
     } else {
         if ($this->isContent == 1) {
             $form->setDefaults(array('weighting' => '10'));
         }
     }
 }
コード例 #15
0
ファイル: login.php プロジェクト: ilosada/chamilo-lms-icpna
function openid_form()
{
    //get_lang('OpenIdAuthentication')
    $form = new FormValidator('openid_login', 'post', null, null, array('class' => 'form-vertical form_login'));
    $form->addElement('text', 'openid_url', array(get_lang('OpenIDURL'), Display::url(get_lang('OpenIDWhatIs'), 'main/auth/openid/whatis.php')), array('class' => 'openid_input'));
    $form->addElement('button', 'submit', get_lang('Login'));
    return $form->return_form();
    /*
     return '<label for="openid_url">'.get_lang('OpenIDURL').' <a href="main/auth/openid/whatis.php" title="'.get_lang('OpenIDWhatIs').'">'.Display::return_icon('info3.gif',get_lang('Info')).'</a></label>
     <input type="text" id="openid_url" name="openid_url" style="background: url(main/img/openid_small_logo.png) no-repeat; background-color: #fff; background-position: 0 50%; padding-left:18px;" value="http://"></input>
    * <input type="submit" name="openid_login" value="'.get_lang('Enter').'" /><br /><br /></form></div>';
    *
    */
}
コード例 #16
0
ファイル: ch_yesno.php プロジェクト: jloguercio/chamilo-lms
 /**
  * @param FormValidator $form
  * @param array $questionData
  * @param array $answers
  */
 public function render(FormValidator $form, $questionData = array(), $answers = null)
 {
     if (is_array($questionData['options'])) {
         if ($questionData['display'] == 'vertical') {
             $class = 'radio';
         } else {
             $class = 'radio-inline';
         }
         $name = 'question' . $questionData['question_id'];
         $form->addRadio($name, null, $questionData['options'], ['radio-class' => $class, 'label-class' => $class]);
         if (!empty($answers)) {
             $form->setDefaults([$name => $answers]);
         }
     }
 }
コード例 #17
0
 /**
  * Constructor.
  * @param $form object
  * @param $userIp string IP address of user request
  * @param $message string Key of message to display on mismatch
  */
 function FormValidatorReCaptcha(&$form, $challengeField, $responseField, $userIp, $message)
 {
     parent::FormValidator($form, $challengeField, FORM_VALIDATOR_REQUIRED_VALUE, $message);
     $this->_challengeField = $challengeField;
     $this->_responseField = $responseField;
     $this->_userIp = $userIp;
 }
コード例 #18
0
 /**
  * Constructor.
  * @param $form Form the associated form
  * @param $field string the name of the associated field
  * @param $type string the type of check, either "required" or "optional"
  * @param $message string the error message for validation failures (i18n key)
  * @param $fields array all subfields for each item in the array, i.e. name[][foo]. If empty it is assumed that name[] is a data field
  */
 function FormValidatorArray(&$form, $field, $type, $message, $fields = array(), $subArray = false)
 {
     parent::FormValidator($form, $field, $type, $message);
     $this->_fields = $fields;
     $this->_subArray = $subArray;
     $this->_errorFields = array();
 }
コード例 #19
0
 /**
  * Constructor.
  * The user function is passed the form data as its first argument and $additionalArguments, if set, as the remaining arguments. This function must return a boolean value.
  * @param $form Form the associated form
  * @param $field string the name of the associated field
  * @param $type string the type of check, either "required" or "optional"
  * @param $message string the error message for validation failures (i18n key)
  * @param $userFunction callable function the user function to use for validation
  * @param $additionalArguments array optional, a list of additional arguments to pass to $userFunction
  * @param $complementReturn boolean optional, complement the value returned by $userFunction
  */
 function __construct(&$form, $field, $type, $message, $userFunction, $additionalArguments = array(), $complementReturn = false)
 {
     parent::__construct($form, $field, $type, $message);
     $this->_userFunction = $userFunction;
     $this->_additionalArguments = $additionalArguments;
     $this->_complementReturn = $complementReturn;
 }
コード例 #20
0
 /**
  * Constructor.
  * @param $form Form the associated form
  * @param $field string the name of the associated field
  * @param $type string the type of check, either "required" or "optional"
  * @param $message string the error message for validation failures (i18n key)
  * @param $radiofields array all the radio buttons to check.
  * @param $twoDim boolean specify if if this is a 2 dimensional array
  */
 function FormValidatorArrayRadios(&$form, $field, $type, $message, $radiofields, $twoDim = false)
 {
     parent::FormValidator($form, $field, $type, $message);
     $this->twoDimenstion = $twoDim;
     $this->_radiofields = $radiofields;
     $this->_errorFields = array();
 }
コード例 #21
0
 /**
  * Constructor.
  * The user function is passed the form data as its first argument and $additionalArguments, if set, as the remaining arguments. This function must return a boolean value.
  * @param $form Form the associated form
  * @param $field string the name of the associated field
  * @param $type string the type of check, either "required" or "optional"
  * @param $message string the error message for validation failures (i18n key)
  * @param $userFunction callable function the user function to use for validation
  * @param $additionalArguments array optional, a list of additional arguments to pass to $userFunction
  * @param $complementReturn boolean optional, complement the value returned by $userFunction
  */
 function FormValidatorCustom(&$form, $field, $type, $message, $userFunction, $additionalArguments = array(), $complementReturn = false)
 {
     parent::FormValidator($form, $field, $type, $message);
     $this->_userFunction = $userFunction;
     $this->_additionalArguments = $additionalArguments;
     $this->_complementReturn = $complementReturn;
 }
コード例 #22
0
 function validate()
 {
     $result = parent::validate();
     if ($result) {
         $this->update_model();
     }
     return $result;
 }
コード例 #23
0
 /**
  * @param FormValidator $form
  * @param array $questionData
  * @param array $answers
  */
 public function render(FormValidator $form, $questionData = array(), $answers = array())
 {
     if ($questionData['display'] == 'vertical') {
         $class = 'checkbox';
     } else {
         $class = 'checkbox-inline';
     }
     $name = 'question' . $questionData['question_id'];
     $form->addCheckBoxGroup($name, null, $questionData['options'], array('checkbox-class' => $class, 'label-class' => $class));
     $defaults = [];
     if (!empty($answers)) {
         foreach ($answers as $answer) {
             $defaults[$name . '[' . $answer . ']'] = true;
         }
     }
     $form->setDefaults($defaults);
 }
コード例 #24
0
 /**
  * Get the error message associated with a failed validation check.
  * @see FormValidator::getMessage()
  * @return string
  */
 function getMessage()
 {
     $primaryLocale = Locale::getPrimaryLocale();
     $allLocales = Locale::getAllLocales();
     //return parent::getMessage() . ' (' . $allLocales[$this->_requiredLocale] . ')';
     return parent::getMessage();
     //Edited by Anne Ivy Mirasol, April 27, 2011
 }
コード例 #25
0
ファイル: Album_model.php プロジェクト: sbadi/shareatrip
 function addAlbumModel($albumForm)
 {
     $formObjRaw = new FormDTO(ADD_ALBUM_FORM, $albumForm);
     $responseDTO = new ResponseDTO(ADD_ALBUM_FORM);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $validator = new FormValidator(ADD_ALBUM_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         //            $validationError = array();
         if (sizeof($validationError) == 0) {
             $userLogged = SessionUtils::getUserLogged();
             $uploadedPhoto = FileUtils::uploadPhotoModel($formDataObj[ADD_ALBUM_FORM . COVER], NULL, ADD_ALBUM_FORM);
             if (get_class($uploadedPhoto) === PHOTODTO) {
                 $userDAO = new UserDAO();
                 $userDTO = $userDAO->getUserByUserId($userLogged->getUserId());
                 $albumDAO = new AlbumDAO();
                 $albumDTO = new AlbumDTO(null, date(DATE_FORMAT), $formDataObj[ADD_ALBUM_FORM . TITLE], $uploadedPhoto, $userDTO);
                 $albumDTO = $albumDAO->insertNewAlbum($albumDTO);
                 if ($albumDTO->getAlbumId() != 0) {
                     $photoAlbumPath = FileUtils::createAlbumDirOnServer($userDTO->getUserId(), $albumDTO->getAlbumId());
                     DataModelUtils::notifyAction($albumDTO->getCover()->getPhotoId() . SEPARATOR . $albumDTO->getCover()->getPhotoUrl() . SEPARATOR . $albumDTO->getAlbumId() . SEPARATOR . $albumDTO->getTitle(), ADD_ALBUM_FORM);
                     return $albumDTO;
                 } else {
                     $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'inserimento dell'album");
                 }
             } else {
                 $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'inserimento della foto profilo");
             }
         } else {
             if (array_key_exists(TITLE, $validationError)) {
                 $responseDTO->setErrField(TITLE, $validationError[TITLE]);
             }
             if (array_key_exists(PHOTO, $validationError)) {
                 $responseDTO->setErrField(COVER, $validationError[PHOTO]);
             }
             SessionUtils::setFormValue($formDataObj);
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
コード例 #26
0
    public function Register()
    {
        if($this->user->isAuthorized()) {
            $this->getView('alreadyRegister');
            return true;
        }
        
        $formValidator = new FormValidator;
        if($_POST['Submit']) {
            $_POST['password'] = $formValidator->getSafetyValue($_POST['password']);
            $_POST['email'] = $formValidator->getSafetyValue($_POST['email']);
            $_POST['password_again'] = $formValidator->getSafetyValue($_POST['password_again']);

            if($formValidator->checkEmail($_POST['email']) && 
                $formValidator->checkPassword($_POST['password'], $_POST['password_again'])) {

                $this->user->register($_POST);
                $this->user->signin($_POST);

                $this->forwardTo('ModifyRegister');
            }  
        }

        $this->getView('register', array('registerParams' => new RegisterParams(), 'errors' => $formValidator->getErrors()));
    }
コード例 #27
0
 /**
  * Validate string
  *
  * @param string $str
  * @param bool $retMsg
  * @return string or bool
  */
 public static function validatePasswords($pass, $rePass)
 {
     $pass = FormValidator::secure($pass);
     $rePass = FormValidator::secure($rePass);
     if ($pass !== $rePass) {
         return "These passwords don't match. Try again?";
     }
     return true;
 }
コード例 #28
0
 /**
  * @param FormValidator $form
  * @param null $objExercise
  * @return bool
  */
 public function processCreation($form, $objExercise = null)
 {
     $file_info = $form->getSubmitValue('imageUpload');
     $_course = api_get_course_info();
     parent::processCreation($form, $objExercise);
     if (!empty($file_info['tmp_name'])) {
         $this->uploadPicture($file_info['tmp_name'], $file_info['name']);
         $documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
         $picturePath = $documentPath . '/images';
         // fixed width ang height
         if (file_exists($picturePath . '/' . $this->picture)) {
             $this->resizePicture('width', 800);
             $this->save();
         } else {
             return false;
         }
     }
 }
コード例 #29
0
 /**
  * Returns a Form validator Obj
  * @todo the form should be auto generated
  * @param   string  url
  * @param   string  action add, edit
  * @return  obj     form validator obj
  */
 public function return_form($url, $action)
 {
     $oFCKeditor = new FCKeditor('description');
     $oFCKeditor->ToolbarSet = 'careers';
     $oFCKeditor->Width = '100%';
     $oFCKeditor->Height = '200';
     $oFCKeditor->Value = '';
     $oFCKeditor->CreateHtml();
     $form = new FormValidator('career', 'post', $url);
     // Setting the form elements
     $header = get_lang('Add');
     if ($action == 'edit') {
         $header = get_lang('Modify');
     }
     $form->addElement('header', $header);
     $id = isset($_GET['id']) ? intval($_GET['id']) : '';
     $form->addElement('hidden', 'id', $id);
     $form->addElement('text', 'name', get_lang('Name'), array('size' => '70'));
     $form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers', 'Width' => '100%', 'Height' => '250'));
     $status_list = $this->get_status_list();
     $form->addElement('select', 'status', get_lang('Status'), $status_list);
     if ($action == 'edit') {
         $form->addElement('text', 'created_at', get_lang('CreatedAt'));
         $form->freeze('created_at');
     }
     if ($action == 'edit') {
         $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
     } else {
         $form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="save"');
     }
     // Setting the defaults
     $defaults = $this->get($id);
     if (!empty($defaults['created_at'])) {
         $defaults['created_at'] = api_convert_and_format_date($defaults['created_at']);
     }
     if (!empty($defaults['updated_at'])) {
         $defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']);
     }
     $form->setDefaults($defaults);
     // Setting the rules
     $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
     return $form;
 }
コード例 #30
0
 /**
  * Constructor.
  * @param $form Form the associated form
  * @param $field string the name of the associated field
  * @param $type string the type of check, either "required" or "optional"
  * @param $message string the error message for validation failures (i18n key)
  * @param $userFunction function the user function to use for validation
  * @param $additionalArguments array optional, a list of additional arguments to pass to $userFunction
  * @param $complementReturn boolean optional, complement the value returned by $userFunction
  * @param $fields array all subfields for each item in the array, i.e. name[][foo]. If empty it is assumed that name[] is a data field
  * @param $isLocaleField boolean
  */
 function FormValidatorArrayCustom(&$form, $field, $type, $message, $userFunction, $additionalArguments = array(), $complementReturn = false, $fields = array(), $isLocaleField = false)
 {
     parent::FormValidator($form, $field, $type, $message);
     $this->_fields = $fields;
     $this->_errorFields = array();
     $this->_isLocaleField = $isLocaleField;
     $this->_userFunction = $userFunction;
     $this->_additionalArguments = $additionalArguments;
     $this->_complementReturn = $complementReturn;
 }