<p>My current workaround: Get the select field directly and set its options to the select field options: </p>

<p><code>{% set donationRecurrenceOptions = craft.fields.getFieldByHandle('donationRecurrence').settings‌​.options %}</code></p>

CC BY-SA 3.0
2017-01-04T22:36:50.943Z
2017-01-04T22:36:50.943Z
tofirius
<p>I have a custom donation form that I'm using that includes some custom Craft fields. Two of those fields are dropdowns which I populated with options from within my Craft admin panel.</p>

<p>Since this is a custom form, it must use Stripe.js, so I have the following lines in my template per the <a href="https://squarebit.co.uk/software/craft/charge/usage/quickstart/using-stripe-js" rel="nofollow noreferrer">tutorial on the SquareBit</a> site:</p>

<pre><code>{% includeJsResource('charge/js/stripe_v2.min.js') %}
{% includeJsResource('charge/js/jquery.charge.js') %}
{% includejs %}
    $(this).charge();
{% endincludejs %}
</code></pre>

<p>Here are my Payment options that are set inside the <code>&lt;form&gt;</code> declaration:</p>

<pre><code>{% set chargePaymentOptions = { 'allowDynamic' : true, 'planCurrency': 'usd', } %}

{{ craft.charge.setPaymentOptions(chargePaymentOptions) }}
</code></pre>

<p>I borrowed some code from the Charge plugin examples for initializing the select fields like so:</p>

<pre><code>{{ forms.selectField({
     label: 'Donation Recurrence',
     name: 'donationRecurrence',
     id: 'donationRecurrence',
     options: (charge is defined ? charge.donationRecurrence.options),
     value: (charge is defined ? charge.donationRecurrence),
     errors: (charge is defined ? charge.getErrors('donationRecurrence'))
}) }}

{{ forms.selectField({
     label: 'Would you like to donate to a specific cause?',
     name: 'donationDesignation',
     id: 'donationDesignation',
     options: (charge is defined ? charge.donationDesignation.options),
     value: (charge is defined ? charge.donationDesignation),
     errors: (charge is defined ? charge.getErrors('donationDesignation'))
}) }}
</code></pre>

<p>As you can see, the select fields get their options from the aforementioned pre-populated custom Craft fields. Those options do <em>not</em> show up on <em>first</em> page load, but if the form is subsequently submitted and comes back with errors, then the select field options appear.</p>

<p>I figured out that on the first page load, doing a <code>dump(charge)</code> shows that the <code>charge</code> object does not exist until the page has been reloaded after the form was submitted.</p>

<p>Thanks for any help.</p>

CC BY-SA 3.0
2017-01-04T19:26:58.430Z
My current workaround, get the field directly and set this to the select field options:
`{% set donationRecurrenceOptions = craft.fields.getFieldByHandle('donationRecurrence').settings.options %}`
tofirius
CC BY-SA 3.0
2017-01-04T22:06:59.460Z
Would you mind adding your workaround as an answer, @tofirius?
Brad Bell
<plugins><plugin-charge>
Charge object not available on first page load
# Charge object not available on first page load

(Asked by: username_0 on 2017-01-03)

I have a custom donation form that I'm using that includes some custom Craft fields. Two of those fields are dropdowns which I populated with options from within my Craft admin panel.
Since this is a custom form, it must use Stripe.js, so I have the following lines in my template per the tutorial on the SquareBit site:
{% includeJsResource('charge/js/stripe_v2.min.js') %}
{% includeJsResource('charge/js/jquery.charge.js') %}
{% includejs %}
    $(this).charge();
{% endincludejs %}

Here are my Payment options that are set inside the  declaration:
{% set chargePaymentOptions = { 'allowDynamic' : true, 'planCurrency': 'usd', } %}

{{ craft.charge.setPaymentOptions(chargePaymentOptions) }}

I borrowed some code from the Charge plugin examples for initializing the select fields like so:
{{ forms.selectField({
     label: 'Donation Recurrence',
     name: 'donationRecurrence',
     id: 'donationRecurrence',
     options: (charge is defined ? charge.donationRecurrence.options),
     value: (charge is defined ? charge.donationRecurrence),
     errors: (charge is defined ? charge.getErrors('donationRecurrence'))
}) }}

{{ forms.selectField({
     label: 'Would you like to donate to a specific cause?',
     name: 'donationDesignation',
     id: 'donationDesignation',
     options: (charge is defined ? charge.donationDesignation.options),
     value: (charge is defined ? charge.donationDesignation),
     errors: (charge is defined ? charge.getErrors('donationDesignation'))
}) }}

As you can see, the select fields get their options from the aforementioned pre-populated custom Craft fields. Those options do not show up on first page load, but if the form is subsequently submitted and comes back with errors, then the select field options appear.
I figured out that on the first page load, doing a dump(charge) shows that the charge object does not exist until the page has been reloaded after the form was submitted.
Thanks for any help.

**Tags:** plugins, plugin-charge
> **Comments:**
> **username_0**: My current workaround, get the field directly and set this to the select field options: `{% set donationRecurrenceOptions = craft.fields.getFieldByHandle('donationRecurrence').settings.options %}`  
> **username_1**: Would you mind adding your workaround as an answer, @tofirius?  

---

## 1 answers

### Answer by username_0 on 2017-01-04. Score: 1

My current workaround: Get the select field directly and set its options to the select field options:

`{% set donationRecurrenceOptions = craft.fields.getFieldByHandle('donationRecurrence').settings‌​.options %}`


---

