Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //========== DATABASE ========================//
- //SCHEMA SETUP
- var studyfieldsSchema = new mongoose.Schema({
- studycat:
- {
- type: mongoose.Schema.Types.ObjectId,
- ref: "studycat"
- }
- ,
- fieldname: String,
- fieldtype: String,
- fieldinputtype: String
- });
- var studycatSchema = new mongoose.Schema({
- studycatname: String
- });
- //MODEL SETUP - COMPILE THE ABOVE SCHEMA TO A MODEL
- var studyfields = mongoose.model("studyfields", studyfieldsSchema);
- var studycat = mongoose.model("studycat", studycatSchema);
- //=============================================//
- Category:
- <select name="catname">
- <% studycats.forEach(function(studycatitem){ %>
- <option value="<%= studycatitem._id %>"><%= studycatitem.studycatname %></option>
- <% }); %>
- </select>
- app.post("/adminstudy", function(req, res){
- //console.log(req.body.study); //Shows parameters coming from the form.
- var studycatname = req.body.catname;
- var fieldname = req.body.fieldname;
- var fieldtype = req.body.fieldtype;
- var fieldinputtype = req.body.fieldinputtype;
- var newstudyfield = {fieldname: fieldname, fieldtype: fieldtype, fieldinputtype: fieldinputtype, studycatname: studycatname} // Tablefieldname: Formfieldname
- //create a new studyfield and save it to the database.
- studyfields.create(newstudyfield, function(err,newlycreated_sf){
- if(err){
- console.log(err);
- } else{
- console.log(newstudyfield);
- console.log(newlycreated_sf);
- res.redirect("/adminstudy"); //redirects to GET route.
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement