daveh / php-mvc

A simple PHP model-view-controller framework, built step-by-step as part of the "Write PHP like a pro: build an MVC framework from scratch" course on Udemy.
https://davehollingworth.com/go/phpmvc/
MIT License
782 stars 311 forks source link

How to insert data into the DB from the View #84

Closed CherukuriSiva closed 3 years ago

CherukuriSiva commented 3 years ago

Hi,

First of all, thank you for open sourcing this wonderful library. I have followed both of your Udemy tutorials.

image

After successful login, I am taking the User to the Home Page. On my home page,

  1. Users can enter some data in the input text field.
  2. They click "Place Bet" button.
  3. Data will be updated in the DB tables.
  4. I want to stay in the same and I do not want to reload the page.

From the View page... how can I invoke a function which is written inside a controller. I tried to use

<a href="/test/test">Test/a> and <form action="/test/test" method="post"> but browser is redirecting to new page. All I want to do is just update the data in the DB and stay at same page. I don't even want to reload the page.

I have created a controller ` *

}`

I am facing difficulties to achieve the above functionality. Maybe I have not understood the library.

CherukuriSiva commented 3 years ago

Do I need to use POST AJAX requests? If yes Do I need to create a separate PHP file for this AJAX request without following the MVC pattern...?

daveh commented 3 years ago

I just replied to your question inside the Q&A section on the course, but yes, you need to use an Ajax request. You can send these using post, getting the data from the form, for example like this.