Skip to content

Commit 2f30c9c

Browse files
committed
ch3 edits
1 parent 974e823 commit 2f30c9c

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

sfcasts/handle-form.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ Open up `src/Controller/AdminController.php`, and in the `newStarshipPart()`
1212
method, right below the form object, add `$form->handleRequest()`.
1313

1414
To pull this off, we need to pass the current request object to this
15-
method. You're familiar with this by now. Inject a `$request` from
16-
HTTP Foundation as a method argument and pass the `$request` to this
17-
method. You might be wondering what this `handleRequest()` is all about.
15+
method. You're familiar with this by now. Inject `Request` from the
16+
HTTP Foundation as the method argument `$request` and pass it to
17+
`handleRequest()`. You might be wondering what this `handleRequest()` is all about.
1818
It simply grabs the submitted data from the request, applies that data to
1919
your form, and now your form contains the user's submitted values.
2020

2121
## Checking Form Submission
2222

23-
Next, we want to know whether the form has actually been submitted or we just
24-
load the form page. That's a breeze — just write `if ($form->isSubmitted())`.
23+
Next, we want to know whether the form has actually been submitted or if we just
24+
loaded the form page. That's a breeze — just write `if ($form->isSubmitted())`.
2525
Then within that `if`, we can retrieve the submitted data with `$form->getData()`.
2626

2727
Since our form type has a `data_class` option set to `StarshipPart::class`,
@@ -32,7 +32,7 @@ variable and below `dd($part)`.
3232

3333
## Testing Our Form
3434

35-
Back in the browser, I'll quickly fill in the form. Hit create to submit it
35+
Back in the browser, I'll quickly fill in the form. Hit create to submit it...
3636
and voila, a shiny new `StarshipPart` object with the data we sent. Notice
3737
that no ID is set because Doctrine hasn't saved it in the database yet.
3838
I'll quickly add a PHPDoc above the variable to make PhpStorm's autocomplete
@@ -42,11 +42,11 @@ happier, and delete the `dd()` statement.
4242

4343
To save the new part, we need Doctrine's `EntityManager`. Inject it with
4444
`EntityManagerInterface $entityManager` in the method signature. Then, back
45-
in the `if`, add `$entityManager->persist($part)`, passing the `$part`
45+
in the `if`, add `$entityManager->persist()`, passing the `$part`
4646
object and next `$entityManager->flush()`.
4747

4848
Back to the browser, I'll set the name to: "Legacy Hyperdrive".
49-
Give it a fair price, and don’t forget about important note:
49+
Give it a fair price, and don’t forget about an important note:
5050

5151
> Be careful with high revs!
5252
@@ -64,10 +64,10 @@ shown exactly once. They are perfect for things like:
6464
6565
If you peek into `templates/base.html.twig` You'll see we already have code
6666
that loops over flash messages and renders them with nice styling depending
67-
on the type: success, warning, error, default. After saving the entity to the
68-
database, let's write this: `$this->addFlash()`
67+
on the type: success, warning, error, default. Back in our controller,
68+
after saving the part entity to the database, write: `$this->addFlash()`
6969

70-
First argument: the message type - it helps to control styling. Write
70+
First argument: the message "type" - it helps to control styling. Write
7171
`success` here. Second argument: the content of the message. How about
7272
`sprintf('The part "%s" was created.', $part->getName())`.
7373

@@ -79,7 +79,7 @@ process with a redirect. This is a classic best practice for POST forms.
7979
Let's return `$this->redirectToRoute()`.
8080

8181
We can redirect anywhere, but I'll send users back to the part list for
82-
convenience. It should be `app_part_index` route name.
82+
convenience. This route name is `app_part_index`.
8383

8484
## Testing the Overall Flow
8585

@@ -88,7 +88,7 @@ name, set a price, and for notes, I'll say:
8888

8989
> Do not exceed 120% core flux
9090
91-
OK, submit the form again, and there it is. Our success flash message,
91+
OK, submit the form again, and there it is. Our flash message,
9292
announcing that the part quantum reactor was successfully created. And if I
9393
try to refresh the page, the message is gone, so it was shown only once,
9494
and Chrome does not ask me if I want to resubmit the form again, so it was

0 commit comments

Comments
 (0)