Submit Page
Closed this issue · 1 comments
Post to /submit
to get validation results.
There are two sets of error messages. Basic form validation and workshop validation (where we validate the files in the actual workshop).
All responses are JSON. A failed response is a request that either failed form validation or workshop validation or both. A failed response will contain the following key success
with a value of false
.
A successful response will contain a success
with a value of true
.
Form validation fail example
Note that form errors come under the key form_errors
. Maybe we can say something like "well the form validation passed but there were a few things wrong with the workshop", if the form passes but not the workshop.
Each field has a key and an array of messages. eg github-url
. The field maps to the input name attribute. The key of each message is an indication of the validation performed, that can be ignored.
Request
POST /submit HTTP/1.1
Host: localhost:3000
frontend: 37prg85r517h731i6a2s7l6ir5
Cache-Control: no-cache
Postman-Token: 267dcb8f-0f02-d28e-f6f7-5fb2439aaf81
Content-Type: application/x-www-form-urlencoded
email=not-an-email&name=&github-url=www.google.com
Response
{
"success": false,
"form_errors": {
"github-url": {
"regexNotMatch": "The URL \"www.google.com\" is not a valid GitHub repository URL."
},
"email": {
"emailAddressInvalidFormat": "The input is not a valid email address. Use the basic format local-part@hostname"
},
"name": {
"isEmpty": "Value is required and can't be empty"
}
}
}
Workshop validation fail example
Note that when you receive these errors, the form actually passed validation but there was something wrong with the workshop in the GitHub link you submitted. These errors come under the key workshop_errors
. Again, it is an array of arrays. You can ignore the keys and just display all the messages.
Request
POST /submit HTTP/1.1
Host: localhost:3000
frontend: 37prg85r517h731i6a2s7l6ir5
Cache-Control: no-cache
Postman-Token: e44180e9-67d8-773d-2e5c-aa27cfdbcab3
Content-Type: application/x-www-form-urlencoded
email=aydin%40hotmail.co.uk&name=Some+New+Workshop&github-url=https%3A%2F%2Fgithub.com%2Fphp-school%2Fcouch-db-check%2F
Response
{
"success": false,
"workshop_errors": {
"type": {
"isEmpty": "The \"type\" key in \"composer.json\" should be \"php-school-workshop\""
},
"bin": {
"isEmpty": "The \"bin\" key in \"composer.json\" should be an array with one entry which points to the entry point of the workshop. For example: {\"bin\" : [\"bin/learnyouphp\"]}"
}
}
}
The above could just be displayed as (just showing how the data structure can be ignored):
<ul>
<li>The \"type\" key in \"composer.json\" should be \"php-school-workshop\"</li>
<li>The \"bin\" key in \"composer.json\" should be an array with one entry which points to the entry point of the workshop. For example: {\"bin\" : [\"bin/learnyouphp\"]}</li>
</ul>
Success example
Request
POST /submit HTTP/1.1
Host: localhost:3000
frontend: 37prg85r517h731i6a2s7l6ir5
Cache-Control: no-cache
Postman-Token: 99559aa3-df9a-c890-4ad2-6074e71a6541
Content-Type: application/x-www-form-urlencoded
email=aydin%40hotmail.co.uk&name=Some+New+Workshop&github-url=https%3A%2F%2Fgithub.com%2Fphp-school%2Flearn-you-php
Response
{
"success": true
}
Done.