<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>

CC BY-SA 3.0
2015-02-20T13:02:21.870Z
2015-02-20T13:02:21.870Z
2017-04-13T12:51:00.200Z
Paul
<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>

CC BY-SA 3.0
2017-03-01T05:34:26.587Z
2017-03-01T05:34:26.587Z
r-ninja
<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>

<plugin-development><globals><saving>
How to save a global set’s content?
# 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 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:

  {{ getCsrfInput() }}
  
   
  
  
  


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!


---

