Answers.Body: <p>Are you/how are you validating the values?
  What I found was that it was a validation issue. If a value isn't considered valid, it will be ignored.</p>
  
  <p>For example: </p>
  
  <blockquote>
    <p>Going along with @Stuart Whitehead comments, right here is proof: "AttributeType::String does not apply any validation rules." Which is why that field was not getting populated.</p>
  </blockquote>
  
  <p><a href="https://craftcms.stackexchange.com/questions/8884/save-contact-form-data-to-database">Check out this thread</a> I think it will have everything you are looking for.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-12T14:26:14.683Z
Answers.LastActivityDate: 2015-05-12T14:26:14.683Z
Answers.LastEditDate: 2017-04-13T12:51:00.253Z
Answers.UserDisplayName: Damon
Body: <p>I have a controller function creating attributes for a model from posted data and sending them to a service to save the data.</p>
  
  <p>Everything seems to be working correctly if I do a print_r in the service function before using setAttributes it is returning the posted data correctly with the changed attribute value. However when I use</p>
  
  <pre><code>$record-&gt;setAttributes($model-&gt;getAttributes());
  </code></pre>
  
  <p>The array that is printed after is using the database values so it is not setting the new attribute as the function suggests.</p>
  
  <p>I have read other posts which suggest there may be a bug with the setAttributes function and a work around setting each post item individually (not ideal) plus I have tried this and it produces the same result.</p>
  
  <p>Am I missing something obvious as to why the setAttributes is not updating the $record variable with the new $model attributes?</p>
  
  <p>Cheers </p>
  
Tags: <models><records>
Title: setAttribute Issue
ThreadText: # setAttribute Issue
  
  (Asked by: username_0 on 2015-05-12)
  
  I have a controller function creating attributes for a model from posted data and sending them to a service to save the data.
  
  Everything seems to be working correctly if I do a print\_r in the service function before using setAttributes it is returning the posted data correctly with the changed attribute value. However when I use
  
  ```
  $record->setAttributes($model->getAttributes());
  
  ```
  
  The array that is printed after is using the database values so it is not setting the new attribute as the function suggests.
  
  I have read other posts which suggest there may be a bug with the setAttributes function and a work around setting each post item individually (not ideal) plus I have tried this and it produces the same result.
  
  Am I missing something obvious as to why the setAttributes is not updating the $record variable with the new $model attributes?
  
  Cheers
  
  **Tags:** models, records
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-05-12. Score: 1 | Accepted answer
  
  Are you/how are you validating the values?
  What I found was that it was a validation issue. If a value isn't considered valid, it will be ignored.
  
  For example:
  
  > Going along with @Stuart Whitehead comments, right here is proof: "AttributeType::String does not apply any validation rules." Which is why that field was not getting populated.
  
  [Check out this thread](https://craftcms.stackexchange.com/questions/8884/save-contact-form-data-to-database) I think it will have everything you are looking for.
  
  
  ---
  
  