Comments (11)
forms.create({
csrf: forms.widgets.hidden({
required: true,
validators: [
function (form, field, callback) {
if (form.fields.csrf !== getExpectedCSRFTokenValue()) {
callback('bad csrf token');
} else {
callback();
}
}
]
})
}).bind({ csrf: 'a token' });
? I haven't tried this yet, but something like that should work?
from forms.
If you get a working solution, I think I've changed my mind - a generic "must match value" widget, that takes a "getValue" function and an "initialValue", might serve your purposes quite well.
from forms.
This is just weird:
> var form = forms.create({ csrf: forms.widgets.hidden() });
> form.bind({ csrf: 'token' });
Throws an error, TypeError: Object #<Object> has no method 'bind'
, but form
certainly does have a bind method:
> form.bind
[Function]
This is with 0.3.0, installed using npm. I would like to clone the repo and start poking around, but right now I have a late project and so I think I should just to do the hidden input manually in the templates for now. Thank you for all your work on this much needed module, I hope I can sort this out after I catch up to my deadline.
from forms.
Sounds good, I'd love to make forms
more useful. I think the argument to form.bind might need to be different - maybe { fields: { csrf: 'token' } }
? i'll take a look at the code later
from forms.
I've added a matchValue
validator that takes a getter function.
from forms.
My situation is quite similar to d4goxn. And I just need to have a value attribute with the csrfToken in it.But wired, I try this:
var loginForm = forms.create({
username: fields.string({ required: validators.required('xxxx') }),
password: fields.password({ required: validators.required('xxxx') }),
csrfToken: widgets.hidden({
required: true
})
}).bind({ fields:{ csrfToken: req.csrfToken() }});
"no bind function error"
and this:
var loginForm = forms.create({
username: fields.string({ required: validators.required('xxxx') }),
password: fields.password({ required: validators.required('xxxx') }),
csrfToken: widgets.hidden({
required: true
value: req.csrfToken()
})
});
I dump the csrf value, it's there. But at the end, the form didn't have a value attribute.
And I try 'value':req.csrfToken() too.
it dosen't work too.
pls help, thnks.
from forms.
@elantion In your second snippet you're missing a comma - is that just a copy/paste error, or is that in your original code?
As for "no bind function error" can you gist the actual output you're getting?
from forms.
Thanks your reply.
The second snippet syntax error just a copy/paste mistake. The code is find.
'no bind function error' detail :
TypeError: undefined is not a function
at /Users/jamesying/Desktop/lc/node_modules/forms/lib/forms.js:36:47
at Array.forEach (native)
at Object.f.bind (/Users/jamesying/Desktop/lc/node_modules/forms/lib/forms.js:34:35)
at /Users/jamesying/Desktop/lc/routes/articles.js:25:8
at Layer.handle [as handle_request] (/Users/jamesying/Desktop/lc/node_modules/express/lib/router/layer.js:82:5)
at next (/Users/jamesying/Desktop/lc/node_modules/express/lib/router/route.js:110:13)
at csrf (/Users/jamesying/Desktop/lc/node_modules/csurf/index.js:97:5)
at Layer.handle [as handle_request] (/Users/jamesying/Desktop/lc/node_modules/express/lib/router/layer.js:82:5)
at next (/Users/jamesying/Desktop/lc/node_modules/express/lib/router/route.js:110:13)
at Route.dispatch (/Users/jamesying/Desktop/lc/node_modules/express/lib/router/route.js:91:3)
from forms.
Yes, I am making another form. But I use the same way to create the form.
/* add article */
router.get('/add', csrfProtection, function(req, res) {
var add_form = forms.create({
title: fields.string({ required: true }),
content: fields.string({ required: validators.required('请输入内容') }),
csrfToken:forms.widgets.hidden({required:true})
}).bind({ fields:{ csrfToken: req.csrfToken() }});
add_form.toHTML();
res.render('article/add',{
add_form:add_form
});
});
from forms.
@elantion This discussion should really go in a brand new issue. Can you file one?
from forms.
sure, I will do it.
from forms.
Related Issues (20)
- Browser bundle is very large HOT 7
- Bound form does not have form.handle HOT 3
- Tags are not properly accessible through forms HOT 8
- Is it possible to add an HTML markup element? HOT 2
- How to create a form with an array of inputs HOT 4
- Wrong POST for multipleCheckbox? HOT 3
- Promise / async/await support HOT 12
- "Placeholder" attribute for text-based inputs HOT 5
- Use WHATWG URL for url and email validation HOT 10
- Form with only boolean fields does not validate successfully HOT 2
- simple checkbox HOT 1
- build broken due to ecstatic? HOT 3
- npm audit issue associated with async lib <= 2.6.2 HOT 1
- Nested forms drawn field by field lose their full names HOT 3
- Disabled attribute HOT 1
- Strange solutions HOT 2
- Add a Promise API side-by-side with the callback API of .validate() HOT 2
- GHSL-2020-356: seeking security contact for your project HOT 2
- Caolan form missing datetimelocal
- Cut a new release? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from forms.