📄️ Section Intro
Now that we have a more intricate router, autoloading and namespaces, we can now focus back on CRUD operations for our listings. We'll be able to create, update and delete listings. We'll start with the create form, but before we look at inserting the data, we need to validate it. We'll be using a validation class that we'll create in the next video. Then we'll look at some other sanitization techniques. Of course, we'll also be using prepared statements to prevent SQL injection attacks.
📄️ Validation Class
Before we jump into the create form and store data in the database, I want to create a class for input validation. This will include static methods, because we will not need to instantiate this class. We will just call the methods statically.
📄️ Form Submission and Sanitation
In this lesson, we will start to hook up the create form, sanitize data and we will also display errors if there are any.
📄️ Implement Validation
Now we will make sure that required fields can not be empty.
📄️ Database Insert
Now we are ready to insert our data. This is going to seem harder than it really is only because we have a lot of data/fields. If we were doing a todo app with a title and body, it would be much simpler. I wanted to do something more realistic though. So we need to piece together the query and the data.
📄️ Delete Listings
Now we want to be able to delete listings. In the show view, you already have an edit and delete button from the theme HTML. You may notice that the delete is actually a form submit button. There is a little bit of a process to this since the browser can only make GET and POST requests. We will need to use a hidden form field to send the DELETE request.
📄️ flash-messages
Flash Message
📄️ Edit Form
We almost have full CRUD functionality for listings. We just need to be able to update them now. Let's create an edit form for listings. Create a new file in App/views/listings called edit.view.php.
📄️ Update Listing
We have our edit form. Now we need to make it work and update the listing in the database.