Creating a user using autoform


#1

I want to create a couple of users quickly and i figured autoform would be of help.

This is my schema

Schema = {};

Schema.UserProfile = new SimpleSchema({
    schoolname: {
    label: "School Name",
    optional: false,
        type: String
    },
    schooldescription: {
        label: "School Description",
    optional: false,
        type: String
    },
    schoollocation: {
        label: "School Location",
    optional: false,
        type: String
    },
    schoollogo : {
        label: "School Logo",
    optional: false,
        type: String
    },
    schooltelephonenumber: {
        label: "School Telephone Number",
    optional: false,
        type: String
    }
});

Schema.User = new SimpleSchema({
    email: {
        type: String,
        // For accounts-password, either emails or username is required, but not both. It is OK to make this
        // optional here because the accounts-password package does its own validation.
        // Third-party login packages may not require either. Adjust this schema as necessary for your usage.
        regEx: SimpleSchema.RegEx.Email
    },
    password: {
        type: String,
    },

    createdAt: {
        type: Date
    },
    profile: {
        type: Schema.UserProfile,
        optional: true
    }
});

Meteor.users.attachSchema(Schema.User);

In my html i have this

{{ #autoForm schema="Schema.User" id="usercreation" collection ="Meteor.users" type="method" meteormethod="usercreation" }}
                                    <fieldset>
                                      <legend>Create an account</legend>
                                      {{> afQuickField name='email' label='Email' }}
                                      {{> afQuickField name='password' label='Password'  }}
                                      {{> afQuickField name='schoolname' label='School Name' }}
                                      {{> afQuickField name='schooldescription' label='School Description' }}
                                      {{> afQuickField name='schoollocation' label='School Location' }}
                                      {{> afQuickField name='schoollogo' label='School Logo' }}
                                      {{> afQuickField name='schooltelephonenumber' label='School Telephone Number' }}
                                      
                                    </fieldset>
                                    <input type="submit">
                                  {{ /autoForm }}

This is my method

   'usercreation': function(params){
      Accounts.createUser({
       email: post.params.email,
       password: params.password,
       profile: {
          schoolname: params.schoolname,
          schooldescription: params.schooldescription,
          schoollocation: params.schoollocation,
          schoollogo: params.schoollogo,
          schooltelephonenumber: params.schooltelephonenumber
        }
        });
    },

The form displayed only shows email and password and not other fields of the form. The code does not create a user too.


#2

Your code sample is for an “update” form. Take a look at this video (approx 20mins in) https://www.youtube.com/watch?v=OlXpdmBzK3o for some discussion and code samples around using autoform to update a user profile.

For “creating” a new user, though, you should use a “method” form type. https://github.com/aldeed/meteor-autoform#method where your method takes in the provided doc to pass into Accounts.createUser()


#3

I updated the type to insert. Do you have the code hosted somewhere?. The video quality is poor and i cant seem to view anything you guys are writing.


#4

I said you should use the “method” type, not “insert”.

Code is visible on the video if you watch carefully.


#5

I have updated the code to include the method,but still i cannot insert.