0
votes

My homepage has 2 different forms on it one for registering the user and one for the login. Both forms point to the same model but to different actions. The problem is that if you submit either form it will set off the action on the other form as well, so if I'm trying to login it will set off the registration action in the controller as if I was trying to register, for instance.

I already checked this solution but it seems overly complicated for something so simple, not to mention it will clutter my models folder with extra models that are pretty much useless except for a single action.

EDIT: I do not have this part of my project under Auth, I have admin routing and an admin section setup under Auth, but on the non-admin parts I'm using my own session handling and user validation.

Here is the code for my forms as well:

This is the registration form:

echo $this->Form->create('Fonyker', array('action' => 'add'));
            echo $this->Form->input('username', array(
                'div' => array(
                    'class' => 'span-8'
                ),
                'class' => 'input-text long',
                'id' => 'FonykerUsernameRegister',
                'label' => array(
                    'class' => 'inlined',
                    'text' => ''
                ),
                'placeholder' => 'Username',
                'onsubmit' => 'return false;'
            ));
            echo $this->Form->input('email', array(
                'div' => array(
                    'class' => 'span-8'
                ),
                'class' => 'input-text long',
                'label' => array(
                    'class' => 'inlined',
                    'text' => ''
                ),
                'placeholder' => 'Email',
                'onsubmit' => 'return false;'
            ));
            echo $this->Form->input('password', array(
                'div' => array(
                    'class' => 'span-8'
                ),
                'class' => 'input-text long',
                'id' => 'FonykerPasswordRegister',
                'label' => array(
                    'class' => 'inlined',
                    'text' => ''
                ),
                'placeholder' => 'Password',
                'onsubmit' => 'return false;'
            ));
            echo $this->Form->input('name', array(
                'div' => array(
                    'class' => 'span-8'
                ),
                'class' => 'input-text long',
                'label' => array(
                    'class' => 'inlined',
                    'text' => ''
                ),
                'placeholder' => 'Name',
                'onsubmit' => 'return false;'
            ));
        ?>
        <div class="span-8 required">
            <label for="FonykerBirthdate" class="inlined">From</label>
            <input id="FonykerBirthdate" type="text" onsubmit="return false;" placeholder="Birthdate" name="data[Fonyker][birthdate]" class="datepicker input-text long" enabled="false">
        </div>
        <?php

            $options = array('M' => 'M', 'F' => 'F');
            $attributes = array(
                'empty' => 'Gender',
                'class' => 'input-combo span-8'
            );

            echo $this->Form->select('gender', $options, NULL, $attributes);

            echo $this->Form->submit('',array(
                'class' => 'signup-button', 
                'id' => 'signup-button'
            ));

            echo $this->Form->end();
        ?>

And the login form:

echo $this->Form->create('Fonyker', array('action' => 'login'));
                    echo $this->Form->input('username', array(
                        'div' => array(
                            'class' => 'span-3'
                        ),
                        'class' => 'input-text short',
                        'id' => 'FonykerUsernameLogin',
                        'label' => array(
                            'class' => 'inlined',
                            'text' => ''
                        ),
                        'placeholder' => 'Username'
                    ));
                    echo $this->Form->input('password', array(
                        'div' => array(
                            'class' => 'span-3',
                        ),
                        'class' => 'input-text short',
                        'id' => 'FonykerPasswordLogin',
                        'label' => array(
                            'class' => 'inlined',
                            'text' => ''
                        ),
                        'placeholder' => 'Password'
                    ));

                    echo $this->Form->submit('',array(
                        'div' => array(
                            'class' => 'span-1'
                        ),
                        'class' => 'login-button', 
                    ));

                    echo $this->Form->input('Fonyker.remember', array(
                        'div' => array(
                            'class' => 'span-3',
                        ),
                        'type' => 'checkbox', 
                        'label' => array(
                            'text' => 'Remember me',
                            'style' => 'margin-left:-10px;'
                        ), 
                        'value' => 'yes',
                        'class' => 'span-1'
                    ));

                    echo $this->Html->link(__("Forgot it?", TRUE), array('controller' => "pages", 'action' => "recover_password" ), array('class' => 'span-2'));

                    echo $this->Form->end();
                ?>
1
"if you submit either form it will set off the validations of the other form as well": by 'validation', do you mean model validation, or your code in the controller? just to make sure I understand. - Anh Pham
Are you using Auth / ACL? As I too have a notempty / isunique / min+max length validation on username, and have a login box next to the add users box with no problems... - Shaz Amjad
I will edit my question, I seem to have misexplained myself somewhat - 8vius
Sounds strange. Do your forms happen to be nested? You cannot nest forms in HTML. - bfavaretto
this is not relevant to your question, but you might find this useful: book.cakephp.org/view/1639/options-inputDefaults or change the css to your need. - Anh Pham

1 Answers

0
votes

The problem in the end was simply due to the naming of my forms, you have to make sure the names of both the forms and fields to not overlap if they are from the same controller, and be sure to end the forms properly.