Drupal Web 表单 REST

发布于 2025-01-16 18:30:13 字数 1308 浏览 7 评论 0原文

我正在尝试使用 Drupal Webform REST。 我在浏览器控制台上收到错误“需要‘restful post webform_rest_submit’权限。”。我已启用模块和 REST 资源,如上所述。 我使用了Authorization,即Postman中生成的Auth,使用基本身份验证。 我正在努力在邮递员中使用“x-csrf-token”。 我想使用匿名用户提交表单。我还需要授权吗?仅令牌在同源上不起作用吗?

const handleSubmit = async (e) => {
    e.preventDefault(); 

    await axios({
      method: 'GET',
      url: `${baseurl.URL}/session/token`,
      headers: {
        'Accept': 'application/vnd.api+json',
      }
    })
    .then(response =>  response)
    .then((token)=>{
      console.log("CSRF TODKEN", token.data);
      axios({
        method: 'post',
        url: `${baseurl.URL}/webform_rest/submit?_format=json`,
        headers:{
          'Accept': 'application/vnd.api+json',
          'Content-Type': 'application/json',
          'X-CSRF-Token': token.data,
          'Authorization':'Basic $S$EDSnVMXDICYbVGJ'
        },
        data: {
          "webform_id": "contact_form",
          "name":name,
          "email": email,
          "subject": subject,
          "message": message
        }
      })
    })
    .then(response => {
      console.log(response)
      response.status === 200 && console.log("Form successfully submitted")
    })
    .catch(err => console.log("SUBMIT FAIL ERROR ",err))```

I am trying to use Drupal Webform REST.
I got an error "The 'restful post webform_rest_submit' permission is required." on browser console. I have enabled modules and REST resources as mentioned.
I used Authorization, the Auth generated in Postman, using basic auth.
I am struggling to use 'x-csrf-token' in postman.
I want to use submit the form by an anonymous user. Do I still need Authorization, will just token not work on same-origin?

const handleSubmit = async (e) => {
    e.preventDefault(); 

    await axios({
      method: 'GET',
      url: `${baseurl.URL}/session/token`,
      headers: {
        'Accept': 'application/vnd.api+json',
      }
    })
    .then(response =>  response)
    .then((token)=>{
      console.log("CSRF TODKEN", token.data);
      axios({
        method: 'post',
        url: `${baseurl.URL}/webform_rest/submit?_format=json`,
        headers:{
          'Accept': 'application/vnd.api+json',
          'Content-Type': 'application/json',
          'X-CSRF-Token': token.data,
          'Authorization':'Basic $S$EDSnVMXDICYbVGJ'
        },
        data: {
          "webform_id": "contact_form",
          "name":name,
          "email": email,
          "subject": subject,
          "message": message
        }
      })
    })
    .then(response => {
      console.log(response)
      response.status === 200 && console.log("Form successfully submitted")
    })
    .catch(err => console.log("SUBMIT FAIL ERROR ",err))```

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑,眼淚并存 2025-01-23 18:30:13

它起作用了。我向匿名用户授予了“访问 Webform 提交资源上的 POST”权限。

It worked. I gave permission to "Access POST on Webform Submit resource" to anonymous users.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文