Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User update form redirects to sign up form if form error #61

Closed
richlove1 opened this issue May 8, 2013 · 4 comments
Closed

User update form redirects to sign up form if form error #61

richlove1 opened this issue May 8, 2013 · 4 comments

Comments

@richlove1
Copy link

If you user the /user route to display the update form, if there is an error it redirects to the create form.

I think the issue is that the registration form and update form both post to /user. The redirection to /user/create is probably there because of the registration form validation but doesn't work for the update form

Not sure on best way to fix... maybe separate post processing for update form, or have a conditional redirect depending on the form id or something?

@richlove1
Copy link
Author

OK so I put in a temporary fix... not sure if it's what we would want but it works....I've put in an error_redirect variable in the user update form then added code to check for this in postIndex() and redirect if present otherwise default to 'user/create'.

public function postIndex()
{
    $user = new User;

    $user->username = Input::get( 'username' );
    $user->email = Input::get( 'email' );
    $user->password = Input::get( 'password' );

    // The password confirmation will be removed from model
    // before saving. This field will be used in Ardent's
    // auto validation.
    $user->password_confirmation = Input::get( 'password_confirmation' );

    // Save if valid. Password field will be hashed before save
    $user->save();

    if ( $user->id )
    {
        // Redirect with success message, You may replace "Lang::get(..." for your custom message.
        return Redirect::to('user/login')
            ->with( 'notice', Lang::get('confide::confide.alerts.account_created') );
    }
    else
    {
        // Get validation errors (see Ardent package)
        $error = $user->errors()->all();

        // Default to redirect to user/create or redirect elsewhere if defined in the form
        $redirectTo = Input::get('error_redirect') ? Input::get('error_redirect') : 'user/create';

        return Redirect::to($redirectTo)
            ->withInput(Input::except('password'))
            ->with( 'error', $error );
    }
}

@richlove1
Copy link
Author

Actually looking at this, I think it's more involved.... postIndex() is trying to handle the create user form submission and the update user form submission. The redirects and messages on success and failure relate to creating a new user, the functionality doesn't stand for the user update.

Not sure if there should be a separate function to handle the update ... although I understand this is supposed to be a restful controller.

I think perhaps this function should be renamed postCreate() and the creation form should submit to that then the functionality in postIndex() should be rewritten to handle the user update form.

(By the way, I'm happy to get involved in code changes but I'm not sure how to do this in terms of sending pull request etc). I've made a few changes here and there locally which I should probably feed back.

@richlove1
Copy link
Author

Think this is also related to #63

@richlove1
Copy link
Author

I was going to add in a postIndex() along the lines of:

/**
 * Updates user
 *
 */
public function postIndex()
{

    $user = Auth::user();
    $user->username = Input::get( 'username' );
    $user->email = Input::get( 'email' );
    $user->password = Input::get( 'password' );
    $user->password_confirmation = Input::get( 'password_confirmation' );*/

    if ( $user->save() )
    {
        ...
    }
    else
    {
        ...
    }
}

but user->save() fails/returns false. Just reading a little about Ardent (I need to read more) and it appears you should just be able to use the form fields but not sure if this allows you to update email/username fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant