Reusableforms Set from email to posted email - phpmailer

I have implemented Reusableforms on my site, everything is working fine apart from when I view received emails in the client, the emails are always from 'contact form' with the email 'forms#domain.com'.
How can I change this to display the senders name and email that is posted via the form? Here is the code from the handler.php included with reusableforms.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
Tested working with PHP5.4 and above (including PHP 7 )
*/
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
$validator = $pp->getValidator();
$validator->fields(['Name','Email'])->areRequired()->maxLength(50);
$validator->field('Email')->isEmail();
$validator->field('Message')->maxLength(6000);
$pp->requireReCaptcha();
$pp->getReCaptcha()->initSecretKey('0000000000000000000000000000000');
$pp->sendEmailTo('orders#domain'); // ← Your email here
echo $pp->process($_POST);

I too been looking for help on this very subject.
I have got this to work - by chance - by having two instances of
'$pp = new FormHandler();'.
See my version of the code below.
I do not understand why it works.
<?php
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
/* The next 7 lines must be in this 1st section */
$mailer = $pp->getMailer();
$mailer->IsSMTP();
$mailer->SMTPAuth = true;
$mailer->SMTPSecure ="ssl";
$mailer->Host = "serverxxx.xxxx.com";
$mailer->Username = "contact#xxxxxxx.com";
$mailer->Password = "xxxxxxxxxxxxxx";
/* The next 2 lines work whether in the 1st or 2nd section */
$pp->requireReCaptcha();
$pp->getReCaptcha()->initSecretKey('xxxxxxxxxxxx');
/* Section 2
I do not understand it, but without the 2nd '$pp = new FormHandler()' below,
the SMTP send fails. The reported error is:
Sorry there was an error sending your form.
mail:SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I have tested changing the 2nd $pp to $pp2 and it also works.
*/
$pp = new FormHandler();
/* The next line has to be in this 2nd section.
If it is the last line in top section then it appears to be sent OK
but the email does not actually arrive.
Checking the SMTP logs shows it was never sent.*/
$pp->sendEmailTo(['leslie#xxxxxxxxxxx.com']);
/* The next 2 lines also must be here rather than in 1st section above. */
$mailer = $pp->getMailer();
$mailer->setFrom('contact#xxxxxxx.com','xxxxxxx Contact Form');
echo $pp->process($_POST);

To send a reply to the user email address on a ReusableForm, you'll need to get the value from the handler.php and add that to FormHandler.php above the 'setFrom' function using the addReplyTo function & $_POST global variable:
$this->mailer->addReplyTo($_POST['Email']);
$this->mailer->setFrom($from_email,'Contact Form',false);
These forms still work well in 2021 using PHP 7.3

Related

How to display default value from prompt macro in value prompt CA11?

I was wondering if it is possible to display the default value from a prompt macro in a Value prompt. My prompt macro looks like this "#prompt('pMonth','MUN','[Previous Month]')#"
so my goal in the value prompt would be to have 202103 displayed instead of header text name which I have named "Previous Month"
I tried with an old javascript from Cognos 10 where you desc the Months and specify what index it should pick but the issue with that code is that everytime you try to change to a different month the report re-runs and loops back to to the same Index value.
<script>
var theSpan = document.getElementById("A1");
var a = theSpan.getElementsByTagName("select"); /* This stmt return an array of all value prompts within span */
for( var i = a.length-1; i >= 0; i-- ) /* now loop through the elements */
{ var prompts = a[i];
if( prompts.id.match(/PRMT_SV_/))
{ prompts.selectedIndex = 2; } /* This selects the second options from top */
canSubmitPrompt();
}
</script>
All solutions, tips and ideas are highly appreciated.
Best regards,
Rubrix
For Cognos Analytics, running with full interactivity, you probably need a Page Module. Check out IBM's Scriptable Reports documentation for Cognos Analytics. You'll want to craft your script to use the current parameter value as default (if you can get it), then fail over to your default value from the data. You will probably need to integrate this with a Custom Control to be able to get that default value from the data.

Google Form Search and Pull Spreadsheet Data

Hi I have google spreadsheet that contains customers' ID and their shipping status. I want to create google form where customers are able to input each of their own ID, with the return that the google form shows their shipping status.
I tried to look for solutions in internet but there was no luck. I am not really good in programming, i hope there is answer to this problem without having me to do some hard programming.
The sample case can be seen in here: https://docs.google.com/spreadsheets/d/14vSAeZxEJTzbNLLYEiref6qt-CMqiVi8alheLcIBugM/edit?usp=sharing
Google form should show something a little bit like is shown in cell D1:E3.
Where customers can fill the form with their own customer id, and the google form shows the status.
Consideration
There is no way to respond back in a Google Form directly. You can't show custom validation messages after From submission either.
Proposed solution
What about using email addresses additionally to the customerID to retrieve the shipping status? In this way you can easily build a notification system that will send an email if a matching customer ID is found in your spreadsheet.
To build such system you will have to build a Form with a Trigger.
It is required a bit of programming but I will try to cover the most important parts the best I can:
Adapt your Database structure
Add the customers email addresses in the column C in order to be able to retrieve it using the same customer ID.
| A | B | C |
|----+--------+-------|
| ID | STATUS | EMAIL |
Build the Form Trigger
In the Form you are using click on the 3 dots from the top menu and select Script Editor. Here you will write the code that will power your notification system.
function installTrigger() {
// This function instructs the program to trigger the checkID function whenever a form response is submitted
ScriptApp.newTrigger('checkID')
.forForm(FormApp.getActiveForm())
.onFormSubmit()
.create();
}
function checkID(e) {
// This function will parse the response to use the customer ID to retrieve email address and shipping status from the Spreadsheet Database
var responses = e.response.getItemResponses(); // Gets the form responses
var id = responses[0].getResponse(); // Assuming the first answer (index 0) is the customer ID)
var found = SpreadsheetApp.openById('spreadsheet_id')
.getRange('Sheet1!A1:C8') // The spreadsheet cells range in A1 Notation
.getValues() // Retrieve their values in rows
.filter((row) => row[0] == id); // Filter the rows for the provided customer ID
if (found) {
var status = found[0][1]; //Column B
var email = found[0][2]; //Column C
var subject = "Shipping Status";
var message =
`Hello!
The status of the order number ${id} is: ${status}.`
MailApp.sendEmail(email, subject, message);
}
}
Install the trigger
From the Script Editor top menu run the installTrigger() function: Run>Run function>installTrigger.
You are done
Following these steps you have successfully set up the notification system. Now you can start sharing the Form link and accept responses.
References
Installable Triggers
Mail App

Suitescript 1.0 attendee sublist on event record

I am attempting to add attendee line items on an event record using a user-event suitescript. However when I save the record, it is not adding the attendee from the script.
Any assistance on why this code is not working correctly would be greatly appreciated!
Your code mixes dynamic/client and standard record access mode.
For a user event before submit script you don't need the insert call. Just:
var newAt = nlapiGetLineItemCount('attendee') + 1;
nlapiSetLineItemValue('attendee', 'attendee', newAt, '95001');
For a user event after submit script similar but:
var eventRec = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId());
var newAt = eventRec.getLineItemCount('attendee') + 1;
eventRec.setLineItemValue('attendee', 'attendee', newAt, '95001');
//add more?
nlapiSubmitRecord(eventRec);

"Field Name was not found in the send source"

I'm a bit new to ExactTarget in general so I apologize if this has already been answered (if it has, I can't find it anywhere).
I am attempting to create an email which will conditionally display n of 50 bulleted lists containing links to product information. However, whenever I attempt to send this email, I receive the following error message:
Other errors found in the email.
Category: AMP Script
Functions and Custom Objects:('
Field Name %%F50%% was not found in the send source.
Category: AMP Script
The second paragraph of the error message is repeated 50 times total (one for each field).
I cannot seem to figure-out why this issue is occurring:
I have a Data Extension with data for each field mapped in it.
I have imported valid data from a CSV to the data extension.
I have a list of valid subscribers to whom I am attempting to distribute.
I have an email template with custom areas inside each of which check if the subscriber has a "true" value for each field and shows/hides the content snippets on that basis.
I have 50x content snippets (one for each field).
There has to be something I'm missing here. Any ideas?
Thanks!
If the 50 fields are not in your sending data extension, you'll need to retrieve them with a script something like this. Note the values are displayed with%%=v(#DEColumn1)=%%:
%%[
var #rows, #row, #rowCount, #numRowsToReturn, #lookupValue, #i
set #lookupValue = "whee"
set #numRowsToReturn = 0 /* 0 means all */
set #rows = LookupOrderedRows("DataExtensionName",#numRowsToReturn,"DEColumn1 desc, DEColumn2 asc","LookupColumn", #lookupValue)
set #rowCount = rowcount(#rows)
if #rowCount > 0 then
for #i = 1 to #rowCount do
var #DEColumn1, #DEColumn2
set #row = row(#rows,#i) /*get row based on loop counter */
set #DEColumn1 = field(#row,"DEColumn1")
set #DEColumn2 = field(#row,"DEColumn2")
]%%
Row %%=v(#i)=%%, DEColumn1 is %%=v(#DEColumn1)=%%, DEColumn2 is %%=v(#DEColumn2)=%%
%%[ next #i ]%%
%%[ else ]%%
No rows found
%%[ endif ]%%
Also, there are a lot more people answering SFMC questions over at salesforce.stackexchange.com -- mostly tagged with marketing-cloud, ampscript.

How can I set the default value in a SharePoint list field, based on the value in another field?

I have a custom list in SharePoint (specifically, MOSS 2007.) One field is a yes/no checkbox titled "Any defects?" Another field is "Closed by" and names the person who has closed the ticket.
If there are no defects then I want the ticket to be auto-closed. If there are, then the "Closed by" field ought to be filled in later on.
I figured I could set a calculated default value for "Closed by" like this:
=IF([Any defects?],"",[Me])
but SharePoint complains I have referenced a field. I suppose this makes sense; the default values fire when the new list item is first opened for entry and there are no values in any fields yet.
I understand it is possible to make a calculated field based on a column value but in that case the field cannot be edited later.
Does anyone have any advice how to achieve what I am trying to do?
Is it possible to have a "OnSubmit" type event that allows me to execute some code at the point the list item is saved?
Thank you.
Include a content editor web part in the page (newform.aspx / editform.aspx) and use jQuery (or just plain javascript) to handle the setting of default values.
Edit: some example code:
In the lists newform.aspx, include a reference to jquery. If you look at the html code, you can see that each input tag gets an id based on the field's GUID, and a title that's set to the fields display name.
now, using jquery we can get at these fields using the jQuery selector like this:
By title:
$("input[title='DISPLAYNAMEOFFIELD']");
by id (if you know the field's internal guid, the dashes will ahve to be replaced by underscores:
// example field id, notice the guid and the underscores in the guid ctl00_m_g_054db6a0_0028_412d_bdc1_f2522ac3922e_ctl00_ctl04_ctl15_ctl00_ctl00_ctl04_ctl00_ctl00_TextField
$("input[id*='GUID']"); //this will get all input elements of which the id contains the specified GUID, i.e. 1 element
We wrap this in the ready() function of jQuery, so all calls will only be made when the document has fully loaded:
$(document).ready(function(){
// enter code here, will be executed immediately after page has been loaded
});
By combining these 2 we could now set your dropdown's onchange event to the following
$(document).ready(function(){
$("input[title='DISPLAYNAMEOFFIELD']").change(function()
{
//do something to other field here
});
});
The Use jQuery to Set A Text Field’s Value on a SharePoint Form article on EndUserSharePoint.com shows you how to set a default value for a field using JavaScript/jQuery.
They also have a whole series of articles on 'taming calculated columns' that will show you many more powerful options you have for calculated fields with the use of jQuery.
One thing to be aware of when inserting JavaScript into a SharePoint page and modifying the DOM is support. There is a small chance that a future service pack will break the functionality you add, and it is quite likely that the next version of SharePoint will break it. Keeping this mind however, I believe it's a good solution at this time.
I've got a walk through with sample code that may help
Setting a default duration for new calendar events
It sets the End Time/Date fields to Start Time + 1.5 hours when you create a new event.
Its complicated a little by the steps need to do the time/date work, but you'll see examples of how to find the elements on the form and also one way to get your script onto the newform.aspx without using SPD.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>
<script type="text/javascript">
// Set the hours to add - can be over 24
var hoursToAdd = 1;
// Mins must be 0 or div by 5, e.g. 0, 5, 10, 15 ...
var minutesToAdd = 30;
// JavaScript assumes dates in US format (MM/DD/YYYY)
// Set to true to use dates in format DD/MM/YYYY
var bUseDDMMYYYYformat = false;
$(function() {
// Find the start and end time/minutes dropdowns by first finding the
// labels then using the for attribute to find the id's
// NOTE - You will have to change this if your form uses non-standard
// labels and/or non-english language packs
var cboStartHours = $("#" + $("label:contains('Start Time Hours')").attr("for"));
var cboEndHours = $("#" + $("label:contains('End Time Hours')").attr("for"));
var cboEndMinutes = $("#" + $("label:contains('End Time Minutes')").attr("for"));
// Set Hour
var endHour = cboStartHours.attr("selectedIndex") + hoursToAdd;
cboEndHours.attr("selectedIndex",endHour % 24);
// If we have gone over the end of a day then change date
if ((endHour / 24)>=1)
{
var txtEndDate = $("input[title='End Time']");
var dtEndDate = dtParseDate(txtEndDate.val());
if (!isNaN(dtEndDate))
{
dtEndDate.setDate( dtEndDate.getDate() + (endHour / 24));
txtEndDate.val(formatDate(dtEndDate));
}
}
// Setting minutes is easy!
cboEndMinutes.val(minutesToAdd);
});
// Some utility functions for parsing and formatting - could use a library
// such as www.datejs.com instead of this
function dtParseDate(sDate)
{
if (bUseDDMMYYYYformat)
{
var A = sDate.split(/[\\\/]/);
A = [A[1],A[0],A[2]];
return new Date(A.join('/'));
}
else
return new Date(sDate);
}
function formatDate(dtDate)
{
if (bUseDDMMYYYYformat)
return dtDate.getDate() + "/" + dtDate.getMonth()+1 + "/" + dtDate.getFullYear();
else
return dtDate.getMonth()+1 + "/" + dtDate.getDate() + "/" + dtDate.getFullYear();
}
</script>

Resources