Title: Custom form &#8211; select entity
Last modified: March 12, 2023

---

# Custom form – select entity

 *  Resolved [flagada](https://wordpress.org/support/users/flagada/)
 * (@flagada)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/custom-form-select-entity/)
 * Hello,
 * I’m new to the plugin.
   I created a custom form to create new contacts.In this
   form, I want to display a dropdown list for contacts to choose their nationality.
   I get the list of nationalities via a FetchXML query that I display in the select
   tag.The nationality field in the crm is linked to an entity, emn_nationalite.
   In the contact entity, the nationality field is called “emn_nationalite_id”.In
   the entity nationality, the ID is in the field “emn_nationalite_id” and the name
   of the nationality corresponds to the field “emn_name”.The contact is created
   well when I submit the form but the nationality field remains empty in the CRM.
   How can I ensure that the nationality is correctly transmitted to the CRM?
 * Here is my code:
 *     ```wp-block-code
       [msdyncrm_twig]
       {% form entity="contact" mode="create" required=["lastname", "emailaddress1", "description"] %}
       <form method="POST">
       <label for="firstname">First Name:</label>
       <input name="firstname" required="" placeholder="First Name">
       <label for="lastname">Last Name:</label>
       <input name="lastname" required="" placeholder="Last Name">
       <label for="mobilephone">Phone Number:</label>
       <input name="mobilephone" type="tel" placeholder="Phone Number">
       <label for="emailaddress2">email:</label>
       <input name="emailaddress2" type="tel" placeholder="email">
       <label for="nationalite">Nationalité:</label>
       <select name="emn_nationalite_id">
        {% for a in nartionality.results.entities %}
               <option value ="{{a.emn_nationaliteid}}">{{a.emn_name}}</option>
             {% endfor %}
       </select>
   
       <button type="submit">Submit</button>
       </form>
       {% endform %}
   
       [/msdyncrm_twig]
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [alexacrm](https://wordpress.org/support/users/alexacrm/)
 * (@alexacrm)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/custom-form-select-entity/#post-16552536)
 * Hi [@flagada](https://wordpress.org/support/users/flagada/)
 * the value for a lookup needs to be a serialized entity reference. Try this code:
 *     ```wp-block-code
       <select name="emn_nationalite_id">
        {% for a in nartionality.results.entities %}
          {% set nationalite = {LogicalName: "emn_nationalite", Id: a.emn_nationaliteid, DisplayName: a.emn_name } %}
           <option value='{{nationalite | json_encode}}'>{{a.emn_name}}</option>
             {% endfor %}
       </select>
       ```
   
 * You may want to add `raw` filter if values do not come across correctly when 
   containing characters requiring escaping: `value ="{{nationalite | json_encode
   | raw }}"`. See [twig documentation](https://twig.symfony.com/doc/3.x/) on autoescaping
   and raw.
 * Hope it helps
   AlexaCRM Support
 *  Thread Starter [flagada](https://wordpress.org/support/users/flagada/)
 * (@flagada)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/custom-form-select-entity/#post-16553171)
 * Thank you for your quick answer, it works!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom form – select entity’ is closed to new replies.

 * ![](https://ps.w.org/integration-dynamics/assets/icon-256x256.png?rev=1589904)
 * [Dynamics 365 Integration](https://wordpress.org/plugins/integration-dynamics/)
 * [Support Threads](https://wordpress.org/support/plugin/integration-dynamics/)
 * [Active Topics](https://wordpress.org/support/plugin/integration-dynamics/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/integration-dynamics/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/integration-dynamics/reviews/)

## Tags

 * [form](https://wordpress.org/support/topic-tag/form/)
 * [lookup](https://wordpress.org/support/topic-tag/lookup/)
 * [submit](https://wordpress.org/support/topic-tag/submit/)
 * [value](https://wordpress.org/support/topic-tag/value/)

 * 2 replies
 * 2 participants
 * Last reply from: [flagada](https://wordpress.org/support/users/flagada/)
 * Last activity: [3 years, 3 months ago](https://wordpress.org/support/topic/custom-form-select-entity/#post-16553171)
 * Status: resolved