Code snippets for symfony 1.x


Refine Tags

Snippets tagged "formremotetag"

Degradable AJAX for form_remote_tag(), link_to_remote(), button_to_remote(),etc


My Snipeet works on the premise that in the JS helpers such as form_remote_tag, or link_to_remote(), the AJAX request action is called via an OnClick/onSubmit() when JS is enabled. For the sake of our argument, we will call the AJAX request action AMod/Aaction .When JS is not enabled, usually a secondary link given via either the 'href' or 'action' attribute is called. The default secondary link for these actions is '#'. Through my classes, when JS is not enabled, the secondary link brings you to myapp/yz_degradable_ajax_module/Process_nonajax_page action. All of the pertinant information is sent to that action via the GET method. The process_nonajax_page action will also be passed AMod/Aaction and the varables that the original JS helper was trying to pass to it. AMod/Aaction will be called via getPresentation and the values usually passed to it via POST or GET will be passed via $this->getRequest->getAttributes() because that is one of the only ways to pass values from one action to another. The HTML output from getPresentation will be put into a varable and redirects back to the original page. Once back on the original page, the create_div method intercepts that variable and outputs it to the user.

So to the lay user, when JS is not active, the page dynamically loading the new contents via ajax, reloads the whole page with the desired contents.

I created 2 files, 1 class and one module(with 1 action.class.php) that lets you to easily integrate degradable AJAX many of the Javascript remote functions

Place the yzDegradableAjax.class.php class in /app/lib/ . This file contains all of the functions and methods used.

Please let me know if this works for you or if my instructions are too confusing and I'll try to clarify. All criticisms are welcome.

Since the this Symfony Snippet section likes to go crazy whenever I paste in lots of code, you can view the code and course documentation at this form:
by Drew Lipsky on 2007-01-30, tagged ajax  buttontoremote  degradable  degradation  formremotetag  graceful  linktoremote