You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Update form-validation.md
Updates the server side code. Fixes#2391
* Update form-validation.md
I removed the server side code and updated the form code to use the right URL.
* Update form-validation.md
Update related to comments.
* Update src/v2/cookbook/form-validation.md
* Update src/v2/cookbook/form-validation.md
* Update src/v2/cookbook/form-validation.md
* Update src/v2/cookbook/form-validation.md
Co-authored-by: Phan An <me@phanan.net>
Copy file name to clipboardExpand all lines: src/v2/cookbook/form-validation.md
+23-18Lines changed: 23 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -333,21 +333,27 @@ We set up the total value as a computed value, and outside of that bug I ran int
333
333
334
334
## Server-side Validation
335
335
336
-
In my final example, we built something that makes use of Ajax to validate at the server. The form will ask you to name a new product and will then check to ensure that the name is unique. We wrote a quick [OpenWhisk](http://openwhisk.apache.org/) serverless action to do the validation. While it isn't terribly important, here is the logic:
336
+
In my final example, we built something that makes use of Ajax to validate at the server. The form will ask you to name a new product and will then check to ensure that the name is unique. We wrote a quick [Netlify](https://netlify.com/) serverless action to do the validation. While it isn't terribly important, here is the logic:
337
337
338
338
```js
339
-
functionmain(args) {
340
-
returnnewPromise((resolve, reject) => {
341
-
// bad product names: vista, empire, mbp
342
-
constbadNames= ['vista', 'empire', 'mbp'];
339
+
exports.handler=async (event, context) => {
340
+
341
+
constbadNames= ['vista', 'empire', 'mbp'];
342
+
constname=event.queryStringParameters.name;
343
+
344
+
if (badNames.includes(name)) {
345
+
return {
346
+
statusCode:400,
347
+
body:JSON.stringify({error:'Invalid name passed.'})
348
+
}
349
+
}
343
350
344
-
if (badNames.includes(args.name)) {
345
-
reject({error:'Existing product'});
346
-
}
351
+
return {
352
+
statusCode:204
353
+
}
347
354
348
-
resolve({status:'ok'});
349
-
});
350
355
}
356
+
351
357
```
352
358
353
359
Basically any name but "vista", "empire", and "mbp" are acceptable. Ok, so let's look at the form.
@@ -389,7 +395,7 @@ Basically any name but "vista", "empire", and "mbp" are acceptable. Ok, so let's
389
395
There isn't anything special here. So let's go on to the JavaScript.
0 commit comments