Answers.Body: <h3>Twig</h3>
  <p>You can check for certain URL parameters via</p>
  <pre><code>{% set param = craft.app.getRequest().getParam('id') %}
  {% if param is not null %}
      {% set entry = craft.app.getElements().getElementById(param) %}
      {# insert your new field value! not the label, the value/handle
      {% do entry.setFieldValue('fieldHandle', 'Reserved') %}
      {% do craft.app.getElements().saveElement(entry) %}
  {% endif %}
  </code></pre>
  <p>However I would not recommend doing this in Twig</p>
  <h3>PHP</h3>
  <p>You can see how to use <a href="https://docs.craftcms.com/v2/plugins/variables.html#app" rel="nofollow noreferrer">Template Variables</a> and create your boilerplate at <a href="http://pluginfactory.io" rel="nofollow noreferrer">pluginfactory.io</a></p>
  <pre><code>{% do craft.myAwesomePlugin.saveEntry(entry, {fieldHandle: 'yourValue'}) %}
  </code></pre>
  <p>And your function could be</p>
  <pre><code>public function saveEntry($entry, $attributes = []){
      $entry-&gt;getContent()-&gt;setAttributes($attributes);
      craft()-&gt;entries-&gt;saveEntry($entry);
  }
  </code></pre>
  <p>That's just a &quot;quick&quot; version, I suggest you to take a look at <code>EntriesController</code> to see how Craft handles it in detail</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-26T07:11:11.500Z
Answers.Text: Thanks! I can see by the "craft.app.xxx" that this is Craft 3 code? The project still runs on Craft 2, is this also available in 2?
  Why wouldn't you recommend doing this in Twig?
Answers.UserDisplayName: mdmngz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-26T07:14:55.917Z
Answers.Text: No it does not work in Craft 2 - Twig is a template engine and not supposed to contain to much logic. You only have limited opportunities for error handling so if something unexpected happens you can't handle it really well
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-26T07:30:53.697Z
Answers.Text: Yes, I understand, you asked if I wanted to use Twig or PHP so I thought I had a choice and would avoid PHP if possible :) Can you set me on the way on how to do this with Craft 2? I assume this needs a custom plugin? I'm not afraid to write some PHP code, but just need to know some steps in order to get this done
Answers.UserDisplayName: mdmngz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-26T07:41:45.427Z
Answers.Text: I've edited the answer
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-26T07:03:23.013Z
Answers.LastActivityDate: 2018-06-26T07:41:37.250Z
Answers.LastEditDate: 2020-06-17T08:56:27.903Z
Answers.UserDisplayName: Robin Schambach
Body: <p>So I'm having this entry (a product) that contains a selectbox field with two values:</p>
  
  <ul>
  <li>Reserved</li>
  <li>Available</li>
  </ul>
  
  <p>By default this field is set to 'Available', but when the user lands on a certain page (a thank you page after "ordering" this product with the entry id as a querystring in the URL), I'd like to change the value of that selectbox to 'Reserved'.</p>
  
  <p>Anyone can put me in the right direction on this one?</p>
  
  <p>Thanks in advance!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-25T20:14:07.150Z
Comments.Text: Do you want to resave the entry or just want to display certain things based on url parameter? Do you want it to save automatically or do you want to create a form?
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-25T21:00:09.457Z
Comments.Text: Resaving the entry automatically at page load of the "/thank-you?id=33" page (with 33 being the entry id of that product)
Comments.UserDisplayName: mdmngz
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-25T21:00:58.300Z
Comments.Text: Do you want to use twig or would you use PHP for it?
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-26T06:59:32.833Z
Comments.Text: Twig, please! If PHP can be avoided, the better :)
Comments.UserDisplayName: mdmngz
Tags: <frontend><saveentry>
Title: How do I change the value of a select box field of a certain entry through the front-end?
ThreadText: # How do I change the value of a select box field of a certain entry through the front-end?
  
  (Asked by: username_0 on 2018-06-25)
  
  So I'm having this entry (a product) that contains a selectbox field with two values:
  
  * Reserved
  * Available
  
  By default this field is set to 'Available', but when the user lands on a certain page (a thank you page after "ordering" this product with the entry id as a querystring in the URL), I'd like to change the value of that selectbox to 'Reserved'.
  
  Anyone can put me in the right direction on this one?
  
  Thanks in advance!
  
  **Tags:** frontend, saveentry
  
  > **Comments:**
  > **username_1**: Do you want to resave the entry or just want to display certain things based on url parameter? Do you want it to save automatically or do you want to create a form?  
  > **username_0**: Resaving the entry automatically at page load of the "/thank-you?id=33" page (with 33 being the entry id of that product)  
  > **username_1**: Do you want to use twig or would you use PHP for it?  
  > **username_0**: Twig, please! If PHP can be avoided, the better :)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-06-26. Score: 1
  
  ### Twig
  
  You can check for certain URL parameters via
  
  ```
  {% set param = craft.app.getRequest().getParam('id') %}
  {% if param is not null %}
      {% set entry = craft.app.getElements().getElementById(param) %}
      {# insert your new field value! not the label, the value/handle
      {% do entry.setFieldValue('fieldHandle', 'Reserved') %}
      {% do craft.app.getElements().saveElement(entry) %}
  {% endif %}
  
  ```
  
  However I would not recommend doing this in Twig
  
  ### PHP
  
  You can see how to use [Template Variables](https://docs.craftcms.com/v2/plugins/variables.html#app) and create your boilerplate at [pluginfactory.io](http://pluginfactory.io)
  
  ```
  {% do craft.myAwesomePlugin.saveEntry(entry, {fieldHandle: 'yourValue'}) %}
  
  ```
  
  And your function could be
  
  ```
  public function saveEntry($entry, $attributes = []){
      $entry->getContent()->setAttributes($attributes);
      craft()->entries->saveEntry($entry);
  }
  
  ```
  
  That's just a "quick" version, I suggest you to take a look at `EntriesController` to see how Craft handles it in detail
  
  > **Comments:**
  > **username_0**: Thanks! I can see by the "craft.app.xxx" that this is Craft 3 code? The project still runs on Craft 2, is this also available in 2? Why wouldn't you recommend doing this in Twig?  
  > **username_1**: No it does not work in Craft 2 - Twig is a template engine and not supposed to contain to much logic. You only have limited opportunities for error handling so if something unexpected happens you can't handle it really well  
  > **username_0**: Yes, I understand, you asked if I wanted to use Twig or PHP so I thought I had a choice and would avoid PHP if possible :) Can you set me on the way on how to do this with Craft 2? I assume this needs a custom plugin? I'm not afraid to write some PHP code, but just need to know some steps in order to get this done  
  > **username_1**: I've edited the answer  
  
  ---
  
  