【问题标题】:ApostropheCMS Contact us form with attachmentApostropheCMS 联系我们的表格和附件
【发布时间】:2018-11-30 00:48:52
【问题描述】:

我是 Apostrophe 的新手,并尝试按照教程在 Apostrophe 中创建带有文件附件的联系我们表格。 https://apostrophecms.org/docs/tutorials/intermediate/forms.html

我还在我的 index.js 中创建了附件字段,它在管理面板中运行良好。

现在,我正在尝试为提交文件的表单创建自己的 html。

// 在 lib/modules/contact-form-widgets/public/js/always.js 中

apos.define('contact-form-widgets', {

    extend: 'apostrophe-widgets',

    construct: function(self, options) {

      self.play = function($widget, data, options) {

        var $form = $widget.find('[data-contact-form]');
        var schema = self.options.submitSchema;
        var piece = _.cloneDeep(self.options.piece);

        return apos.schemas.populate($form, self.schema, self.piece, function(err) {
          if (err) {
            alert('A problem occurred setting up the contact form.');
            return;
          }
          enableSubmit();
        });

        function enableSubmit() {
          $form.on('submit', function() {
            submit();
           //I can access file here
            // console.log($form.find('file'))

            return false;
          });
        }

        function submit() {
          return async.series([
             convert,
            submitToServer
          ], function(err) {
            if (err) {
              alert('Something was not right. Please review your submission.');
            } else {
              // Replace the form with its formerly hidden thank you message
              $form.replaceWith($form.find('[data-thank-you]'));
            }
          });
          function convert(callback) {
            return apos.schemas.convert($form, schema, piece, callback);
          }
          function submitToServer(callback) {



            return self.api('submit', piece, function(data) {

                alert("I AM AT SUBMIT API ")
              if (data.status === 'ok') {
                // All is well
                return callback(null);
              }
              // API-level error
              return callback('error');
            }, function(err) {
              // Transport-level error
                alert("I AM HERE AT API ERROR")

              return callback(err);
            });
          }
        }
      };
    }
  });



    //and my widget.html is

    <div class="form-group">
        <input name="custom-file" type="file">
      </div>

当我运行它时,我得到以下错误

user.js:310 Uncaught TypeError: Cannot read property 'serialize' of undefined
    at Object.self.getArea (user.js:310)
    at Object.self.getSingleton (user.js:303)
    at Object.convert (user.js:686)
    at user.js:164
    at async.js:181
    at iterate (async.js:262)
    at async.js:274
    at async.js:44
    at setImmediate.js:27
    at runIfPresent (setImmediate.js:46)

我的问题是,我如何处理文件提交?有没有更好的方法呢?

【问题讨论】:

    标签: node.js apostrophe apostrophe-cms


    【解决方案1】:

    使用apostrophe-pieces-submit-widgets 模块更容易做到这一点,它允许您为用户可以提交的内容定义模式。您可以在其中包含attachment 类型的字段,这在自述文件中进行了演示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-25
      • 1970-01-01
      • 2014-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      相关资源
      最近更新 更多