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 7648821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:48:48+00:00 2026-05-31T10:48:48+00:00

I have a Profile form that inherits from sfGuardRegisterForm I have these fields: $this->useFields(

  • 0

I have a Profile form that inherits from sfGuardRegisterForm

I have these fields:

$this->useFields(
    array('first_name', 
          'last_name',
          'email_address',
          'country',
          'language',
          'current_password',
          'new_password',
          'password_again',
    )
);

Required fields are:

email_address, country and language

And the conditions are:

  1. If the email_address is not equal with the current email_address
    then check if it’s unique then save it
  2. If the current_password is the actual password of the user then verify if new_password and password_again are equals and verify that the new_password is not equal to the actual password of the user

I just can’t figure out in how implement this

EDIT

Thanks 1ed your example works but the problem is that I load the user Profile and I fill the fields: 'first_name', 'last_name', 'email_address', 'country', 'language' with the actual logged user so the email_address field will show the email address:

//...
$this->widgetSchema['email_address']->setDefault($this->_user->getEmailAddress());
//...

If the user dont change the email it will always show this message:

An object with the same “email_address” already exist.

I just want to skip that

Also this $this->getObject()->checkPassword() does not works, always show this message:

Incorrect current password.

I use:

$this->_user = sfContext::getInstance()->getUser()->getGuardUser();

To get actual user profile

EDIT2

Thanks again 1ed

This is very weird and I’m getting frustated, this is the situation

  1. I have a “workaround” for this but it does not follow the standard, I can make it works but using sfContext::getInstance()->getUser()->getGuardUser(); and it will be more unnecesary code
  2. If I use new ProfileForm($user) automatically fills all the fields, that’s very good but I can’t setDefault() I can’t set null or empty any field so I can’t use doUpdateObject() because this function only works when the current data is updated, also I have tested overriding bind(), save() etc. without results
  • 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-31T10:48:49+00:00Added an answer on May 31, 2026 at 10:48 am

    email_address uniqueness: you should set unique: true in schema, in sfDoctrineGuardPlugin that’s the case by default, so in BasesfGuardUserForm you should see a unique validator already: sfValidatorDoctrineUnique(array('model' => 'sfGuardUser', 'column' => array('email_address'))

    current_password: you should create a callback type post validator for this

    // in sfGuardRegisterForm::configure()
    
    // these fields can be blank
    $this->getValidator('current_password')->setOption('required', false);
    $this->getValidator('new_password')->setOption('required', false);
    $this->getValidator('password_again')->setOption('required', false);
    
    // check the current password (this validator is not `required` by default)
    $this->mergePostValidator(new sfValidatorCallback(array(
      'callback' => array($this, 'checkPassword'),
    ), array(
      'invalid' => 'Incorrect current password.'
    )));
    
    // add this method to the same form class
    public function checkPassword(sfValidatorBase $validator, array $values, array $arguments)
    {
      // if a new password is given check whether the old one is correct or not and rise an error if not correct
      if(0 != strlen($values['new_password']) && !$this->getObject()->checkPassword($values['current_password']))
      {
        throw new sfValidatorErrorSchema($validator, array(
          'current_password' => new sfValidatorError($validator, 'invalid')
        ));
      }
    
      return $values;
    }
    

    Alternatively you can create a custom post validator, but I think it’s not necessary.

    EDIT:

    If you would like to display empty email address just like the password fields add these to your form class:

    // at form load remove the default value
    protected function updateDefaultsFromObject()
    {
      parent::updateDefaultsFromObject();
    
      if (isset($this['email_address']))
      {
        $this->setDefault('email_address', '');
      }
    }
    
    // before save remove empty email address
    protected function doUpdateObject($values)
    {
      if (isset($values['email_address']) && 0 == strlen($values['email_address']))
      {
        unset($values['email_address']);
      }
    
      parent::doUpdateObject($values);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a profile weblog that contains all our users details (fields seperate from
I have a form that allows a user to update their profile information, but
In my web application I have a user profile page. That page has these
I need add the first_name and last_name fields associated with that User model and
I have a form in my Profile edit view beginning with this line: <%
I have a 'form' that generates a url for a user via javascript. This
Let's say you have a profile page that can only be accessed by the
Hy, I have a profile x, that has a born_date and then i want
Hy! Here is my problem: i have a profile and this profile has for
In my CakePHP 1.2.5 app, I have a Profile model that belongsTo a User

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.