简体   繁体   中英

Parse.com - Cannot add additional fields to User

Just getting started with Parse.com and following their JavaScript ToDo app tutorial and having some issues.

Basically it will work perfectly and post to the Parse database when I just have the Username and Password but if I try to add any additional fields like email or phone, it won't send it to the database. I have already defined both email and phone fields in my Parse database.

Any help would be appreciated. Thanks!

My html for my form:

<script type="text/template" id="login-template">
  <header id="header"></header>
   <form class="signup-form">
      <h2>Sign Up</h2>
      <div class="error" style="display:none"></div>
      <input type="text" id="signup-username" placeholder="Username" />
      <input type="password" id="signup-password" placeholder="Create a Password" />
      <input type="email" id="signup-email" placeholder="Email" />
       <input type="text" id="signup-phone" placeholder="Phone" />
      <button>Sign Up</button>
    </form>
  </div>
</script>

My JS:

var LogInView = Parse.View.extend({
events: {
  "submit form.signup-form": "signUp"
},

el: ".content",

initialize: function() {
  _.bindAll(this, "signUp");
  this.render();
},

signUp: function(e) {
  var self = this;
  var username = this.$("#signup-username").val();
  var password = this.$("#signup-password").val();
  var email = this.$("#signup-email").val();
  var phone = this.$("#signup-phone").val();

  Parse.User.signUp(username, password, email, phone, { ACL: new Parse.ACL() }, {
    success: function(user) {
      new ManageTodosView();
      self.undelegateEvents();
      delete self;
    },

    error: function(user, error) {
      self.$(".signup-form .error").html(error.message).show();
      self.$(".signup-form button").removeAttr("disabled");
    }
  });

  this.$(".signup-form button").attr("disabled", "disabled");

  return false;
},

render: function() {
  this.$el.html(_.template($("#login-template").html()));
  this.delegateEvents();
}
});

You should use the following syntax, like specified in the javascript docs ( https://parse.com/docs/js_guide ):

var user = new Parse.User();
user.set("username",username);
user.set("password",password);
user.set("email",email);
user.set("phone",phone);

user.signUp(null,{
    success:function(user){...},
    error:function(user,error){...}
});

You can add any fields you want with the set method.

I had to change <!--<button>Submit</button>--> to <!--<input type="submit"></input>--> to get this to work but then it did. Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM