I currently have two different forms on one inven.ejs file:
One for simple description:
///inven.ejs
<form method="POST" value="inven">
<div id="some-form" style="display: none;">
<table>
<tr>
<td><label for="item">Item</label></td>
<td><input type="text" name="item" required/></td>
</tr>
<tr>
<td><label for="text-box-value">Value</label></td>
</tr>
<tr>
<td><label for="comments">Comments</label></td>
<td><textarea rows="4" cols="50" required></textarea></td>
</tr>
<tr>
<td><input type="submit" /></td>
</tr>
</table>
</div>
</form>
and another for file upload:
///inven.ejs
<div id="fileUp">
<form id="fileUpload" name="fileUpload" enctype="multipart/form-data" method="post">
<fieldset>
<input type="file"id="fileSelect">
<input type="submit" name="upload" value="upload">
</fieldset>
</form>
</div>
In express, how can I differentiate between these two posts in my list.js file?
router.post('/list', function(req,res){
// ???
});
Do I need two routers? Am I completely doing this incorrectly?
Thank you!
EDIT:
Included an image, if it helps?
It makes sense to have forms post to a different address.
That is, <form id="fileUpload" action="file_upload" ... >
Then, if the form is found at http://server/my_form, it will post to http://server/file_upload
In your Node.js router you need to catch that and done.
If you still desire to send both forms to the same address, you can then use hidden fields.
Example: <input type="hidden" name="form_type" value="file_up_form">. Then in your Node.js you check for the argument form_type and check its value.
Related
<form method="POST" action="/admin/update-blog/{{blogs._id}}">
<div class="form-group">
<label for="exampleInputPassword1">HEADING</label>
<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" value="{{blogs.heading}}" name="heading">
</div>
<br><br>
<div class="form-group">
<label for="exampleInputPassword1">BLOG</label>
<input type="text" class="form-control" id="exampleInputPassword1" value="{{blogs.blog}}" name="blog">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<br><br>
<h2><i><b>Comments</b></i></h2>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Email</th>
<th scope="col">Message</th>
</tr>
</thead>
<tbody>
{{#each blogs.comments}}
<tr>
<th scope="row"></th>
<td>
<form method="POST" action="/admin/delete-comment">
<div class="form-group">
<label for="exampleInputEmail1"></label>
<input type="email" class="form-control" id="myInput"readonly aria-describedby="emailHelp" placeholder="Enter email" value="{{this.email}}" name="email">
</div>
<button type="submit" class="btn btn-danger">delete</button>
</form>
</td>
<td>{{this.message}}</td>
</tr>
{{/each}}
</tbody>
</table>
How can i pass the {{blogs._id}} to a form which is inside a loop called {{#each blogs.comments}} .Is that possible.I am trying to delete a comment based on the email and the id of blog.Here the blog id is there in the top of code which is the first form where it displays the blog .And in the second form it displays the comments for the blog.
For me it is not possible to pass the id from blog to second loop(display comment).
I want to pass the id of blog to the action of the form in second loop(display comment)
THANKS IN ADVANCE😊
<option value="{{id}}">{{title}} {{../externalValue}}</option>
//The ../ path segment references the parent template scope that should be what you want.
So, I am working on a CRUD application and I am trying to make it so that I can edit the project when I click edit. I can successfully get the project ID with the req.params.id and it is successfully printing the correct information into the console but when I go to send it to my front end it is still updating the information for the first entry in the collection. Below is the code that I used for this.
Backend:
router.get('/edit/(:id)', function (req, res, next) {
var o_id = new ObjectId(req.params.id).toString();
db.collection('projects').find({
"_id": ObjectId(o_id).toString
}).toArray(function (err, result) {
if (err) return console.log(err)
// if user not found
if (!result) {
req.flash('error', 'Project not found with id = ' + req.params.id)
res.redirect('/projects')
} else { // if user found
console.log(result);
// render to views/user/edit.ejs template file
res.render('edit.ejs', {
user: req.user,
title: 'Edit User',
//data: rows[0],
projID: result[0]._id,
projName: result[0].projectName,
projStat: result[0].status,
projEngineer: result[0].engineer,
projCost: result[0].finalCost
});
}
});
});
Frontend for listing the projects:
<tbody>
<form action="/edit/<%=projID%>" method="post" class="d-flex align-self-center mx-auto" style="width:500px;height:500px;padding:0px;margin:0px;background-color:rgb(255,255,255);">
<tr>
<td>
<input type="text" class="form-control" name="projName" value="<%=projName %>">
</td>
<td>
<input type="text" class="form-control" name="projStat" value="<%=projStat %>">
</td>
<td>
<input type="text" class="form-control" name="projEngineer" value="<%=projEngineer %>">
</td>
<td>
<input type="text" class="form-control" name="projCost" value="<%=projCost %>">
</td>
</tr>
<button class="btn btn-primary btn-block" type="submit" style="background-color:rgb(4,148,74);">Submit</button>
</form>
</tbody>
Front end for editing
<tbody>
<form action="/edit/<%=projID%>" method="post" class="d-flex align-self-center mx-auto" style="width:500px;height:500px;padding:0px;margin:0px;background-color:rgb(255,255,255);">
<tr>
<td>
<input type="text" class="form-control" name="projName" value="<%=projName %>">
</td>
<td>
<input type="text" class="form-control" name="projStat" value="<%=projStat %>">
</td>
<td>
<input type="text" class="form-control" name="projEngineer" value="<%=projEngineer %>">
</td>
<td>
<input type="text" class="form-control" name="projCost" value="<%=projCost %>">
</td>
</tr>
<button class="btn btn-primary btn-block" type="submit" style="background-color:rgb(4,148,74);">Submit</button>
</form>
</tbody>
So I figured out my issue, the way I was querying the db returned all of the objects, I just had to loop over it and find where the id matches up. Thanks to #andreiNikolaenko for pointing out to check that.
Given the HTML snippet below how can I, using page-object field accessors, get the second input field, the one with id="333:".
I can't use the id to identify the field as it's auto-generated.
Using page-object accessors I can get the embedded table and the correct cell but the cell object is a PageObject::Elements::TableCell which doesn't seem to have any methods that allow access to the embedded span and input field.
I can get the input field using native Watir accessors - i.e., browser.div( ... etc ...) but would prefer to use just page-object accessors if possible.
If not possible then I'll live with native Watir. Thanks
<div class="modalContent">
<table role="presentation" id="324:_layoutTbl" class="axial">
<tbody>
<tr>
<td>
<input id="326:" name="" value="" onchange="juic.fire("326:","_change",event);" onfocus="juic.fire("326:","_focus",event);" onblur="juic.fire("326:","_blur",event);" type="text">
</td>
</tr>
<tr>
<td class="sfTH">
<label for="332:">Users:</label>
</td>
<td>
<table class="noborder" role="presentation">
<tbody>
<tr>
<th>
<label id="336:" class="rcmFormLabel">Hiring Manager</label>
<label id="337:" for="333:" class="rcmFormLabe">Users, Hiring Manager</label>
</th>
<td><span class="autocompspan ">
<input class="autocompinput" id="333:" name="333:" onfocus="juic.fire("333:","_focus",event);" size="20" value="Bill Murray" role="combobox" type="text">
<input value="111111" id="333:_hidden" name="333:_hidden" type="hidden">
</span>
<div id="335:" style="display:none"><img alt="" class="globalFloatLeft">
<div id="335:_error" style="color:#ff0000">undefined is required</div>
<div style="clear:both;"></div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
After more experimenting I found the answer to my question. I declared the table accessor, e.g., div(:my_table, :class => 'modalContent').table.table then in the code, to get the input field in the first row I did my_text_field = my_table_element[0].text_field_element which returned the PageObject::TextField object in column 2 of row 1
I know you like to see code, so here it is. All I want to do is to encrypt the password using SHA as it is entered. I have managed to encrypt the mysql database field to match it already.
I can't seem to find the correct syntax so I get a row of blobs instead of the password in clear text, which means it is not being sent to the server encrypted.
Thanks
<body>
<div id="container">
<div id="logo"><img src="images/Logo.jpg" alt="mycena" />
<div id="banner">
<h1>Shropshire Fungus Group</h1>
<p> </p>
</div>
</div>
<div id="ruler">
<hr />
</div>
</div>
<div class="menu"><ul class="nav" >
<li>Home</li>
<li>Membership</li>
<li>Resources</li>
<li>Gallery</li>
<li>Newsletters</li>
<li>Fixture List</li>
<li>Useful Links</li>
</ul>
</div>
<div id="intro">
<h2>Please complete your details to log in</h2>
<table>
<tr>
<td> Username: </td>
<td><input type="text" name="user" id="user" size="35" maxlength="50"/></td>
</tr>
<!-- password should be 8 characters or more in length -->
<tr>
<td> Password: </td>
<td><input type="text" name="upword" id="upword" size="40" maxlength="40"/></td>
</tr>
</table>
<p> </p>
<form action="loginphp170114.php" method="post" id="demo">
<input type="submit" value="Submit form" />
</form>
You'll need to use an external library such as this one, or else implement the sha1 algorithm yourself.
Note that sha1 is hashing, not encryption, and it's not a hash algorithm designed for storing passwords, so it's easily broken.
How come I customize the session in Liferay?Sample codes are welcome as it will help more,I am pretty new to Liferay?
To be more specific, i'll explain what i've done. Using Custom JSPs Hooks , i have overridden the $PORTAL_ROOT_HOME/html/portlet/login login.jsp and created my own jsp page and also overridden the LoginAction class.My login.jsp page looks like:
<aui:form action="" method="post">
<table>
<tr>
<td>Username :</td>
<td><input name="login" size=15 type="text" /></td>
</tr>
<tr>
<td>Password :</td>
<td><input name="password" size=15 type="password" /></td>
</tr>
</table>
<aui:button type="submit" value="sign-in"/>
</aui:form>
Now please tell upon clicking on the submit button , how can i get the login values in LoginAction.java and hence set the values to session. This is what i mean by customizing.
You should have copied the origonal login.jsp file from the start. By the looks of your codesnipsets you forgot to set the action to your loginAction. This can be done the following way:
<portlet:actionURL secure="<%= PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS || request.isSecure() %>" var="loginURL">
<portlet:param name="saveLastPath" value="0" />
<portlet:param name="struts_action" value="/login/login" />
<portlet:param name="doActionAfterLogin" value="<%= portletName.equals(PortletKeys.FAST_LOGIN) ? Boolean.TRUE.toString() : Boolean.FALSE.toString() %>" />
</portlet:actionURL>
<aui:form action="<%= loginURL %>" method="post">
<table>
<tr>
<td>Username :</td>
<td><aui:input name="login" size=15 type="text" /></td>
</tr>
<tr>
<td>Password :</td>
<td><aui:input name="password" size=15 type="password" /></td>
</tr>
</table>
<aui:button type="submit" value="sign-in"/>
</aui:form>
Please note that it is better to copy the orginal $PORTAL_ROOT_HOME/html/portlet/login/ login.jsp to your hook. Then make the modifications if any needed.
Your Hook will break / remove allot of existing functionality if the provided snipset is all you have.
To receive the parameters from the action you can use Pauls answer.
You can get login values with this code:
String login = ParamUtil.getString(request, "login");
String password = ParamUtil.getString(request, "password");
To set some values to session use this:
HttpSession session = request.getSession();
session.setAttribute("parm", "somevalue");
BR,
Paul