Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fuel Forms possible in Modals?
  • Hello,

    is it possible to fire Fuel Fiorms also from Modal Windows?

    Actually I have View and Delete via a Modal Windows and I am thinkung about having also Create and Edit in that.

    Is that possible? How can I do that?
    I think I have to bring the data somewhere back to the Fuel URLs?

    Thanks
    Kay
  • Hi kay899.

    I guess your issue is more a "general coding procedure" question than a FuelPHP specific question. But I want to answer it the best I can with the experience I got in such modal things ;)

    Now, there are no limitations to you putting any form into a modal window. You just need to answer two questions (for yourself):
    * Do you want to include the code of the forms within another page (e.g., you have a /list/ page that has three modals (one for create, update, and one for delete) hidden in the source code and on clicking the respective anchor you pop-up the corresponding modal)?
    * Or do you want to use AJAX for dynamic modal creation?

    The first case might be the first choice, however, you need to consider that (a) every item on your /list/-page needs to be uniquely identified to a modal or you do some e.g., jQuery-logic that populates the form-placeholders with values from the list-item.

    The second choice is most likely the choice you should go for on the longer run. This is mainly for two reasons: You separate view-code by logic and you're still supporting those that don't have Java installed or activated on their browser.

    Set up the page to work without AJAX i.e., create controller actions and views that take care of creating, editing, and deleting items.
    Then, you put a placeholder modal into you /list/-page and add ajax-events to clicking the edit, create, or delete link. This actions need to be caught by jQuery and perform an AJAX-call to the corresponding URL (which actually points to the previously generated controller-action) and get the content which jQuery will parse into the modal.
    On your controller you now would just have to check whether it's an AJAX-call or not and then either return the whole page (with <head> and stuff) or just return the form.

    For submitting the form you can either make the form submit to e.g., the controller-action "action_edit" where you first check for \Input::method() == "POST" and then do the updating routine just like without AJAX.
    Or you do it with AJAX again but need to modify the "action_edit"-logic to return the proper responses for an AJAX-request.

    You might also want to make your controller extend the Controller_Rest to separate POST and GET logic.

    I hope, my answer shed some light into your darkness ;)
  • Hi philipptempel,

    thanks very much for your great answer. This really makes me start thinking.

    Actually I have only the View and Delete issues in a modal, which are done vi your first idea.

    I think it makes sense to have all elements via your second way with your AJAX calls.

    Do you have one example how to do that?

    Thanks
    Kay

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion