Set a Contact Field with JavaScript
Usage
ActiveMember360 provides a function that allows you to set a contact field for the contact associated with the current remote user.
The value specified always overwrites the existing field content. The function cannot be used to append data to a contact field.
The setting of any contact field is immediately effective within WordPress for the the current remote user.
Function
mbr_set_field ( $field, $value )
Parameters
Parameters | Type | Description |
---|---|---|
$field | (string) | Specifies the name of an ActiveCampaign contact field to set. The field can be any custom contact field in ActiveCampaign and any field type. The available field names can be found in ActiveMember360, Utilities, Contact Fields. The upper case version of the Perstag should be used as the field name. Defaults: none. Required: yes. |
$value | (string) | Specifies the value for the ActiveCampaign contact field. Defaults: none. Required: yes. |
When setting multiple selection field types such as list box and checkbox the selections must be separated by a double pipe ||.
Examples
- Text
- Text Area
- Date
- Date/Time
- Dropdown
- List Box
- Radio
- Checkbox
- Hidden
Using this Javascript code snippet in conjunction with a HTML button with the CSS class mbr-set-field-text, when the button is clicked the text field with the Perstag MY_TEXT will be set as Lorem lipsum for the remote user.
<script>
jQuery( document ).ready( function( $ ) {
$( '.mbr-set-field-text' ).click( function() {
mbr_set_field( 'MY_TEXT', 'Lorem lipsum');
} );
} );
</script>
<button class="mbr-set-field-text">
Set field named MY_TEXT (field type text) to Lorem lipsum
</button>
Using this Javascript code snippet in conjunction with a HTML button with the CSS class mbr-set-field-textarea, when the button is clicked the textarea field with the Perstag MY_TEXTAREA will be set as Lorem lipsum for on line 1 and second line for line 2 for the remote user.
<script>
jQuery( document ).ready( function( $ ) {
$( '.mbr-set-field-textarea' ).click( function() {
mbr_set_field( 'MY_TEXTAREA', 'Lorem lipsum\nsecond line.');
} );
} );
</script>
<button class="mbr-set-field-textarea">
Set field named MY_TEXTAREA (field type textarea) to lorem lipsum for line 1
and second line for line 2
</button>
Using this Javascript code snippet in conjunction with a HTML button with the CSS class mbr-set-field-date, when the button is clicked the date field with the Perstag MY_DATE will be set as 2022-08-31 (format yyyy-mm-dd) for the remote user.
<script>
jQuery( document ).ready( function( $ ) {
$( '.mbr-set-field-date' ).click( function() {
mbr_set_field( 'MY_DATE', '2022-08-31');
} );
} );
</script>
<button class="mbr-set-field-date">
Set MY_DATE (field type date) to 2022-08-31
</button>
Using this Javascript code snippet in conjunction with a HTML button with the CSS class mbr-set-field-datetime, when the button is clicked the date time field with the Perstag MY_DATE_TIME will be set as 2022-08-31 06:30:00 for the remote user.
<script>
jQuery( document ).ready( function( $ ) {
$( '.mbr-set-field-datetime' ).click( function() {
mbr_set_field( 'MY_DATE_TIME', '2022-08-31 06:30:00');
} );
} );
</script>
<button class="mbr-set-field-text">
Set field named MY_DATE_TIME field type (field type Date Time) to 2022-08-31
06:30:00
</button>
Using this Javascript code snippet in conjunction with a HTML button with the CSS class mbr-set-field-select when the button is clicked the dropdown field with the Perstag MY_DROPDOWN will be set as Option 3 for the remote user.
<script>
jQuery( document ).ready( function( $ ) {
$( '.mbr-set-field-dropdown' ).click( function() {
mbr_set_field( 'MY_DROPDOWN', 'Option 3');
} );
} );
</script>
<button class="mbr-set-field-select">
Set MY_DROPDOWN (field type dropdown) to Option 3
</button>
Using this Javascript code snippet in conjunction with a HTML button with the CSS class mbr-set-field-multi-select when the button is clicked the list box field with the Perstag MY_LIST_BOX will be set as Option 1||Option 3 for the remote user.
<script>
jQuery( document ).ready( function( $ ) {
$( '.mbr-set-field-list-box' ).click( function() {
mbr_set_field( 'MY_LIST_BOX', 'Option 1||Option 3');
} );
} );
</script>
<button class="mbr-set-field-list-box">
Set MY_LIST_BOX (field type listbox) to Option 1||Option 3
</button>
Using this Javascript code snippet in conjunction with a HTML button with the CSS class mbr-set-field-radio when the button is clicked the radio field with the Perstag MY_RADIO will be set as Option 3 for the remote user.
<script>
jQuery( document ).ready( function( $ ) {
$( '.mbr-set-field-radio' ).click( function() {
mbr_set_field( 'MY_RADIO', 'Option 3');
} );
} );
</script>
<button class="mbr-set-field-radio">
Set MY_RADIO (field type radio) to Option 3
</button>
Using this Javascript code snippet in conjunction with a HTML button with the CSS class mbr-set-field-checkbox when the button is clicked the checkbox field with the Perstag MY_CHECKBOX will be set as Option 1||Option 3 for the remote user.
<script>
jQuery( document ).ready( function( $ ) {
$( '.mbr-set-field-checkbox' ).click( function() {
mbr_set_field( 'MY_CHECKBOX', 'Option 1||Option 3');
} );
} );
</script>
<button class="mbr-set-field-checkbox">
Set MY_CHECKBOX (field type checkbox) to Option 1||Option 3
</button>
Using this Javascript code snippet in conjunction with a HTML button with the CSS class mbr-set-field-hidden when the button is clicked the hidden field with the Perstag MY_HIDDEN will be set as hidden_value for the remote user.
<script>
jQuery( document ).ready( function( $ ) {
$( '.mbr-set-field-hidden' ).click( function() {
mbr_set_field( 'MY_HIDDEN', 'hidden_value');
} );
} );
</script>
<button class="mbr-set-field-hidden">
Set MY_HIDDEN (field type hidden) hidden_value
</button>