How to make a form with date field? (DD/MM/YYYY)

Asked

Viewed 4,972 times

3

I am a beginner in Kohana and need to make a form with a date field. My form is this:

<?=form::open('controllerInscricao/index')?>
<?php echo form::select('TURMA_codturma', $TURMA_codturma); ?> <br><br>

<div>Matricula: <?=form::input('ALUNO_MATRICULA' );?></div>
<div>Data: </div>
<?php echo '<div'.HTML::attributes($attrs).'>'.$content.'</div>'; ?>
<?=form::submit('btn_submit', 'Salvar') ?>
<?=form::close()?>

How to make a txt field in DD/MM/YYYY format ?

  • 2

    Vacant. You want a text field with the format DD/MM/YYYY, a field for each day month year, or a select?

  • A text field with DD/MM/YYYY format, forgot to specify.

  • 1

    In this case it is a common input, but the filter for DD/MM/YYYY should be done by the JS.

2 answers

6


I recommend the use of datepicker + maskedinput. I use the 1.3.1 version of maskedinput that works on older IE.

Documentation links and downloads:

http://digitalbush.com/projects/masked-input-plugin/

http://jqueryui.com/datepicker/

The code will look something like this:

<input type="text" id="data />

$.datepicker.setDefaults($.datepicker.regional['pt']);

$("#data").mask("99/99/9999");

$('#data').datepicker();

OBS: These two plugins will already save you time in the matter of checking if they were included in the plugin only numbers.

  • I gave UP for the answer itself, however, say that will not need to do any checking, as these two plugins already take account, is a huge misunderstanding. There is no validation on the client side, JS is just a mask. Alias, the name of the plugin is MASK.

  • I agree Papa Charlie, I think I expressed myself badly, I referred to simple validations, how to check if were included only numbers.

  • In this case it falls like a glove and actually kills the checks on the client’s side. Since you edited the question, I will remove the comment above and this one too. OK?

  • 1

    That’s up to you, I would, because it might solve someone else’s.

3

I suggest using the plugin datepicker of jqueryui: http://jqueryui.com/datepicker/

Code example:

// Cria-se um input padrão com um id para identificar ele
<diva>Data: <input type="text" id="datepicker"></div>

And add the script to the bottom of the page:

<script>
$(function() {
  // #datepicker é o seletor para o campo criado
  // datepicker() é o método do plugin que diz que aquele campo
  // deverá obedecer as regras de data
  $('#datepicker').datepicker();
});
</script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.