Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 738913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:20:25+00:00 2026-05-14T08:20:25+00:00

I have a form to edit a UserProfile which is stored in mysql db.

  • 0

I have a form to edit a UserProfile which is stored in mysql db. Which includes the following custom configuration:

public function configure()
  {
    $this->widgetSchema['password']=new sfWidgetFormInputPassword();
    $this->validatorSchema['password']->setOption('required', false); // you don't need to specify a new password if you are editing a user.
  }

When the user tries to save the executeUpdate method is called to commit the changes.
If the password is left blank, the password field is set to ”, but I want it to retain the old password instead of overwriting it.

What is the best (/most in the symfony ethos) way of doing this? My solution was to override the setter method on the model (which i had done anyway for password encryption), and ignore blank values.

public function setPassword( $password )
{
  if ($password=='') return false; // if password is blank don't save it.
  return $this->_set('password', UserProfile ::encryptPassword( $password ));
}

It seems to work fine like this, but is there a better way?

If you’re wondering I cannot use sfDoctrineGuard for this project as I am dealing with a legacy database, and cannot change the schema.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:20:26+00:00Added an answer on May 14, 2026 at 8:20 am

    It looks fine to me:

    public function setPassword($password)
    {
      if (!$password) return false;
      return $this->_set('password', UserProfile::encryptPassword($password));
    }
    

    I’ve got a few forms where I need to update sfGuardUser password along with other form fields that relate to different models, and I’ve ended up with something like this:

    $id = // sfGuardUser primary key
    $values['password'] = // the form post value returned
    
    if ($values['password']) {
      $user = Doctrine::getTable('sfGuardUser')->find($id);
      $user->setPassword($values['password']);
      $user->save();
    }
    

    … saves a value if a value was posted in the form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form on a page where the user has inputs to edit
I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>
I have subclassed Form to include some extra functionality, which boils down to a
I have a form in which people will be entering dollar values. Possible inputs:
I have a form with the following HTML below: <form id=course_edit_form name=course_form action=/courses/save method=post>
I have a login.jsp page which contains a login form. Once logged in the
I have an Ajax form, which loads several files; the problem is that Request.Files
I have form area in my view. If I click button A , I
I have form that displays several keywords (standard set of choice lists that changes
I have a form in C# that has a button that, when clicked, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.