Creating a customer from the 'customer' form.

Highlighted
Shopify Partner
1 0 1

If you look in most themes there is a template for a newsletter subscription. It will have something like this: 

{% form 'customer' %}
      {{ form.errors | default_errors }}
      {% if form.posted_successfully? %}
        <p class="note form-success">{{ 'general.newsletter_form.confirmation' | t }}</p>
      {% else %}
        <input type="hidden" name="contact[tags]" value="newsletter">
        <input type="email" value="{% if customer %}{{ customer.email }}{% endif %}" placeholder="{{ 'general.newsletter_form.newsletter_email' | t }}" name="contact[email]" id="Email" class="input-group-field" aria-label="{{ 'general.newsletter_form.newsletter_email' | t }}" autocorrect="off" autocapitalize="off">
        <input type="submit" class="btn" name="subscribe" id="subscribe" value="{{ 'general.newsletter_form.submit' | t }}">
      {% endif %}
    {% endform %}

This allows you to create a 'customer', where only the email is set. I am attempting to utilize this functionality for a giveaway my store is running. However, I want to also allow customers to provide a name and opt-in for future marketing. By default, this newsletter form sets it. 

 

I have tried a million things and cannot get my form to set the [accepts_marketing] field to false. No matter what it is always true. I have seen several forums where people have had success implementing this on the 'create_customer' form that is found on customer/registration.liquid. 

 

Here is my most recent attempt, but I have tried several others, does anyone know if this is just simply blocked by the 'customer' form and there is no overriding it? 

{% form 'customer' %}

      {{ form.errors | default_errors }}
      {% if form.posted_successfully? %}
        <p class="note form-success">Thank you for participating in our contest!</p>
      {% else %}

      <label for="FirstName" class="label--hidden">{{ 'customer.register.first_name' | t }}</label>
      <input type="text" name="contact[first_name]" id="FirstName" placeholder="{{ 'customer.register.first_name' | t }}" {% if form.first_name %}value="{{ form.first_name }}"{% endif %} autocapitalize="words" autofocus>

      <label for="LastName" class="label--hidden">{{ 'customer.register.last_name' | t }}</label>
      <input type="text" name="contact[last_name]" id="LastName" placeholder="{{ 'customer.register.last_name' | t }}" {% if form.last_name %}value="{{ form.last_name }}"{% endif %} autocapitalize="words">

      <label for="Email" class="label--hidden">{{ 'customer.register.email' | t }}</label>
      <input type="email" name="contact[email]" id="Email" placeholder="{{ 'customer.register.email' | t }}" {% if form.errors contains "email" %} class="error"{% elsif form.email %} value="{{ form.email }}"{% endif %} autocorrect="off" autocapitalize="off">

      <label for="CreateTags" class="label--hidden">Tags</label>
      <input type="hidden" name="contact[tags]" id="CreateTag2" value="This Contest Only">
      
      <div id="accept" class="clearfix inputrow">
        <label for="accepts_marketing" class="login">Mailing List?</label>
        <input type="hidden" name="contact[accepts_marketing]" value="false" />
        <input type="checkbox" name="contact[accepts_marketing]" id="accepts_marketing" class="{% if form.errors contains 'email' %} error{% endif %}" value="true" checked />
      Subscribe to stay updated with new products and offers!
      </div>     

      <p>
        <input type="submit" value="Enter Contest" class="btn" style="width:100%;text-transform:uppercase;">
      </p>
		{% endif %}
    {% endform %}

Any help would be extremely welcome! Thank you.

Highlighted
Shopify Partner
112 3 20

Hi!

I had a similar request for a customer.

In the end, I built a private app to set that flag back in Shopify. 

Hope it helps!

Bogdan

Bogdan | WebShopAssist
User friendly apps with top-rated support
- SKUGen the SKU generator
- DPD Integration
0 Likes
Highlighted
Shopify Partner
1 0 0

How I can add phone number field? I tried but it won't be displayed on customer detail. Can you please help me

0 Likes
Highlighted
Excursionist
21 0 6

Hi @joannakimberlyw 

 

Did you ever get this solved? I don't think 'write an app' is an appropriate solution as its total overkill for just storing a value against a customer record. I've been trawling the forums to understand how to create key:value pairs from a for. There were some posts on `customer[note]` but i couldn't get sufficient documentation on it to get it working.

 

Nathan

Highlighted
Shopify Partner
135 4 57

If this is still relevant, something like https://apps.shopify.com/customr might do the trick.

 

There are actually quite a few different way of going about this, so it that's a no go then reply here and we'll go from there.

0 Likes
Highlighted
New Member
1 0 0

I don't know if this thread is still relevant, but I write my solution 'cause I guess someone might find it useful someday. 
In order to set the [accepts_marketing] field to false you just need to delete the "checked" attribute from the original code. I also set the value to "false" and it works like a charm. 
So the [accepts_marketing] field code should read: 

<input type="checkbox" name="contact[accepts_marketing]" id="accepts_marketing" class="{% if form.errors contains 'email' %} error{% endif %}" value="false" />

(by the way,  many thanks to @joannakimberlyw: I struggled for a whole day with a similar form and didn't manage to get it working till I found her code!) 

0 Likes
Highlighted
New Member
1 0 0

I am also struggling with this issue. It seem like the form will always set it to true. 

I have tried to set the value of the check box to true or false, checked or unchecked, included the hidden input with value "" or "false". Nothing seems to get the accepts marketing to switch to false when the form is submitted. Is there so default setting of a "customer" form that I am up against?

My form is as follows:

 

 

    {% form 'customer' %}
      <div class="sold-out-contact module newsletter-form">
        <div class="sold-out-container newsletter-form-container">

          {% if section.settings.sold_out_title != blank or section.settings.subheading != blank %}
            <div class="">
              {% if section.settings.sold_out_title != blank %}
                <h3 class="module-title">
                  {{ section.settings.sold_out_title | escape }}
                </h3>
              {% endif %}
              {% if section.settings.sold_out_text != blank %}
                <div class="sold-out-sub module-subtitle">
                  {{ section.settings.sold_out_text }}
                </div>
              {% endif %}
            </div>
          {% endif %}

          <div class="module-body">
            <div class="newsletter-form-container">
              {% if form.posted_successfully? %}
                <p class="module-subtitle" style="font-size: 35px;">
                  Registration Complete!
                </p>
              {% else %}
                {% if form.errors %}
                  <div class="newsletter-form-message">
                    {{ form.errors | default_errors }}
                  </div>
                {% endif %}

                <input type="hidden" id="contact_tags" name="contact[tags]" value="registered_product">

                <div class="newsletter-field-wrapper">
                  
                  <div class="input-wrapper">
                    <label class="input-label" for="contact_first_name">First Name</label>
                    <input
                      class="icon-arrow-right"
                      name="contact[first_name]"
                      type="text"
                      placeholder="First Name"
                      aria-label="Order Number">
                  </div>
                  
                  <div class="input-wrapper">
                    <label class="input-label" for="contact_last_name">Last Name</label>
                    <input
                      class="icon-arrow-right"
                      name="contact[last_name]"
                      type="text"
                      placeholder="Last Name"
                      aria-label="Order Number">
                  </div>
                  
                  <div class="input-wrapper">
                    <label class="input-label" for="contact_note_order_number">Order Number <span class="rocky-icon-inline product-info-link info" title="The Order Number can be found on your order confirmation email"></span></label>
                    <input
                      class="icon-arrow-right"
                      name="contact[note][order_number]"
                      type="text"
                      placeholder="Order Number"
                      aria-label="Order Number">
                  </div>

                  <div class="input-wrapper">
                    <label class="input-label" for="contact_email">Email Address</label>
                    <input
                      class="icon-arrow-right"
                      name="contact[email]"
                      type="email"
                      placeholder="{{ 'general.general.email_placeholder' | t }}"
                      aria-label="{{ 'general.general.email_placeholder' | t }}">
                  </div>
                  
                  
                 <div class="input-wrapper">
                    <input type="hidden" name="contact[accepts_marketing]" value="false" />
                    <input
                      class="icon-arrow-right"
                      name="contact[accepts_marketing]"
                      type="checkbox"
                      value="false"
                    >
                   <label class="input-label" for="accepts_marketing">Accept occasional emails from Rocky Talkie</label>
                  </div>

                  
                  <div class="input-wrapper cta-container">
                    <input
                      class="button"
                      name="subscribe"
                      type="submit"
                      value="Register"
                      aria-label="Register" />
                  </div>
                </div>
              {% endif %}
            </div>
          </div>

        </div>
      </div>
    {% endform %}

 

0 Likes