tags:

views:

204

answers:

2

Hi,

i'm trying to join in the same action the login and the register forms. This is what i'm trying:

modules/miembros/actions.class.php

  public function executeAux(sfWebRequest $request)
  {
        // I execute this action

  }

modules/miembros/templates/auxSuccess.php

<?php include_component('sfGuardRegister', 'register'); ?>
<?php include_component('sfGuardAuth', 'signin'); ?>

modules/miembros/components.class.php

public function executeSignin($request)
{

  if ( $request->isMethod( 'post' ) && ($request-
>getParameter('submit')=='signin') ){

    $this->form->bind( $request->getParameter( 'login' ) );
    if ( $this->form->isValid() ){
      $this->getController()->getActionStack()->getLastEntry()->getActionInstance()->redirect( '@home' );
    }
  }

}

modules/miembros/templates/_signin.php

<form action="<?php echo url_for('miembros/aux?submit=signin') ?>"
method="post">

        <?php echo $form['email_address']->renderLabel() ?>
        <?php echo $form['email_address'] ?>
... 

It's working ok, but i would to know if you have other alternatives.

For example i don't like the line: $this->getController()->getActionStack()->getLastEntry()->getActionInstance()->redirect( '@home' );

Regards

Javi

+1  A: 

you shouldn't process the form in your component , you should do it in your action. the components meant to be reusable views that can get included in other templates (similar to partials, but with some code behind them to sustain more complex data retrieves). If you want to show the form in a component so you can reuse it, you can, but you should handle the form in another action.

matei
I have a new proposal based on your comment.
A: 

Hi again,

thanks to the comment of matei this is my new proposal. What's your opinion now?

modules/miembros/actions/actions.class.php

public function executeAux(sfWebRequest $request)
{
    return $this->renderPartial('aux');
}

modules/miembros/templates/_aux.php

if(!isset($form_register)){

    $form_register = new sfGuardFormRegisterByOthers();
} 

include_partial('sfGuardRegister/register', array('form' => $form_register));


if(!isset($form_signin)){

    $form_signin = new sfGuardFormSigninByEmail();
}

include_partial('sfGuardAuth/signin', array('form' => $form_signin));

modules/sfGuardAuth/templates/_signin

<form action="<?php echo url_for('sfGuardAuth/signin') ?>" method="post">

modules/miembros/sfGuardAuth/actions.class.php

 if ($this->form->isValid())
 {
   //...

 }else{

    return $this->renderPartial('miembros/aux', array('form_signin' => $this->form));

 }

It works also.

Javi