course when you register on learnphalcon
The examples on this site are currently tested to work on Phalcon V3.4 and Phalcon Devtools V3.2 Some issues may arise when using later versions.

Please get in touch or post a comment below the post if you encounter a problem.

Now that the booking fee is automatically calculated we need to modify the booking form to remove the booking fee field - which should not be entered by the user. Given that there is a cost associated with the booking we need to notify the user of the final cost of the booking so that they are aware of how much they will have to pay when they show up to take their court.

Removing the fee field from the court booking form is easy. Edit the file /app/views/booking/new.phtml and remove the <div> block highlighted in red.

The court Booking form now looks like this

As a final step, we need to notify the user of the Booking fee after they have saved their booking. I admit that this is a little clunky from a UX perspective and it would make more sense for the user to be notified as to the cost of the booking before they commit to it. I choose to ignore this on the basis that in the tennis club most people are very familiar with the cost of booking a court and there won't be any great surprises but it still makes sense to remind them how much will be due when they show up to play.

Modify the new.phtml view in the booking Controller calls the createAction() function in the BookingController. This then sets all the values in the booking object before the $booking->save() function is called which will commit these functions to the database. If there are any validation errors they will be handled at this point.

If the booking is saved successfully the code generated by the scaffolder sends the user to the edit view of the booking. This doesn't really make much sense as it is unlikely a user will need to modify a view that they have just created. This is easily rectified.

Modify the code at the bottom of the createAction() function as follows - replace the block of  code outlined in red with the code supplied

Replace the code outlined in red with the following code to let the user know how much they will have to pay when they show up to play tennis.

$this->flash->success("Booking created. Your booking fee is €" . $booking->getFee());

Now replace the code outlined in green with the following code so the dispatcher routes the User back to the Search bookings page when the Booking has been created.

    'controller' => "booking",
    'action' => 'search'

Now when the booking is created the user will see the following screen