Added submit logic in sample.js and fixed toObject().