[TYPO3-mvc] Extbase: No way to store NULL / leave form fields empty?

g4-lisz at tonarchiv.ch g4-lisz at tonarchiv.ch
Sun Apr 12 09:25:43 CEST 2015


Hi everyone!

This is a double posting  (also in TYPO3-German) and some people get
will get angry - but only because they don't know an answer to it...

I try to save NULL values in a DB table form Extbase.
What I want to achieve is this: In a (Fluid) web form, there are lots of
input fields for numeric values. But they are not mandatory, so the user
can left them emtpy.
In my saveAction I need to know if the user filled out this fields or
left them empty by purpose.

The issue is that Extbase always fills empty numeric fields in the DB
table with '0' (zero).  So there is no way to distinguish if someone
filled in '0' values or left the field emtpy.

I tried different things:

- Set the DB field properties to NULL by default, like:
  mw double (10,2) DEFAULT NULL

- Set the model class property to NULL by default:
  /**
   * mw
   *
   * @var float
   */
 protected $mw = null;

- Tried different TCA configs like:
  "eval" => "null, double"
  "default"  =>"null"
  "default"  => null

I did this check to assure that NULL is handled over to the getter for
empty form fields:

  public function setMw($mw) {
          if ($mw == NULL)
              $this->mw = 999;
          else
              $this->mw = $mw;
  }

999 is written to the DB as expected. That means that NULL is passed to
the setter in case of emtpy form fields.

But $this->mw = $mw; results in '0' DB entries, even if $mw == NULL -
how can this be?

Resumee: 0 !== NULL. Is there any way to reproduce this in Extbase (6.2)?

Cheers,
Till




More information about the TYPO3-project-typo3v4mvc mailing list