2016-10-25 25 views
0

私はフレームワークPhalconを使用してWebページを構築します。私は、テキスト、整数、日付を求めるフォームを持っています。私はdatepicker(https://jqueryui.com/datepicker/)を使って日付を取得しています。データベースに挿入すると、この日付は挿入されず、テキストとintだけが挿入されます。 日付の形式の問題だと思いますので、検証したいと思います。 テキストフィールドにデータの存在を確認できますが、日付であることを検証するための「バリデータ」はありません。Phalconのフォームで日付を検証するにはどうすればよいですか?

これは私のフォームクラスである:ここで

<?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); 
    } 
} 

は図である。ここでは

<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> 

はコントローラです:

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; 
} 

私はMariaDB(同じを使用していますMySQL)。私は、日付の "addValidator"を検索しようとしているが、おそらく他の問題です。どんな援助も歓迎されるだろう。

+1

​​ – Timothy

答えて

関連する問題