我包括了storyblok对象和serializeArray函数:
import { serializeArray } from '../utils';
import { storyblok } from '../shims/Storyblok';
现在,我想将表单数据传递给sendEmail函数。它是如何工作的?
submit(event:Event) {
event.preventDefault();
let formData = serializeArray(<HTMLFormElement> this.$());
// what to do here?
storyblok.sendEmail(message,
// success
function(data:any) {
console.log(data);
console.log('success');
},
// error
function(data:any) {
console.log(data);
console.log('error');
}
)
}
最佳答案
Storyblok联系人表单API允许您以以下格式传递参数:
var message = {};
message['message[email]'] = 'Valid Email goes here'; // assign your email field here
message['message[body]'] = 'This is my Message'; // assign your message field here
这两个字段(
email
和body
)是必填字段-您可以根据需要向API传递任意数量的参数。您可以使用以下cURL请求直接尝试您的请求
curl 'https://api.storyblok.com/v1/messages?token={{YOUR_TOKEN}}'
-H 'pragma: no-cache'
-H 'origin: {{YOUR_SPACE_DOMAIN}}'
-H 'accept-encoding: gzip, deflate, br'
-H 'x-requested-with: XMLHttpRequest'
-H 'accept-language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,hr;q=0.2,el;q=0.2,bg;q=0.2,sr;q=0.2,fr;q=0.2,sq;q=0.2'
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36'
-H 'content-type: application/x-www-form-urlencoded'
-H 'accept: */*'
-H 'cache-control: no-cache'
-H 'authority: api.storyblok.com'
-H 'referer: {{YOUR_SPACE_DOMAIN}}' --data 'message%5Bemail%5D=test%40test.test&message%5Bbody%5D=yourMessageGoesHere' --compressed
关于javascript - 如何在Javascript/Typescript中使用Storyblok电子邮件服务?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41978157/