Node.js + express is in use. Oh, the ejs template!
You are about to implement a search function among the bulletin board functions.
I'm trying to implement it in a get way.
<option value="title,body">Title+Content</option>
<option value="title">Title</option>
<option value="content">Content</option>
<input type="text" name="searchText">
<Button class="btn"> Search</Button>
Implement the search form as shown above.
?searchType=title,body&searchText=tunnel
If you get it to the query list as above, the server req.query.searchType and req.You are trying to implement a search function by processing db with query.searchText.
(I don't know if this is the right way to develop a search function. )
If the above method is wrong, I would like to be advised of the right direction If correct, I would like to know the value of the dropdown selected when the Search button is pressed and how to send a query list such as ?searchType=title, body&searchText=tunnel to the search term.
node.js query-string search
I checked briefly, and Xe gives me title + content search like this.
I think we should filter it out with an if, switch. Simply separated by , you can identify the table schema structure or be the basis of an injection attacks.
If the setting is good, there will be no problem, but if there is an error message because the setting is wrong when sending searchType like a, b, and c, it will be a problem
Even if it's a bit annoying, I think it would be better to divide it into a regular search or a set of title, content, etc
When searching, if you want to send a query string like that, simply give the form method as get
<form action="" method="get">
<select name="searchType">
<option value="title_body">Title+Content</option>
<option value="title">Title</option>
<option value="content">Content</option>
</select>
<input type="text" name="searchText">
<input type="submit" class="btn"> Search</Button>
</form>
If you search, the query string will be attached to url.
© 2024 OneMinuteCode. All rights reserved.