2016-10-25 4 views
0

프레임 워크 Phalcon을 사용하여 웹 페이지를 만듭니다. 텍스트, 정수 및 날짜를 ​​묻는 양식이 있습니다. DatePicker (https://jqueryui.com/datepicker/)를 사용하여 날짜를 가져 왔습니다. 이 날짜는 데이터베이스에 삽입 할 때 삽입되지 않으며 텍스트와 int 만 삽입됩니다. 날짜 형식의 문제라고 생각하여 유효성을 검사하고 싶습니다. 텍스트 필드에 데이터가 있는지 확인할 수는 있지만 유효성을 검사하는 "유효성 검사기"는 날짜가 아닙니다. 여기 팔콘 양식의 날짜를 어떻게 확인할 수 있습니까?

<div class="page-header"> 
<h2>Registro de Nueva Keyword</h2> 
</div> 
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 

<section class="container animated fadeInUp"> 
<div class="row"> 
    <div class="col-md-6 col-md-offset-3"> 
    <div id="login-wrapper"> 
     <div class="panel panel-primary"> 
      <div class="panel-heading"> 
       <h3 class="panel-title">  
        Registrar Nueva Keyword 
       </h3> 
      </div> 
      <div class="panel-body"> 
       {{ form('admin/nuevakeyword/', 'id': 'nuevakeywordForm', 'onbeforesubmit': 'return false') }} 

       <fieldset> 

        <div class="control-group"> 
         {{ form.label('trackeable', ['class': 'control-label']) }} 
         <div class="controls"> 
          {{ form.render('trackeable', ['class': 'form-control']) }} 
         </div> 
        </div> 

        <div class="control-group"> 
         {{ form.label('idcliente', ['class': 'control-label']) }} 
         <div class="controls"> 
          {{ form.render('idcliente', ['class': 'form-control']) }}       
         </div> 
        </div> 

        <div class="control-group"> 
         {{ form.label('fecha_final', ['class': 'control-label']) }} 
         <div id="datepicker" class="controls"> 
          {{ form.render('fecha_final', ['class': 'form-control']) }} 
         </div> 
        </div> 

        <div class="form-actions"> 
         {{ submit_button('Insertar', 'class': 'btn btn-primary', 'onclick': 'return SignUp.validate();') }} 
        </div> 

       </fieldset> 
       </form> 
      </div> 
     </div> 
    </div> 
    </div> 
</div> 
</section> 

<script type="text/javascript"> 
    $(function() { 
     $("#fecha_final").datepicker(); 
    }); 
</script> 

는 컨트롤러 : 여기
<?php 

use Phalcon\Forms\Form; 
use Phalcon\Forms\Element\Text; 
use Phalcon\Forms\Element\Date; 
use Phalcon\Forms\Element\Password; 
use Phalcon\Validation\Validator\PresenceOf; 
use Phalcon\Validation\Validator\Email; 

class NuevakeywordForm extends Form{ 

public function initialize($entity = null, $options = null){ 
    // Trackeable 
    $trackeable = new Text('trackeable'); 
    $trackeable->setLabel('Palabra Clave'); 
    $trackeable->setFilters(array('striptags', 'string')); 
    $trackeable->addValidators(array(
     new PresenceOf(array(
      'message' => 'Palabra clave requerida' 
      )) 
     )); 
    $this->add($trackeable); 

    // IdCliente 
    $idcliente = new Text('idcliente'); 
    $idcliente->setLabel('idcliente'); 
    $idcliente->addValidators(array(
     new PresenceOf(array(
      'message' => 'IdCliente is required' 
      )) 
     )); 
    $this->add($idcliente); 

    // Fecha Límite 
    $fecha = new Text('fecha_final'); 
    $fecha->setLabel('Fecha Final'); 
    $fecha->addValidators(array(
     new PresenceOf(array(
      'message' => 'Por favor pon una fecha límite' 
      )) 
     )); 
    $this->add($fecha); 
    } 
} 

뷰입니다 : 내가 MariaDB를 사용하고

public function nuevakeywordAction(){ 
    $auth = $this->session->get('auth'); 
    $permiso = $auth['active']; 
    if($permiso!='A'){return $this->forward('servicios/index');} 

    $form = new NuevakeywordForm; 

    if ($this->request->isPost()) { 

     $trackeable = $this->request->getPost('trackeable', array('string', 'striptags')); 
     $idcliente = $this->request->getPost('idcliente'); 
     $fecha = $this->request->getPost('fecha'); 

     $keyword = new Keyword(); 
     $keyword->trackeable = $trackeable; 
     $keyword->cliente_idcliente = $idcliente; 
     $keyword->fecha_inicial = new Phalcon\Db\RawValue('now()'); 
     $keyword->fecha_final = $fecha; 
     if ($keyword->save() == false) { 
      foreach ($keyword->getMessages() as $message) { 
       $this->flash->error((string) $message); 
      } 
     } else { 
      $this->tag->setDefault('trackeable', ''); 
      $this->tag->setDefault('idcliente', ''); 
      $this->tag->setDefault('fecha', ''); 
      $this->flash->success('Keyword agregada correctamente'); 
      return $this->forward('admin/verkeywords'); 
     } 
    } 

    $this->view->form = $form; 
} 

로 (같은

은 내 양식 클래스입니다 MySQL). 날짜에 대한 "addValidator"를 찾으려고하지만 다른 문제 일 수 있습니다. 어떤 도움도 환영 할 것입니다.

+1

Phalcon\Validation\Validator\Date Timothy

답변

관련 문제