2 years ago

Posting to database (form validation 101 video)

Posted 2 years ago by Mick79

Hi, in this video Jeffrey shows us various ways to post data from a form to the database. He finally lands on this way:


and here is the form

<form method='POST' action='/posts'>
                    <div class="form-group">
                        <label for="exampleInputEmail1">Title</label>
                        <input type="text" class="form-control" name='title' placeholder="Title">
                    <div class="form-group">
                        <textarea class='form-control' title='body' placeholder='Body' name='body'></textarea>
                    <button type="submit"
                            class="btn btn-primary">

I'm struggling to work out how the controller knows what to post where. I have come to the conclusion that for this way to work, you need the "name" fields in your form to match the column names in your database.

Would that be correct?

Please sign in or create an account to participate in this conversation.