-2

so here is code:

echo "<label>";
echo "  <span>Data nuo: </span>";
echo "  <input id='data' name='data' type='date' pattern='(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))' title='Data ivesti tokiu formatu: 2016-01-01' >"; 
echo "  </label>";

ad then

$field3 = isset( $_POST['data']) ? $_POST['data'] : "";
echo $field3;

so when date is set, I get my chosed date printed, but if date is not set, i get nothing printed, question is, what is default value of date if date is not set? NULL? How to print "Date is not set" if date is not set?

if ($field3 == ????) {
echo "date is not set";
Shadow
  • 33,525
  • 10
  • 51
  • 64
  • `$field3 = isset( $_POST['data']) ? $_POST['data'] : "Nothing printed";echo $field3;` Is that what you are looking for? – JTC Feb 03 '16 at 21:38
  • not really, it gives nothing printed if submit button is not pushed, after pushing it, it prints nothing... – Eimantas Linartas Feb 03 '16 at 21:43
  • You're probably looking for `if ( ! $field3 )` or `if ( empty( $field3 ) )`. You can use `isset( $_POST['data'] )` to see if the field was submitted in the form, but if it is empty, it will be an empty string. [Some details here](http://stackoverflow.com/questions/7191626/isset-and-empty-what-to-use). – Kenney Feb 03 '16 at 21:44
  • Just like any other `` field -- the default value is an empty satring. – Barmar Feb 03 '16 at 22:06

3 Answers3

0

Simply echo the expected data format :

$field3 = isset( $_POST['data']) ? $_POST['data'] : "YYYY-MM-DD";
echo $field3;
Pain67
  • 326
  • 1
  • 9
0

if ($field3 == ????) {

Actually you can use "" instead of ????. But I suggset to do:

if (empty($field3)) {
0

This will do what you want

if empty($field3) {
    echo "date is not set";
}

http://php.net/manual/en/function.empty.php

Jeff
  • 9,076
  • 1
  • 19
  • 20