Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // html
- <form id="searchForm" action="/results" method="POST" enctype="multipart/form-data">
- <input type="text" id="search" name="search" placeholder="search" />
- </form>
- // ExpressJS
- app.post('/results', (req, res) => {
- const form = new formidable.IncomingForm()
- form.parse(req, (err, field) => {
- if (err) console.log(err)
- const rawRequest = field.search
- const keyword = rawRequest.toLowerCase().trim().replace(/\W+\D+/gim, "")
- // in MongoDB you need to have 'keywords' field
- var query = contact.find({ keywords: { $regex: keyword } })
- query.exec(function(err, contact) {
- if (err) console.log(err)
- res.render('results.html', {
- contacts: contact
- })
- })
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement