Lime Survey Validate Text Field Equal to Other - forms

I'm asking to the user for double email check, so I have two text fields and I need to know how to validate that the second text field input be equal to the first one.
Maybe somekind of regular expression in the validation field?
Thanks
UPDATE
This basic script solved my need. Select "html source" on the Tiny editor of the second question, where you are asking again for the email and then add.
jQuery(document).ready(
function(){
var first_email = jQuery("#answer496577X323X3572"),
second_email = jQuery('#answer496577X323X3573');
first_email.on('focusout', function(){
email = first_email.val();
});
second_email.on('focusout', function(){
email2 = second_email.val();
if (email2 != email){
alert("Mail input doesn't match");
first_email.focus();
}
});
});
Change the "answer496577X323X3572" by the proper input ID of the fields.

Your system can be easily hijacked with deactivate the javascript. You don't validate via the server. And LimeSurvey can do both : show an error in javascript + validate in PHP (server).
If you use a multiple text question with EMAIL for code, EMAIL for subcode #1 and CONFIRM for #2 : put this in "Question validation equation" advanced settings.
EMAIL_EMAIL == EMAIL_CONFIRM.

Related

Capture HTML Form Responses in Google Sheets and send a Confirmation Email to the Form Submitter

I want the script to send the created html email template email.html to the person who last submitted the form.
Below is the success message I get in the console:
Below is the actual email that is received by the person who submits the form:
The email.html is formatted correctly and appears perfectly when sent manually.
I hope this is reprex enough.
EDIT: Maybe it's easier if I include the code
function sendEmail () {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
var data = ss.getRange(lr,3);
var email = data.getValue();
var message = HtmlService.createTemplateFromFile('email');
var subject = "Test Subject"
GmailApp.sendEmail(email,subject, message);
}
It's not clear why you are using HtmlService.createTemplateFromFile, but from the image it's clear there at least one error, the script misses two methods:
HtmlService.HtmlTemplate.evaluate() to evaluate the Templated HTML
HtmlService.HtmlOutput.getContent() to get the HTML from the HtmlService.HtmlOutput object returned by the previous method.
Another option that looks to be an error is the use of GmailApp.sendEmail(string,string,string) method, as the third parameter should be a string to be used as the email plain text content. If you want to pass HTML, instead use GmailApp.sendEmail(string,string,string, Object)
Related
Emailing Google Sheet range (with or without formatting) as a HTML table in a Gmail message
Sending an email in HTML and plain with a Gmail Apps Script
Google script inject html into html email
References
https://developers.google.com/apps-script/guides/html
https://developers.google.com/apps-script/guides/html/templates
https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String)

Send a personnalised email from a Google Form

I'm starting a new project. I have to send a confirmation email when someone purchases a book with my Google Form. By now, I can send an email when you complete the form but I can't put the name of the buyer and the number of books in the email. F.ex : Hello "John", you gonna receive your "3" books in a week.
I've tried something like this :
function sendEmail(e) {
var formreponse = e.responses;
var itemreponse = formreponse.getItemResponses();
var number= itemreponse[5].getResponse(); //because it's in the 5th columns of the spread sheets
var name= itemreponse[3].getResponse();
And then I just write a simple code like this
var TextToSend = "blablabla" + name + " blabla" + number + ".";
GmailApp.sendEmail(emailTo, subject, TextToSend, options);
But I've got an error message:
Cannot read property 'responses' of undefined.
And I don't know why!
It's very frustrating for me not to be able to finish this simple task.
Issues:
When running this function manually, through the editor, no event object is passed, and so e is undefined. You should not run this function manually.
responses is not a valid Event property of Form submit triggers.
Solution:
Install an onFormSubmit trigger, either manually or programmatically, so that the function will run automatically when the Form is submitted, and e will be populated.
Change e.responses to e.response:
var formreponse = e.response;
Reference:
Event Objects > Google Forms events > Form submit

How to access a data attribute value of a form input server side?

I am sending through a form object to Google Apps Script with:
var formObject = $("#my_form")[0];
google.script.run.processForm(formObject)
The form includes a file input and I have no problem retrieving this and the other input values on the server with something like:
function processForm(formObject) {
var user_name = formObject.userNameInputName;
}
The documentation is clear that GAS can send through a form providing it is the only parameter:
https://developers.google.com/apps-script/guides/html/reference/run#myFunction(...)
My question is:
How do I access a data attribute value of a form input server side?
And to answer this I need to ask a silly question:
What is a "form object"? What is it's structure, what does it "look like" - is it just a JavaScript object or something else? (if I console.log(formObject) client side it just displays the HTML). If I know this I figure I will know how to access the data attribute value correctly.
Edit:
I ended up just adding a hidden input field to the form and setting the val() of it via an on click event before submitting the form, then I could access the value server side with:
function processForm(formObject) {
var user_name = formObject.userNameInputName;
var was_a_data_attribute = formObject.myHiddenInputField;
}

Altering a Drupal form after validation

I have a Drupal 7 form where after submitting it, some validation happens. It is taking the email address and doing a database look-up to see if that user already exists. If the user exists, I need to alter the form that re-renders on the page that normally displays the errors, removing some fields. Basically on the error page, regardless of any other validation errors they would have normally received (First name required, last name required etc.) they would only get one error message that says "that email address is already in the system" and then I no longer want to display ANY of the other fields at this point except the email address field and a file upload field. So I'm having trouble trying to figure out how to alter the form after the first submission based on some validation.
Thanks
What you want to do is add some data to the $form_state variable in your validation function that can inform your form function as to what fields it should provide.
Untested Example:
function my_form($form, &$form_state){
$form['my_field1'] = array('#markup' => 'my default field');
// look for custom form_state variable
if ($form_state['change_fields']) {
$form['my_field2'] = array('#markup' => 'my new field');
}
}
function my_form_validate($form, &$form_state){
// if not valid for some reason {
form_set_error('my_field1','this did not validate');
$form_state['change_fields'] = true;
// }
}

Drupal 7 - Creating dependent autocomplete form fields

I'm wondering if anyone can assist me in updating the code detailed here (http://oif.eafarris.com/blog/pre-fill-cck-node-fields-based-on-a-node-re...) for Drupal 7. The function described in that post is identical to what I'm looking to do on my Drupal 7 site but I'm not well versed enough programmatically to do it myself.
I have a content type Event. On the node creation form for Event, I have an autocomplete field for "Client". Below that are additional fields for name, address, etc. The end result I'm hoping to achieve here is:
User enters client name in the autocomplete Client field.
Entered client name matches an existing client and is selected.
Using the node ID of the selected client, the address fields are then populated automatically.
I have a JSON view with a nid argument which spits out the required fields at the url http://domain.com/json-clients/[nid]. But I am unable to get that info returned to the correct fields on the form.
Below is the code as I've got it modified trying to get it to work with D7. Anyone see the glaring errors and care to assist?
(function ($) {
Drupal.behaviors.sponsorhelper = function () {
$("input[name='field_client[und][0][nid]']").blur(function() {
nidRegEx = /\[nid:(\d+)\]/;
SponsorHelper.fill($(this).attr('value').match(nidRegEx)[1]);
})
};
SponsorHelper.fill = function(nid) {
var url = Drupal.settings.basePath + 'json-clients/' + nid;
jQuery.getJSON(url, function (data, result) {
if (result != 'success') {
return;
}
$("input[name='field_address_1[und][0][value]']")
.attr('value',data.nodes[0].node.field_address_1_value);
$("input[name='field_address_2[und][0][value]']")
.attr('value',data.nodes[0].node.field_address_2_value);
})
};
})(jQuery);
Any help is greatly appreciated.
Thanks.
Instead of writing your own javascript try handling this with a couple of drupal's community modules. Check out:
http://drupal.org/project/conditional_fields
http://drupal.org/project/computed_field/
You can us conditional fields to hide the address until the client info is put in. Then use computed fields to search for the client and auto fill the address fields.