I’m a super beginner in php, and I’m using a MVC php framework called Yii. I can’t seem to find any articles that explain how to get values of html elements with PHP. Everywhere I look it’s all about how to get values from form fields after a POST in some other view. Is there anyway to get field values and send them to a controller in PHP and just come back to the original view.
In .Net MVC I just use jquery to get form fields and do an ajax call. It’s not sensitive data so I’m not worried about security. I like ajax because I don’t do any page post back, I just send my data over and remain on the same page I was on.
Is there any way to do MVC AJAX kind of thing with PHP? Read html element values and send them to a controller for data manipulation?
It works the same way. Yii comes bundled with jquery, so you
to some controller function, do whatever you want with it, and return a response, with php’s
echo.If you already know some jquery, then the client-side shouldn’t be much different from .net mvc.
Edit:
To add a
<script>to the generated html see registerScript.To create urls use the createUrl function.
To add ajax options to html tags code looks similar to:
Every html tag generator helper function takes htmlOptions array, where we can also pass ajax options.
While reading these values in the controller:
Hope this is enough for you to get started.