Php – TYPO3 Extbase Controller/Model Validation fails

extbasefluidPHPtypo3-flow

Environment: Mac OS X Lion, PHP 5.3.10, MySQL 5.X, TYPO3 4.7.1, Extbase 4.7.1, Fluid 4.7.0

I have been struggeling for a few days with a strange validation error in extbase.

Tx_Foo_Controller_FeUserController contains the two following actions:

    /**
     * @param $feUser
     * @return void
     * @dontvalidate $feUser
     */
    public function registerAction(Tx_Foo_Domain_Model_FeUser $feUser = NULL )

and

    /**
     * @param Tx_Foo_Domain_Model_FeUser $feUser
     * @param string $password2
     * @return void
     */
    public function createAction( Tx_Foo_Domain_Model_FeUser $feUser ,$password2 )

Content of both actions:

$this->view->assign('feUser', $feUser);

The register.html has the following form:

<f:flashMessages />

<f:form.errors>
    <div class="error">
        {error.message}
        <f:if condition="{error.propertyName}">
            <p>
                <strong>{error.propertyName}</strong>:
                <f:for each="{error.errors}" as="errorDetail">
                    {errorDetail.message}
                </f:for>
            </p>
        </f:if>
    </div>
</f:form.errors>        
<f:form object="{feUser}" objectName="feUser" class="form-horizontal" id="fooRegisterForm"
  controller="FeUser" action="create" noCache="1" noCacheHash="1">

     <f:form.textfield type="email" property="email" value="{feUser.email}"/>
    <f:form.textfield property="password" value=""/>
    <f:form.textfield name="password2" value=""/>    
</f:form>

and createAction has just some "OK" text in it.

The problem is: Each time I add an @validate annotation to the createAction() method I'll get this error:
An error occurred while trying to call Tx_Foo_Controller_FeUserController->createAction()

There is no difference if I use a custom validator or a bundled one.

Example for createAction()

     * @validate $password2 Tx_Extbase_Validation_Validator_IntegerValidator

Integer is used to provoke an error.

A custom validator is like Tx_Foo_Domain_Validator_FeUserValidator where you don't have to add the @validation tag.

Custom validator:

/**
 * Validation of given Params
 *
 * @param Tx_Foo_Domain_Model_FeUser $feUser
 * @return void
 */
public function isValid($feUser)
{

    $this->addError('Passwords are not RSA strings', 1297418974 );
    return false;        
}

It doesn't matter if there is a return statement…

I've looked up in Tx_Extbase_MVC_Controller_ActionController -> callActionMethod() and the whole validation process (via var_dump and debug_backtrace and so on) to figure out why this error is happening and why there is no output from the error messages. It's all very strange … so maybe someone has a tipp here 🙂

The same error occurs if I add a @validation tag in the model of my feUser class like
@validate notEmpty

Extbase configuration via typoscript

config.tx_extbase {
    features.rewrittenPropertyMapper = 1
    persistence{
        storagePid = 5
        enableAutomaticCacheClearing = 1
        updateReferenceIndex = 0
        classes {
            Tx_Foo_Domain_Model_FeUser {
                mapping {
                    tableName = fe_users
                    columns {
                        lockToDomain.mapOnProperty = lockToDomain
                    }
                }
            }
        }
    }
}

Thanks a lot in advance.

PS: Sure I googled it a lot before asking here.

Best Answer

In my case this error comes up, because an extbase referrer was missing. If there is no referrer, the default message is thrown by extbase.

Because I had no form but just a link, I have to add the referrer manually:

/index.php?id=10&tx_bieval_pi1[send]=1&tx_bieval_pi1[hash]=12345&tx_bieval_pi1[__referrer][actionName]=index&tx_bieval_pi1[action]=form&tx_bieval_pi1[controller]=Participation

That did the trick

Related Topic