将登录字段添加到数据库?

时间:2015-10-13 20:29:11

标签: javascript html mongodb meteor meteor-accounts

我目前正在尝试创建一个字段,将用户插入的数据插入到数据库中。我目前正在尝试创建一个名为“UserRecords”的数据库,以便在提交表单时,它访问数据库并使用用户插入字段的内容更新“UserRecords”数据库。目前,我尝试连接的唯一字段是“地址”字段。

这是我的两个/ config.js文件:

UserRecords = new Mongo.Collection("userrecords");

AccountsTemplates.configure({

    // Behavior
    confirmPassword: true,
    enablePasswordChange: true,
    forbidClientAccountCreation: false,
    overrideLoginErrors: true,
    sendVerificationEmail: true,
    lowercaseUsername: false,
    focusFirstInput: true,

    // Appearance
    showAddRemoveServices: false,
    showForgotPasswordLink: true,
    showLabels: true,
    showPlaceholders: true,
    showResendVerificationEmailLink: true,

    // Client-side Validation
    continuousValidation: false,
    negativeFeedback: false,
    negativeValidation: true,
    positiveValidation: true,
    positiveFeedback: true,
    showValidating: true,

    // Privacy Policy and Terms of Use
    privacyUrl: 'privacy',
    termsUrl: 'terms-of-use',

    // Redirects
    homeRoutePath: '/map',
    redirectTimeout: 4000,
});

AccountsTemplates.addField({  
    _id: "address",
    type: "text",
    displayName: "Address",
    placeholder: {
        signUp: "Your Address"
    },
});

AccountsTemplates.addField({
    _id: "pilotorcustomer",
    type: "radio",
    displayName: "Are You A Pilot Or Looking For A Service",
    required: true,
    select: [
        {
        text: "Pilot",
        value: "aa",
      }, {
        text: "Customer",
        value: "bb",
      },
    ],
});

如果有人想查看整个文件,可以通过以下链接在github上找到:

https://github.com/Aggr0vatE/testbasichelp

先谢谢你,

斯蒂芬

1 个答案:

答案 0 :(得分:1)

好的,所以我通过向AccountTemplates.addField添加一个全局变量然后创建一个函数来调用变量将其插入到数据库中来解决这个问题。

这是完成的config.js代码:

UserRecords = new Mongo.Collection("userrecords");

insertDatabase = function (address) {
    UserRecords.insert({
        Address: address._id,
    });
};

AccountsTemplates.configure({

    // Behavior
    confirmPassword: true,
    enablePasswordChange: true,
    forbidClientAccountCreation: false,
    overrideLoginErrors: true,
    sendVerificationEmail: true,
    lowercaseUsername: false,
    focusFirstInput: true,

    // Appearance
    showAddRemoveServices: false,
    showForgotPasswordLink: true,
    showLabels: true,
    showPlaceholders: true,
    showResendVerificationEmailLink: true,

    // Client-side Validation
    continuousValidation: false,
    negativeFeedback: false,
    negativeValidation: true,
    positiveValidation: true,
    positiveFeedback: true,
    showValidating: true,

    // Privacy Policy and Terms of Use
    privacyUrl: 'privacy',
    termsUrl: 'terms-of-use',

    // Redirects
    homeRoutePath: '/map',
    redirectTimeout: 4000,
});

address = AccountsTemplates.addField({  
    _id: "address",
    type: "text",
    displayName: "Address",
    required: true,
    placeholder: {
        signUp: "Your Address"
    },
});

AccountsTemplates.addField({
    _id: "pilotorcustomer",
    type: "radio",
    displayName: "Are You A Pilot Or Looking For A Service",
    required: true,
    select: [
        {
        text: "Pilot",
        value: "aa",
      }, {
        text: "Customer",
        value: "bb",
      },
    ],
});