Body: <p>I am trying to change custom field values of a existing entry, but it won't save them in the database. It saves it on the model but the entry isn't persisted to the database.</p>
  
  <pre><code>craft()-&gt;on('guestEntries.success', function(GuestEntriesEvent $event) {
      if (!$event-&gt;fakeIt)
      {
          $entryModel = $event-&gt;params['entry'];
          if ($entryModel-&gt;section-&gt;handle == "aanvragen")
          {
              $form = $entryModel-&gt;formulier-&gt;first();
              if ($form)
              {
                  // get all entries with that form
                  $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
                  $criteria-&gt;section = "aanvragen";
                  $criteria-&gt;relatedTo = array(
                      'targetElement' =&gt; $form
                  );
  
                  $total = strval($criteria-&gt;total());
  
                  $form-&gt;getContent()-&gt;setAttributes(array(
                      'aantalAanvragen' =&gt; $total
                  ));
  
                  craft()-&gt;entries-&gt;saveEntry($form);
              }
          }
      }
  }
  </code></pre>
  
  <p>This for example <code>$form-&gt;setAttribute('slug', "testtestetst");</code> won't work.
  Is there something i am missing here?</p>
  
  <p>EDIT:</p>
  
  <p>It seems that it was sticking on entry validation upon saving. There are some fields required. However these fields are already filled in, in the CP, i just want to update one field on a EntryModel is there a way to just do this.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-21T08:13:40.490Z
Comments.Text: Spot on, i get it to work with the first method of Brandon here http://craftcms.stackexchange.com/questions/4485/can-someone-help-me-identify-why-my-entry-is-invalidating getting the value first and then resaving it again..thanks
Comments.UserDisplayName: Jacob
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-21T09:52:35.367Z
Comments.Text: That method is not nice, I agree, but it's currently necessary. Fortunatelly Craft 3 will improve on it (if it's true what I heard).
Comments.UserDisplayName: carlcs
Tags: <plugin-development><entrymodel><events><attribute><plugin-guestentries>
Title: Change existing EntryModel custom attribute values
ThreadText: # Change existing EntryModel custom attribute values
  
  (Asked by: username_0 on 2016-04-19)
  
  I am trying to change custom field values of a existing entry, but it won't save them in the database. It saves it on the model but the entry isn't persisted to the database.
  
  ```
  craft()->on('guestEntries.success', function(GuestEntriesEvent $event) {
      if (!$event->fakeIt)
      {
          $entryModel = $event->params['entry'];
          if ($entryModel->section->handle == "aanvragen")
          {
              $form = $entryModel->formulier->first();
              if ($form)
              {
                  // get all entries with that form
                  $criteria = craft()->elements->getCriteria(ElementType::Entry);
                  $criteria->section = "aanvragen";
                  $criteria->relatedTo = array(
                      'targetElement' => $form
                  );
  
                  $total = strval($criteria->total());
  
                  $form->getContent()->setAttributes(array(
                      'aantalAanvragen' => $total
                  ));
  
                  craft()->entries->saveEntry($form);
              }
          }
      }
  }
  
  ```
  
  This for example `$form->setAttribute('slug', "testtestetst");` won't work.
  Is there something i am missing here?
  
  EDIT:
  
  It seems that it was sticking on entry validation upon saving. There are some fields required. However these fields are already filled in, in the CP, i just want to update one field on a EntryModel is there a way to just do this.
  
  **Tags:** plugin-development, entrymodel, events, attribute, plugin-guestentries
  
  > **Comments:**
  > **username_0**: Spot on, i get it to work with the first method of Brandon here http://craftcms.stackexchange.com/questions/4485/can-someone-help-me-identify-why-my-entry-is-invalidating getting the value first and then resaving it again..thanks  
  > **username_1**: That method is not nice, I agree, but it's currently necessary. Fortunatelly Craft 3 will improve on it (if it's true what I heard).  
  
  ---
  
  ## 0 answers
  
  