Move fields to the bottom of the config form and also rework the submission code as per suggestion from coleman and also ensure that the submit_action and redirect are exposed in the front end metadata
Remove debugging
Revmoe submit action field as no longer required
Make improvements as per Coleman's review
Update text as per Coleamn and fix regex to allos for ? = # & options in urls
Fix Regex to do some wildcard matching
'description' => $perm['description'] ?? NULL,
];
}
-
$dateRanges = \CRM_Utils_Array::makeNonAssociative(\CRM_Core_OptionGroup::values('relative_date_filters'), 'id', 'label');
$data['dateRanges'] = array_merge([['id' => '{}', 'label' => E::ts('Choose Date Range')]], $dateRanges);
<label for="af_config_form_server_route">
{{:: ts('Page:') }}
</label>
- <input ng-model="afform.server_route" name="server_route" class="form-control" id="af_config_form_server_route" pattern="^civicrm\/[-0-9a-zA-z\/_]+$" onfocus="this.value = this.value || 'civicrm/'" onblur="if (this.value === 'civicrm/') this.value = ''" title="{{:: ts('Path must begin with "civicrm/"') }}">
+ <input ng-model="afform.server_route" name="server_route" class="form-control" id="af_config_form_server_route" pattern="^civicrm\/[-0-9a-zA-Z\/_]+$" onfocus="this.value = this.value || 'civicrm/'" onblur="if (this.value === 'civicrm/') this.value = ''" title="{{:: ts('Path must begin with "civicrm/"') }}">
<p class="help-block">{{:: ts('Expose the form as a standalone webpage. (Example: "civicrm/my-form")') }}</p>
</div>
<p class="help-block">{{:: ts('Choose which contact from the search should match the contact being viewed.') }}</p>
</div>
</fieldset>
+ <fieldset>
+
+ <legend>{{:: ts('Submit Actions') }}</legend>
+ <div class="form-group" ng-class="{'has-error': !!config_form.redirect.$error.pattern}">
+ <label for="af_config_redirect">
+ {{:: ts('Post-Submit Page') }}
+ </label>
+ <input ng-model="afform.redirect" name="redirect" class="form-control" id="af_config_redirect" title="{{:: ts('Post-Submit Page') }}" pattern="^((http|https):\/\/|\/|civicrm\/)[-0-9a-zA-Z\/_.]\S+$" title="{{:: ts('Post-Submit Page must be either an absolute url, a relative url or a path starting with CiviCRM') }}"/>
+ <p class="help-block">{{:: ts('Enter a URL or path that the form should redirect to following a successful submission.') }}</p>
+ </div>
+ </fieldset>
</ng-form>
[
'name' => 'permission',
],
+ [
+ 'name' => 'redirect',
+ ],
[
'name' => 'layout',
'data_type' => 'Array',
}
$moduleName = _afform_angular_module_name($params['name'], 'camel');
+ $formMetaData = (array) civicrm_api4('Afform', 'get', [
+ 'checkPermissions' => FALSE,
+ 'select' => ['redirect', 'name'],
+ 'where' => [['name', '=', $params['name']]],
+ ], 0);
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('afform', [
'camel' => $moduleName,
- 'meta' => ['name' => $params['name']],
+ 'meta' => $formMetaData,
'templateUrl' => "~/$moduleName/$moduleName.aff.html",
]);
$mimeType = 'text/javascript';
bindings: {
ctrl: '@'
},
- controller: function($scope, $routeParams, $timeout, crmApi4, crmStatus) {
+ controller: function($scope, $routeParams, $timeout, crmApi4, crmStatus, $window, $location) {
var schema = {},
data = {},
ctrl = this;
this.submit = function submit() {
var submission = crmApi4('Afform', 'submit', {name: ctrl.getFormMeta().name, args: $routeParams, values: data});
+ var metaData = ctrl.getFormMeta();
+ if (metaData.redirect) {
+ submission.then(function() {
+ var url = metaData.redirect;
+ if (url.indexOf('civicrm/') === 0) {
+ url = CRM.url(url);
+ } else if (url.indexOf('/') === 0) {
+ url = $location.protocol() + '://' + $location.host() + url;
+ }
+ $window.location.href = url;
+ });
+ }
return crmStatus({start: ts('Saving'), success: ts('Saved')}, submission);
};
}
'title' => 'Public',
'type' => CRM_Utils_Type::T_BOOLEAN,
];
+ $fields['redirect'] = [
+ 'title' => 'Redirect URL',
+ 'type' => CRM_Utils_Type::T_STRING,
+ ];
}
/**