Answers.Body: <p>Try using <code>setContentFromPost</code>, as mentioned in <a href="https://craftcms.stackexchange.com/a/4487/110">this answer</a> from Brandon.</p>
  
  <pre><code>$content = array(
      'fieldHandle' =&gt; 'value',
  );
  
  $globalSet-&gt;setContentFromPost($content);
  craft()-&gt;globals-&gt;saveContent($globalSet);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-20T13:02:21.870Z
Answers.LastActivityDate: 2015-02-20T13:02:21.870Z
Answers.LastEditDate: 2017-04-13T12:51:00.200Z
Answers.UserDisplayName: Paul
Answers.Body: <p>You can also use a front-end form:</p>
  
  <pre><code>&lt;form method="post"&gt;
    {{ getCsrfInput() }}
    &lt;input type="hidden" name="action" value="globals/saveContent"&gt;
    &lt;input type="hidden" name="setId" value="123"&gt; 
    &lt;input type="text" name="fields[fieldname]" value="{{globalsetslug.fieldname}}"&gt;
    &lt;input type="text" name="fields[anotherfieldname]" value="{{globalsetslug.anotherfieldname}}"&gt;
    &lt;input type="submit" value="Save globals" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Of course you need to replace <code>123</code> by your globals set id and <code>globalsetslug</code> by your globals set slug. You are not required to include all globals set fields in your form, Craft will save only those inside the form.</p>
  
  <p>I know it's an old post, but perhaps this will help others!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-01T05:34:26.587Z
Answers.LastActivityDate: 2017-03-01T05:34:26.587Z
Answers.UserDisplayName: r-ninja
Body: <p>I’m trying to set data within a global set. I’ve tried the following without success:</p>
  
  <pre><code>$globalSetHandle = 'settings';
  $globalSet = craft()-&gt;globals-&gt;getSetByHandle($globalSetHandle);
  
  $globalSet-&gt;fieldHandle = 'value';
  
  craft()-&gt;globals-&gt;saveContent(GlobalSetModel $globalSet);
  </code></pre>
  
Tags: <plugin-development><globals><saving>
Title: How to save a global set’s content?
ThreadText: # How to save a global set’s content?
  
  (Asked by: username_0 on 2015-02-20)
  
  I’m trying to set data within a global set. I’ve tried the following without success:
  
  ```
  $globalSetHandle = 'settings';
  $globalSet = craft()->globals->getSetByHandle($globalSetHandle);
  
  $globalSet->fieldHandle = 'value';
  
  craft()->globals->saveContent(GlobalSetModel $globalSet);
  
  ```
  
  **Tags:** plugin-development, globals, saving
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-02-20. Score: 3 | Accepted answer
  
  Try using `setContentFromPost`, as mentioned in [this answer](https://craftcms.stackexchange.com/a/4487/110) from Brandon.
  
  ```
  $content = array(
      'fieldHandle' => 'value',
  );
  
  $globalSet->setContentFromPost($content);
  craft()->globals->saveContent($globalSet);
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2017-03-01. Score: 0
  
  You can also use a front-end form:
  
  ```
  <form method="post">
    {{ getCsrfInput() }}
    <input type="hidden" name="action" value="globals/saveContent">
    <input type="hidden" name="setId" value="123"> 
    <input type="text" name="fields[fieldname]" value="{{globalsetslug.fieldname}}">
    <input type="text" name="fields[anotherfieldname]" value="{{globalsetslug.anotherfieldname}}">
    <input type="submit" value="Save globals" />
  </form>
  
  ```
  
  Of course you need to replace `123` by your globals set id and `globalsetslug` by your globals set slug. You are not required to include all globals set fields in your form, Craft will save only those inside the form.
  
  I know it's an old post, but perhaps this will help others!
  
  
  ---
  
  