Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a description how to update a record with a lookup in a free form #73

Merged
merged 6 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions datapress/Forms/create-form.md

This file was deleted.

41 changes: 41 additions & 0 deletions datapress/Forms/custom-forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Make sure to define your form between the `<form></form>` tags. The form submiss

To link a form control to a corresponding table column, specify the logical name of the column in the HTML column `name`, e.g. `emailaddress1` for Email.

[Read more about a form with a lookup](../knowledge_base/lookup/lookup_free.md)

## Protect form submissions with reCAPTCHA

To prevent spam submissions from getting into your CRM, add reCAPTCHA to your form. Add `recaptcha=true` to the list of `{% raw %}{% form %}{% endraw %}` parameters, and add the `<recaptcha>` placeholder to a desired place in your form.
Expand Down Expand Up @@ -110,6 +112,45 @@ Before you start using reCAPTCHA in your forms, please configure reCAPTCHA in th
{% endform %}
```

## Create a Contact Us form

The plugin provides a Gutenberg block, "Dataverse Plain". It accepts Twig code and renders it as HTML at front-end.
Custom forms allow creating new Dataverse / Dynamics 365 rows, as well as updating existing rows.

```php
{% form entity="lead" mode="create" recaptcha=true %}
<form>
<div class="form-group">
<label>
First Name:
<input class="form-control" name="firstname">
</label>
</div>
<div class="form-group">
<label>
Last Name:
<input class="form-control" name="lastname">
</label>
</div>
<div class="form-group">
<label>
Email:
<input class="form-control" name="emailaddress1">
</label>
</div>
<div class="form-group">
<recaptcha>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Send</button>
</div>
</form>
{% endform %}
```

The `{% form %}` Twig tag lets you configure the form settings, such as target table, submission mode (create or update), etc.
Form control `name` columns refer to the corresponding table columns, such as `firstname`, `lastname` and `emailaddress1`. Put the `<recaptcha>` placeholder where you want to put reCAPTCHA control if you enable reCAPTCHA on your form. Before you use reCAPTCHA, please configure it in plugin settings.

### Getting row GUID

After the row has been successfully created, you can get the guid using the redirect setting with the %s parameter.
Expand Down
41 changes: 2 additions & 39 deletions datapress/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,46 +99,9 @@ Go to your WordPress Admin Area and access the *Integration Dataverse* menu. Sw

Now the plugin is connected to CRM, and you can start building the integration.

## Create a Contact Us form
## Create a form

The plugin provides a Gutenberg block, "Dataverse Plain". It accepts Twig code and renders it as HTML at front-end. To create your first form, you can use the [custom form syntax](/datapress/Forms/custom-forms.md). It allows creating HTML forms and capturing submissions into your Dataverse or Dynamics 365 organization.

Custom forms allow creating new Dataverse / Dynamics 365 records, as well as updating existing records. reCAPTCHA is supported to protect your forms from spam.

```php
{% form entity="lead" mode="create" recaptcha=true %}
<form>
<div class="form-group">
<label>
First Name:
<input class="form-control" name="firstname">
</label>
</div>
<div class="form-group">
<label>
Last Name:
<input class="form-control" name="lastname">
</label>
</div>
<div class="form-group">
<label>
Email:
<input class="form-control" name="emailaddress1">
</label>
</div>
<div class="form-group">
<recaptcha>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Send</button>
</div>
</form>
{% endform %}
```

The `{% form %}` Twig tag lets you configure the form settings, such as target entity, submission mode (create or update), etc. See [custom forms documentation](/datapress/Forms/custom-forms.md).

Form control `name` attributes refer to the corresponding entity attributes, such as `firstname`, `lastname` and `emailaddress1`. Put the `<recaptcha>` placeholder where you want to put reCAPTCHA control if you enable reCAPTCHA on your form. Before you use reCAPTCHA, please configure it in plugin settings.
The plugin provides a Gutenberg block, "Dataverse Plain". To create your first form, you can use the [custom form syntax](/datapress/Forms/custom-forms.md).

## Install Premium Features

Expand Down
90 changes: 89 additions & 1 deletion datapress/knowledge_base/lookup/lookup_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tags:
keywords: [DataPress lookup]
---

To create a form with a lookup field you can follow next example
To `create` a form with a lookup field you can follow next example

```
{% fetchxml collection="contacts" %}
Expand Down Expand Up @@ -54,4 +54,92 @@ To create a form with a lookup field you can follow next example
</entity>
</fetch>
{% endfetchxml %}
```

To use `hidden` fields pay attention to this example
```
<input type="hidden" name="contactid" value="contact:{{ contact.contactid }}" />
<input type="hidden" name="accountid" value="account:{{ contact.parentaccount.Id }}" />
```

To `display` a record with a lookup via a form using free plugin you can follow 2 ways:

1. serialised lookup (recommended)
In this approach, you’ll serialize the lookup value and store it in a field on your form. When the form is submitted, this serialized value is used to update the corresponding record.
```
{% fetchxml collection="contacts" %}
<fetch mapping='logical' returntotalrecordcount='true'>
<entity name='contact'>
<attribute name='contactid' />
<attribute name='fullname' />
</entity>
</fetch>
{% endfetchxml %}

{% set currentRecord=entities.account['0a7e4fb6-a6f1-ee11-904b-000d3a6a6eca'] %}
{% set contactref = {"LogicalName": "contact", "Id": contactid } %}
{% form entity="account" mode="update" record=currentRecord|to_entity_reference cache='PT1M' %}
<form>
<div class="form-group">
<label>
Name:
<input class="form-control" name="name" value="{{ currentRecord["name"] }}">
</label>
</div>
<div class="form-group">
<label>
Contact:
<select class="form-control custom-select" name="contactid">
{% for contact in contacts.results.entities %}
<option value='{{contactref}}'>{{ contact.fullname }} </option>

{% endfor %}
</select>

</label>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Send</button>
</div>
</form>
{% endform %}
```

2. table:guid
In this approach, you directly use the GUID value from the lookup field to update the record.
```
{% fetchxml collection="contacts" %}
<fetch mapping='logical' returntotalrecordcount='true'>
<entity name='contact'>
<attribute name='contactid' />
<attribute name='fullname' />
</entity>
</fetch>
{% endfetchxml %}

{% set currentRecord=entities.account['0a7e4fb6-a6f1-ee11-904b-000d3a6a6eca'] %}
{% form entity="account" mode="update" record=currentRecord|to_entity_reference cache='PT30M' %}
<form>
<div class="form-group">
<label>
Name:
<input class="form-control" name="name" value="{{ currentRecord["name"] }}">
</label>
</div>
<div class="form-group">
<label>
Contact:
<select class="form-control custom-select" name="contactid">
{% for contact in contacts.results.entities %}
<option value='contact:{{ contact.Id }}'>{{ contact.fullname }} </option>
{% endfor %}
</select>

</label>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Send</button>
</div>
</form>
{% endform %}
```
12 changes: 8 additions & 4 deletions datapress/twig.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,11 @@ Dataverse Integration provides several Dataverse-specific and general purpose Tw
"Content-Type": "text/html; charset=utf-8",
"Cache-Control": "max-age=604800"
}
) -- returns URL to the image stored in the specified Dataverse image column.
)
```
-- returns URL to the image stored in the specified Dataverse image column.

```php
- file_url(
record,
column,
Expand All @@ -194,12 +197,13 @@ Dataverse Integration provides several Dataverse-specific and general purpose Tw
"Content-Type": "text/html; charset=utf-8",
"Cache-Control": "max-age=604800"
}
) -- returns download URL for the file stored in the specified Dataverse file column.
)
```
-- returns download URL for the file stored in the specified Dataverse file column.

- `last_error()` - returns last error generated by the Twig provider.

- `entity_url( record, postId = null )` -- {% include icds_premium.html %} returns URL to the website page with the given entity record bound to it. Uses [Table Binding](/datapress/binding/table-binding.md) feature. If more than one WordPress post is bound to the table, you can pass post ID to link to a different page instead.
```
- `entity_url( record, postId = null )` -- returns URL to the website page with the given entity record bound to it. Uses [Table Binding](/datapress/binding/table-binding.md) feature. If more than one WordPress post is bound to the table, you can pass post ID to link to a different page instead. <Highlight color="#25c2a0">Premium feature! </Highlight>

## Templates usage

Expand Down