首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TYPO3 9.5表单框架AJAX

TYPO3 9.5表单框架AJAX
EN

Stack Overflow用户
提问于 2019-03-21 08:38:41
回答 2查看 2.2K关注 0票数 3

我试图通过AJAX发送表单,这些表单是用TYPO3 forms框架创建的。带有此表单的内容元素将通过pageType显示。当我直接调用这个pageType并提交表单时,一切都很好。保存数据,发送邮件,并显示成功消息。

当我通过jQuery AJAX发送表单时,不会调用finisher,也不会显示错误消息。而不是这样,我得到表单,预先填充了我的输入值¯_(ツ)_/,目前我不知道这个提交是在哪里失败的。

是否有人已经有了这个问题,并能给我一个提示如何解决它?

contact.form.yaml

代码语言:javascript
运行
复制
renderingOptions:
  additionalParams:
    type: 1552662805
type: Form
identifier: contact
label: contact
prototypeName: standard
finishers:
  -
    options:
      1:
        table: 'tx_form_contact'
        mode: insert
        databaseColumnMappings:
          pid:
            value: 10
          contact_type:
            value: 'press'
        elements:
          singleselect-1:
            mapOnDatabaseColumn: salutation
          text-1:
            mapOnDatabaseColumn: last_name
          text-2:
            mapOnDatabaseColumn: first_name
          text-8:
            mapOnDatabaseColumn: company
          text-7:
            mapOnDatabaseColumn: position
          text-5:
            mapOnDatabaseColumn: address
          text-3:
            mapOnDatabaseColumn: zip
          text-4:
            mapOnDatabaseColumn: city
          text-6:
            mapOnDatabaseColumn: phone
          email-1:
            mapOnDatabaseColumn: email
          textarea-1:
            mapOnDatabaseColumn: message
          fileupload-1:
            mapOnDatabaseColumn: attachment
          checkbox-1:
            mapOnDatabaseColumn: gdpr
    identifier: SaveToDatabase
  -
    options:
      subject: 'Kontaktanfrage'
      recipientAddress: test@example.com
      recipientName: 'Empfänger'
      senderAddress: '{email-1}'
      senderName: '{text-2} {text-1}'
      replyToAddress: ''
      carbonCopyAddress: ''
      blindCarbonCopyAddress: ''
      format: html
      attachUploads: true
      translation:
        language: ''
    identifier: EmailToReceiver
  -
    options:
      message: ''
      contentElementUid: '7'
    identifier: Confirmation
renderables:
  -
    renderingOptions:
      previousButtonLabel: ''
      nextButtonLabel: ''
    type: Page
    identifier: page-1
    label: ''
    renderables:
      -
        type: Fieldset
        identifier: fieldset-1
        label: Kontaktdaten
        renderables:
          -
            properties:
              options:
                Herr: Herr
                Frau: Frau
              prependOptionLabel: '-'
            type: SingleSelect
            identifier: singleselect-1
            label: 'Single select'
          -
            defaultValue: ''
            type: Text
            identifier: text-1
            label: Name
            properties:
              fluidAdditionalAttributes:
                placeholder: Name
          -
            defaultValue: ''
            type: Text
            identifier: text-2
            label: Vorname
            properties:
              fluidAdditionalAttributes:
                placeholder: Vorname
          -
            defaultValue: ''
            type: Text
            identifier: text-8
            label: Firma
            properties:
              fluidAdditionalAttributes:
                placeholder: Firma
          -
            defaultValue: ''
            type: Text
            identifier: text-7
            label: Abteilung/Position
            properties:
              fluidAdditionalAttributes:
                placeholder: Abteilung/Position
          -
            defaultValue: ''
            type: Text
            identifier: text-5
            label: Straße
            properties:
              fluidAdditionalAttributes:
                placeholder: Straße
          -
            defaultValue: ''
            type: Text
            identifier: text-3
            label: PLZ
            properties:
              fluidAdditionalAttributes:
                placeholder: PLZ
          -
            defaultValue: ''
            type: Text
            identifier: text-4
            label: Ort
            properties:
              fluidAdditionalAttributes:
                placeholder: Ort
          -
            defaultValue: ''
            type: Text
            identifier: text-6
            label: Telefon
            properties:
              fluidAdditionalAttributes:
                placeholder: Telefon
          -
            defaultValue: ''
            type: Email
            identifier: email-1
            label: E-Mail
            properties:
              fluidAdditionalAttributes:
                placeholder: E-Mail
                required: required
              validationErrorMessages:
                -
                  code: 1221560910
                  message: 'Bitte füllen Sie die E-Mail-Adresse aus'
                -
                  code: 1221560718
                  message: 'Bitte füllen Sie die E-Mail-Adresse aus'
                -
                  code: 1347992400
                  message: 'Bitte füllen Sie die E-Mail-Adresse aus'
                -
                  code: 1347992453
                  message: 'Bitte füllen Sie die E-Mail-Adresse aus'
              elementDescription: ''
            validators:
              -
                identifier: EmailAddress
              -
                identifier: NotEmpty

      - type: Fieldset
        identifier: fieldset-3
        label: 'Ihre Nachricht'

        renderables:
          - defaultValue: ''
            type: Textarea
            identifier: textarea-1
            label: 'Ihre Nachricht an uns'
            properties:
              fluidAdditionalAttributes:
                required: required
              validationErrorMessages:
                - code: 1221560910
                  message: 'Bitte teilen Sie uns Ihr Anliegen mit'
                - code: 1221560718
                  message: 'Bitte teilen Sie uns Ihr Anliegen mit'
                - code: 1347992400
                  message: 'Bitte teilen Sie uns Ihr Anliegen mit'
                - code: 1347992453
                  message: 'Bitte teilen Sie uns Ihr Anliegen mit'
            validators:
              - identifier: NotEmpty

          - properties:
              saveToFileMount: '1:/user_upload/contact/press/'
              allowedMimeTypes:
                - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                - application/pdf
                - application/zip
                - image/jpeg
              elementDescription: 'Sie können Daten in den Formaten pdf, jpg, doc, docx und zip hochladen. Eine Datei darf maximal 4MB groß sein.'
            type: FileUpload
            identifier: fileupload-1
            label: Dateianhang
            validators:
              -
                options:
                  minimum: 0B
                  maximum: 4M
                identifier: FileSize

      -
        type: Fieldset
        identifier: fieldset-2
        label: 'Formular absenden'
        renderables:
          -
            type: Checkbox
            identifier: checkbox-1
            label: 'Ich habe die Nutzungsbedingungen und Bestimmungen zum Datenschutz gelesen und akzeptiere diese.'
            properties:
              fluidAdditionalAttributes:
                required: required
              validationErrorMessages:
                -
                  code: 1221560910
                  message: 'Bitte bestätigen Sie dieses Feld'
                -
                  code: 1221560718
                  message: 'Bitte bestätigen Sie dieses Feld'
                -
                  code: 1347992400
                  message: 'Bitte bestätigen Sie dieses Feld'
                -
                  code: 1347992453
                  message: 'Bitte bestätigen Sie dieses Feld'
            validators:
              -
                identifier: NotEmpty

FormContact.typoscript

代码语言:javascript
运行
复制
formContact = PAGE
formContact {
    typeNum = 1552662805

    config {
        disableAllHeaderCode = 1
        xhtml_cleaning = 0
        admPanel = 0
        #additionalHeaders = Content-type: text/plain
        no_cache = 1
        debug = 0
    }

    10 = CONTENT
    10 {
        table = tt_content
        select {
            pidInList = 25
            uidInList = 94
        }
    }
}

contact.js

代码语言:javascript
运行
复制
let form = $('form')
let formData = new FormData(form.get(0));
let request = $.ajax({
    url: form.prop('action'),
    method: 'POST',
    data: formData,
    enctype: 'multipart/form-data',
    processData: false,  // Important!
    contentType: false,
    cache: false,

    beforeSend: function() {
        formHolder.html(template.loadingSpinner);
    }
});

// show form
request.done(function(data, text, jqXHR) {
    formHolder.html(data);
});

// show error
request.fail(function(jqXHR) {
    formHolder.html(template.errorMessage.replace('$$MESSAGE$$', formSelector.data('errorMessage')));
});
EN

回答 2

Stack Overflow用户

发布于 2019-08-05 07:07:56

也有同样的问题。需要添加

代码语言:javascript
运行
复制
<input type='hidden' name='tx_form_formframework[FORMNAME][__currentPage]' value='1'>

以我的形式。(用Jquery做的)

代码语言:javascript
运行
复制
$('#FORMNAME').prepend("<input type='hidden' name='tx_form_formframework[FORMNAME][__currentPage]' value='1'>");

在那之后它起作用了。与普通请求和ajax请求进行比较。

票数 4
EN

Stack Overflow用户

发布于 2022-10-22 10:42:47

按钮保存__currentPage的值。

代码语言:javascript
运行
复制
<button type="submit" name="tx_form_formframework[contact-form-5][__currentPage]" value="1">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55276483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档