Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. //========== DATABASE ========================//
  2. //SCHEMA SETUP
  3. var studyfieldsSchema = new mongoose.Schema({
  4. studycat:
  5. {
  6. type: mongoose.Schema.Types.ObjectId,
  7. ref: "studycat"
  8. }
  9. ,
  10. fieldname: String,
  11. fieldtype: String,
  12. fieldinputtype: String
  13. });
  14. var studycatSchema = new mongoose.Schema({
  15. studycatname: String
  16. });
  17.  
  18. //MODEL SETUP - COMPILE THE ABOVE SCHEMA TO A MODEL
  19. var studyfields = mongoose.model("studyfields", studyfieldsSchema);
  20. var studycat = mongoose.model("studycat", studycatSchema);
  21.  
  22. //=============================================//
  23.  
  24. Category:
  25. <select name="catname">
  26. <% studycats.forEach(function(studycatitem){ %>
  27. <option value="<%= studycatitem._id %>"><%= studycatitem.studycatname %></option>
  28. <% }); %>
  29. </select>
  30.  
  31. app.post("/adminstudy", function(req, res){
  32. //console.log(req.body.study); //Shows parameters coming from the form.
  33. var studycatname = req.body.catname;
  34. var fieldname = req.body.fieldname;
  35. var fieldtype = req.body.fieldtype;
  36. var fieldinputtype = req.body.fieldinputtype;
  37. var newstudyfield = {fieldname: fieldname, fieldtype: fieldtype, fieldinputtype: fieldinputtype, studycatname: studycatname} // Tablefieldname: Formfieldname
  38. //create a new studyfield and save it to the database.
  39. studyfields.create(newstudyfield, function(err,newlycreated_sf){
  40. if(err){
  41. console.log(err);
  42. } else{
  43. console.log(newstudyfield);
  44. console.log(newlycreated_sf);
  45. res.redirect("/adminstudy"); //redirects to GET route.
  46. }
  47. });
  48. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement