I built multiple webforms in Drupal. I want user to
Submit only ONE submission by form.
Auto load last submission when they go again on webform submitted.
How can I do this?
You could use the email webform component, set it as unique and check the User email as default, if you'd have one in your webform.
Autoloading a webform submission might be possible with by creating a views block with a contextual filters to the user giving the uid provided & a relation to webform.
As you might not want an additional webform component for your webforms (or not all of them), you could always create a module, include the webform functionality and retrieve the submitted data on a webform instance with hook_form_alter() as:
/**
* Implements hook_form_alter().
*/
function YOUR_MODULE_form_alter(&$form, &$form_state, $form_id) {
// get current user
global $user;
// include webform functionality
module_load_include('inc','webform','includes/webform.submissions');
// make sure to only alter webform forms
if (strpos($form_id, 'webform_client_form_') !== FALSE) {
// check if the user is a an authenticated user
if (in_array('authenticated user', $user->roles)) {
// build $filters array for submission retrieval
$filters = array(
'nid' => $form['#node']->webform['nid'],
'uid' => $user->uid,
);
/**
* When not using a unique webform component for 1 submission
* you can use a submission of the user on a webform instance
* to prevent another submission.
*/
// get submissions of the user by webform nid
if ($submissions = webform_get_submissions($filters)) {
// disable the form to limit multiple submissions per instance
$form['#disabled'] = TRUE;
/**
* Webform instance submission data of the current user
* can be found in $submissions[1]->data array
*/
# render your submission with Form api
}
}
}
}
Hope this helps.
Limiting to only 1 submission per webform can be done via Webform -> Form Settings -> Total Submissions Limit and Per User submission limit as shown in this screenshot
To autoload user submission, since above would not allow you to show the webform would be via using the submission id of the webform they already submitted. Based on this code
module_load_include('inc','webform','includes/webform.submissions');
$sid = 10;
$submission = webform_get_submissions(array('sid' => $sid));
$nid = $submission[$sid]->nid;
$web_submission = webform_get_submission($nid, $sid);
$node = node_load($nid);
$output = webform_submission_render($node, $web_submission, NULL, 'html');
print $output;
Related
I am experimenting on botpress slots . There is the new option called as slot which will validate the user input . However I am not able to find resources which will validate the user input.
The bot must validate the use input as a phone number using slot feature or any other without use of external api ?
Is this possible ?
for example:
If the user inputs a valide phone number the flow will proceed.
else if use enters invalid phone number the flow will ask to re enter a valid phone number.
I have tried multiple things but had no luck finding the proper documentation/ tutorial regarding it.
I think you can use a custom action to achieve this. A custom action for validating mobile number may look like:
const baseMessage = {
type: 'text',
markdown: false
}
/**
* check if phone number is valid
* #title validate phone number
* #category Validation
* #author Your name
* #param {string} phone - phone number
*/
const validateNumber = async phone => {
var phoneRegex = /^\d{10}$/
if (phone.match(phoneRegex)) {
temp.phone_validation = 'success'
} else {
temp.phone_validation = 'error'
}
}
return validateNumber(args.phone)
You can call the custom action in your validation flow and redirect user accordingly
I am trying to calculate total amount using logic hook.
I have two modules. Accounts and Payments having 1:M Relationship
I have written logic hook after save in payments module.
$hook_array['after_save'][] = Array(1, 'Update pending amount and paid amount in case', 'custom/modules/Payments/logic_hooks_class.php','logic_hooks_class', 'after_save_method');
Its working if I add Payment directly from payment module. But when I trying to insert Payment in accounts module thorugh payment subpanel then its not calling after save logic hook.
I have also checked with process record logic hook.
Could you please someone help me resolve this. I am using SuiteCRM 7.6.4
Thanks in advance.
Try to use
For more info try this link Click here ....
after_relationship_add
Example
./custom/modules/{module}/logic_hooks.php
$hook_version = 1;
$hook_array = Array();
$hook_array['after_relationship_add'] = Array();
$hook_array['after_relationship_add'][] = Array(
//Processing index. For sorting the array.
1,
//Label. A string value to identify the hook.
'after_relationship_add example',
//The PHP file where your class is located.
'custom/modules/{module}/logic_hooks_class.php',
//The class the method is in.
'logic_hooks_class',
//The method to call.
'after_relationship_add_method'
);
/custom/modules/{module}/logic_hooks_class.php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class logic_hooks_class
{
function after_relationship_add_method($bean, $event, $arguments)
{
// check $arguments.related_module == "Payments"
//logic
}
}
I'm trying to work with two forms in a single controller in Symfony2. The page is displaying a list of e-mail addresses with checkboxes to select them.
The first form is a research form and the second is used to remove e-mail addresses. There is also a pagination in my page.
My problem is that I can't remove an e-mail address with a research when the e-mail address is not displayed in the first page.
public function emailsAction(Request $request, $paginationParams)
{
$searchForm = $this->createForm(new SearchFormType(), null, array());
$searchForm->handleRequest($request);
if ($searchForm->isValid()) {
// FETCH E-MAILS WITH SEARCH
} else{
// FETCH E-MAILS WITHOUT SEARCH
}
// here I slice the result depending on the pagination params
$removeForm = $this->createForm(new RemoveFormType(), null, array(
'emails' => $emails
));
$removeForm->handleRequest($request);
if ($removeForm->isValid())
{
$formData = $removeForm->getData();
// here I remove the e-mails
}
...
$params['remove_form'] = $manageSubscribersForm->createView();
$params['search_form'] = $searchAbonneActuForm->createView();
return $this->renderView('my_template.html.twig', $params);
}
If I understand it correctly, the problem is that my removeForm is created with the spliced array and without the search applied when handling the removeForm.
When I search for a name, say johnsmith, it displays me on page 1, one result which is johnsmith#email.com.
If johnsmith#email.com is on page 2 without search, the removeForm handling my request is created with a spliced array not containing johnsmith, so the removeForm is not considered valid.
How should I do to create my removeForm, taking account of the search done before when submitting the removeForm? Or maybe I'm doing this wrong ?
I'm not a native english speaker so if anything is not clear, feel free to ask.
You can use a hidden field with the current page index, that will help you make your search again.
Or you can use an event listener to modify the form field before the submission for the validation.
I have a Drupal site and a Zend application. The main thing is the Drupal site, where the users are stored & everything.
I want my users to be automatically logged in to the Zend app when they log in on Drupal. The problem is that Drupal changes the session cookie to SESS* where * is some random (EDIT: not random, but based on protocol and domain) string.
Is there any way I can tell Zend to use this cookie as a session identifier and to log the user automatically?
You have to write your own authentication adapter:
class YourApp_Auth_Adapter_DrupalBridge implements Zend_Auth_Adapter_Interface
{
/**
* #return Zend_Auth_Result
*/
public function authenticate()
{
// Check if the Drupal session is set by reading the cookie.
// ...
// Read the current user's login into $username.
// ...
// Create the authentication result object.
// Failure
if (null === $username) {
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, null);
}
// Success
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $username);
}
}
Then process your authentication:
$adapter = new YourApp_Auth_Adapter_DrupalBridge();
$result = Zend_Auth::getInstance()->authenticate($adapter);
if ($result->isValid()) {
// User is logged in
}
I have a one page website that has two seperate forms that need to be posted back to the same page, the problem being, that if I submit one form, the error checking is done on both, so displays error messages for both. What I need is that if form one is submit, only form ones' error messages appear, and not form twos. Is this possible in zend?
It isn't a problem for zend to do - but it is a problem for you to solve!
If you give your form a hidden field, or if you have a field ID unique to one form, you should be able to check which form has been submitted in your controller, then you tell zend which form you want it to check. Something like the following should do the job, it will check for a field with the ID unique_form_one_field which obviously should only be on form one, this could be a hidden field for example:
// Get the forms:
$form1 = $this->_helper->formLoader('form_one');
$form2 = $this->_helper->formLoader('form_two');
// Check if there is a POST:
if (!$request->isPost())
{
// It isn't show the forms:
$this->view->form_one = $form1;
$this->view->form_two = $form2;
}
else
{
// It is, get the POST data:
$post_data = $request->getPost();
// Check if form one has been submitted:
if (isset($post_data['unique_form_one_field']))
{
// Check if form one is valid:
if (!$form1->isValid($post_data))
{
// Its got an error, display the forms again, form one will now be populated with the data and also the error messages:
$this->view->form_one = $form1;
$this->view->form_two = $form2;
}
else
{
// Form one was valid - do what you want to process it:
}
}
else
{
// Check if form two is valid:
if (!$form2->isValid($post_data))
{
// Its got an error, display the forms again, form two will now be populated with the data and also the error messages:
$this->view->form_one = $form1;
$this->view->form_two = $form2;
}
else
{
// Form two was valid - do what you want to process it:
}
}
}