6

I'm wanting to display a general error message if there are any errors in the validation_errors() array, but if I do something like

if(isset(validation_errors())) { echo 'error'; }

then it returns back and says:

Fatal error: Can't use function return value in write context

Any help would be grand.

valiano
  • 16,433
  • 7
  • 64
  • 79
Cecil
  • 1,609
  • 5
  • 21
  • 26

2 Answers2

20
if(validation_errors() != false) { echo 'error'; }

isset is used to Determine if a variable is set and is not NULL

Read http://php.net/manual/en/function.isset.php

Gaurav
  • 28,447
  • 8
  • 50
  • 80
2

Just echo vadidation_errors()

It will output if there are errors, and nothing if no errors. You don't need if

CappY
  • 1,510
  • 1
  • 17
  • 32
  • What if you want to contain the errors in a div. Not each individual divs, but a wrapping div. In that case you need an if statement – jsheffers Dec 06 '12 at 03:55
  • 2
    @jsheffers You can specify the wrappers in the function params: `validation_errors('
    ', '
    ')`
    – rybo111 May 28 '14 at 16:23