I have a Kohana controller, and a route corresponding to it.
also, i want to make a form that will appear as a ajax modal, when a user clicks a link. The problem is: i want this form to be controlled by a different controller action, and of course, because i am using exactly the same data as in the view using the first controller action, i will have exactly the same parameters (in the second controller action).
The problem is that, having the same parameters and only different actions, my both controlers's routes will point in the same page. So...
How can i make an ajax modal form that will use exactly the same variables that the view in which i am putting the link to the modal form is using? is it indicated to make another controller action?
Thank you!
I guess you just should create 2 different views.
Related
I have a question related to form submission done in PHP application that's built in MVC architecture (self-written framework).
All examples that I've seen so far (including existing back-end frameworks) work this way that once form for adding record to database is submitted then certain method of controller is executed [say i.e. addRecord()], which triggers method of appropriate model. If everything goes OK then record is added and controller's method [addRecord() in this example] renders view of "index" page that displays table with records from database.
What I would like to achieve is to render view with form used to add records (the same that I used to add first record) instead of "index". Obviously I can do it easily by just rendering appropriate view from addRecord() (view with the form).
But the tricky point is when you check url you'll see the following:
The first time you enter it will be i.e.
http://project_name/my_controller/create
Once first form was submietted and you return to the view from addRecord() method then url will be:
http://project_name/my_controller/addRecord
What I would like to see is return to the original url, that is http://project_name/my_controller/create
Not sure if this is clear?
PS. Of course I could use AJAX call for form submission (that way I will stay at the same page) but perhaps it's possible to achieve the same without AJAX.
Thanks in advance,
On the controller you will want to submit to the addRecord route and do the processing. Have a check to make sure it was successful and on successful submission you can redirect back to the create route.
It is hard to give an example since you are using a custom made framework. I use slim which has a redirect method for a route. If what you have made does not have something like that then using should do the trick.
header('Location: '.$createUrl);
die(); //or exit
I am working in laravel 5.1. I have three pages in routes Home,show,short.
I also have blade file for home and short routes
I have a form on home page .After submit the button on home page I want that
(1). the data will be save at the database via post request which code has been written in a method postdata() which routes is show..
(2). I want to display the results based on the inserted data after doing query from database which code has written in showdata() method of short route .
I want all that happen after clicking the submit button without refreshing the page.but my problem is that i have two routes and in url of ajax method how can i give two url. please suggest me the better and efficient way to do that.
how I can call an action from the view of another action, knowing that the 2 actions are belong to the same controller ?
the controller is named FilesController, and the requested action is named Subscribing.
Actions shouldn't really be called from within the view. The view should only have data fed into it that will be represented by the view code itself. Views can, however, call other views. You may want to look at how your logic is structured to see if there's a different way to go about doing this.
There is one way, though, and that's via ajax. You can make an ajax call via Javascript/jQuery to a controller, and then have that controller send back a view, which is then placed into a specific area of the original view file.
I have two views from a form, one is loaded in my codeigniter index, and another is loaded in its on function. how do i make the form work so that when i click submit on the first form it loads the new view/function as the new
if i understand your question,
i think you need to set the action of the first form to be the url of your second controller
<form action=/controller/form2 >
or you can do a redirect
or you can simply load the form2 instead of form1
I'm using the Zend Framework and I'm about to hack up some of my controller code to do something that seems like there should be a pattern for already.
Currently when I only have one form, the form's action points back to the same action and controller as the one that generated the page. The controller's action function then verifies the form and if verification succeeds, does the desired action. If verification fails, it doesn't perform the action and the page is re-generated using the form that was validated so error messages appear in the correct place.
My situation now is that I have an action/controller that creates two forms and a list of items to the view for display. The view displays the list (say, for example, a list of users) and shows the forms (add user and create role - just as an example). What is the correct "Zend Framework" way to handle this? Should each of the forms' actions be pointing back to the same action/controller? If so, how does one handle validation?
My guess (and how I'm going to proceed for now) is to point both forms back to the controller, figure out which form was submitted, validate that form only, perform action on validation, or re-generate view on failure.
Yes. Let each form have different submit name and validate them based on that. But beware, when you validate wrong form, the error messages will appear ;) So test carefully.
You can submit the two forms to the two different actions of the same controller, and extract the list generation to a third method, and call it from indexAction, and the both form submission actions.