Typo3, Formhander and the eval() of death

I was working on a typo3 site again that uses formhandler. Formhandler advertises it's strength as being usable for building

rock solid, state of the art forms in TYPO3 the easy way.

I'll give the extension that you can build complex forms with it. I wouldn't exactly call it easy or intutive though. I mean, the simple example has you editing stuff in a dozen or so locations. But it's typo3 after all, so it's enterprisy.

But on campaign launch day I found entries in the webserver's error log like:

PHP Parse error:  syntax error, unexpected ')' in /path/to/typo3conf/ext/formhandler/Classes/Controller/Tx_Formhandler_Controller_Form.php(1073) : eval()'d code on line 1, referer: <bla>

What.. the.. eval? Ok, let's check out that code.

$finalCondition = '(' . implode(' || ', $orConditions) . ')';
eval('$evaluation = ' . $finalCondition . ';');

I was flabbergasted why on earth there would be an eval in there. I thought formhandler was supposed to be the good form extension! Rock solid, state of the art, MVC, modular, modern, smart. So why was it trying to eval() what turned out to be "((FALSE))"?

Anyway, from the code it wasn't too hard to figure out what was going on, the $orConditions kind of gives it away as I had just added some conditional form field validation the day before. It turns out the problem lied in a condition like:

isTrue {
  # Make settings for a different step 3
  3 {
    templateSuffix = _alternative
    validators.1.config.disableErrorCheckFields = firstname,lastname,email
  }
}

If you compare this snippet to the example in the docs, you'll see an empty else block there. It turns out formhandler really really wants you to use that empty else block in your typoscript configuration if you don't want formhandler to throw 500s at your users. Typoscript is a declarative configuration language.

Like this:

isTrue {
  # Make settings for a different step 3
  3 {
    templateSuffix = _alternative
    validators.1.config.disableErrorCheckFields = firstname,lastname,email
  }
}
else {
  # Do something if the condition was not true. This will not be needed often.
}

This won't be needed often, but the hell you omit the empty block.

0 comments

Reply

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceUse a maskWorldInternet securityPianoFontGnuPGThunderbirdJenkinshome-assistant-logo