Has anyone faced this feature request and were able to resolve it? We have a webapps that is capable of creating a form as a template. That template will basically be called and user will need to fill out the form before it got push into the db. So the form is created directly inside the application and the fields, labels and variables are all defined when the form is created by user using the apps. Since the form is always going to be changing, I can't hardcode the activity in android and have to create it manually and recompile every time a new form is created. Is there a way for us to read the label, variables setting that's stored in db either in XML format or called as JSON and build the form dynamically everytime the form is called via android? Am I making any sense? Please advise?
Yes. Everything you do in XML (view creation, positioning etc) can be done dynamically via code as well.
A simple way would to be to put a single ScrollView with a single LinearLayout inside it. Then in your activities onCreate(), you can read your JSON or XML file just like any other file (you can store this is assets folder or maybe query it from your backend). Then depending on your variables you can initialize and add TextViews and EditText's to the LinearLayout. The ScrollView will expand infinitely to accommodate all your form elements.
Just make sure you don't do any long-running operation such as querying from your backend or reading from your file in the main UI thread. Another caveat is that if ScrollView does not recycle views and putting too many views in it (say more than 20) can make your application run out of memory and slow down/crash.
You can create a form in relative layout having all the fields/view you require in XML, then on Runtime in code According to your label name in db or whatever you are using, you can hide/show the fields/view which are needed dynamically. This way you can preserve the position and setting of each field as when 1 view is hidden other views are going to take its position.
Related
In page.tpl.php of Drupal, the following code has variable $page which contains the html codes that are required to render part of the webpage.
<?php if ($page['content']): ?>
I'm trying to retrieve the updated content from DB at an interval and update a DIV without refreshing the whole page. My question is, where can I find the DB query codes from which $page came about?
page['content'] variable
When Drupal displays the "content" variable, think of it as big array of data that will be rendered in a specific section of the page.
Before that happens, it either retrieves data from the block settings of the native interface (block visibility settings) or from custom modules that override this original settings like f.e. context (https://www.drupal.org/project/context).
>> Template files
The template files are kinda like the last stop where data is built and ready to be rendered and delivered to the client.
In general, the best practice is keep the render templates intact and keep the logic and variables manipulation at the pre_hook levels .
>> So if you do wanna have "programmatic" control over what you can display you can f.e.:
Render specific nodes with "node_load" function and then using node_view($node)
f.e.
$node = node_load(23); //23 is random a node id
if (isset($node)) {
$node_data = node_view($node,'default''); // here's my node display data
print drupal_render($node_data); // here's my html
}
Render templates that aggregate different data with the "theme_render_template"
https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_render_template/7
Render views by using views_get_view('view name') like stated before.
Hooks like these might help you in adding/modifying the content you wish
template_preprocess : (hook templates
hook_node_view : (alter node array data before render)
page_alter : (alters page variables like content, header and so on)
hook_views_pre_render : (views is built, can alter render process)
hook_panels_alter : (for page manager and ctools approach)
>> Database queries
Doing a straight query to the database can also be done through the database api and then rendered, but be aware you might miss out the drupal hook power and end up having high maintenance code that escapes the convenient and safer Drupal way.
Hope it helps!
That content comes from inner node templates (if you are displaying node on that page) or i.e. view template....or...depending on what page you are displaying. But if we assume that you are displaying node page in some content type "player" you created content will "come" from template file "node--player.tpl.php"
https://www.drupal.org/node/1089656
Inside that file you can do database query (by using Drupal's database api) or even easier use Drupal's views module to query database:
https://www.drupal.org/project/views
What you are trying to do :
"I'm trying to retrieve the updated content from DB at an interval and update a > DIV without refreshing the whole page"
, is usually done with Javascript sending Http requests from the browser and not from PHP code executing server side in a Drupal template file, and is named AJAX. Doing AJAX with Drupal could be done in multiple ways, one of the recommended ones is with the use of the "Drupal AJAX Framework", resulting in PHP code with "Drupal AJAX API" calls server side that will generate for you the appropriate JavaScript client code renderer in the Drupal's output. The Drupal "Views" module may also help in this task, being "aware" of the Drupal AJAX framework. A good understanding of general AJAX mechanisms and of the Drupal AJAX framework are required to do this properly.
I have a tournament with multiple divisions and multiple forms for which I use gravity forms.
There are times when someone requests to be changed to a different division. However, I am unable to move the competitor from one division to another in gravity forms, as the divisions are each using a different form ID (and they have still not developed a method for helping with this).
How would I go about moving a SINGLE ENTRY from one gravity form to another forms entry list please.
We have many teams at the tournament, so mass export and import is not what i am looking to achieve. Its about being able to move a single entry from one list of entries in one form to another forms list of entries?
ANY help would be greatly appreciated. Even a simple "use this method" in general terms will help me greatly. Would I use some form of JQuery fiddle, a php script, an sql script or what please as Import Entries is not available currently in GF
Regards
You can not do that, but instead maybe you shold design your form to include all types of submissions logic. I mean you can put a drop-down field at the beginning of your form. Then you can use https://gravityview.co/ to edit your single entry field.
I have a workaround for this which i am using in one of my current projects for http://projects.dzign-r.com.au and that is,
1) export both of the the forms (i.e the one from which you need the field to move and the other to which you need this field to be moved to) and it exports these as json files
2) search for the field ID that you need to be moved to another form, cut its json code from the json file and paste it in the other form's json file where you need it to be moved to
3) then import the form back. and test it to make sure it works as you want it, (as a caution you may change the field ID after you paste it in new form to be something which is not used in this form already).
4) once u see everything is fine u may just delete the old form?
I'm trying to add the editiedon field to the modx manager pages so my users can edit the value using this bit of documentation as a start point:
http://rtfm.modx.com/revolution/2.x/case-studies-and-tutorials/adding-custom-fields-to-manager-forms
Which does work, but:
how can I make that a date/time field?
how can I place it in the settings tab of the given resource?
Isn't input type="date" the answer to the first question? I'm not sure how you would do the second part, unless you managed to get the rendered content and splice it in there somehow (unless theres som hidden specified method).
Otherwise, you could always solve it with regular form customization. You'll want to create a TV of type Date, and give it a custom default data through a snippet, that just fetches the current resources editedon value. I guess you only need to update the resource/update form set. Under the template variables tab of the set, make sure your TV is connected and change the region value of it to "modx-resource-settings"
There are two different ways which have their own pros & cons.
At first you can use template variable with Date type. It gives you correct ExtJS component for dates and you'll see calendar in TV's tab.
If you'll choose this method you have to create a plugin which invokes on OnBeforeDocFormSave event. There you can redefine modResource editedon property from your TV and it will be saved in proper way. Also you may invoke another event(OnLoadWebDocument). There you can set modResource editedon property from you TV if you want to see correct data.
Pros:
fast calendar integration to the one of modResource's tab
you can use Form Customization for security reasons. It's rather easy and from the box.
Cons:
Additional TV which complicates modResource updating process a little bit
Another method is more complicated (you need skills in ExtJS).
Create plugin which invokes on OnDocFormPrerender event. You can add JS to the modResource page there. Your scripts should render new custom tab to the document where you can add your special field with calendar. So there is special ExtJS component in MODX for these purposes. And of course you need events from first method for loading and updating editedon value.
Also you can just render special field to the existing tab instead of creating new tab and rendering your custom field to it.
Pros:
you don't need TV anymore
it's flexible
Cons:
it's more complicated and takes time
P.S. You can view Xlexicon github repo. There you can find example of rendering new tab and manipulation with modResource properties.
Also you can check modAvatar extra for MODX. There is an example of manupulation with existing tab.
Context
I'm working on a project that I'd like to make more dynamic with PHP + AJAX.
I'm using jQuery for the AJAX part because I totally suck in Javascript, and anyway it seems to be worth something.
I reached a point where my application needs to use a form to send a post, and I want to use an ajax call to perform this action. In the page I'd like to send the post, there is also a list of the most recent 15 posts submitted.
First question: Should I just forget about it and use just PHP?
The action
The user writes something in the <textarea></textarea> and clicks on a <a id="myPostSubmit">Submit</a> that is the handler that I'll manage on the jQuery script with something like $("#myPostSubmit").live('click', function() { /* here i make the ajax call */ });. If the post is successfully submitted we are going to do something (I'll talk about it in the next section), either we will alert the user using my showAlert(text) function, that shows a black box for 4 seconds with the text in it.
Second question: Should I manage the click event in any other ways? Should I create a function, such as sendpost(post) and attach it into the HTML onclick="" event?
If the post is successfully sent
I'd open a discussion about 2 options:
We refresh the page [not actually
loading the entire page but making
another ajax call that retrieves the
posts lists and makes disappear the
old one, load the PHP file to
retrieve the new posts (including
the one we just sent), and then make
the post list appear]. Pro: 1) We are sure that what the user is reading after the post list is loaded is the real post sent. So it actually double checks the action. 2) We load also some possible posts sent in the mean while. Cons: 1) We have to create a PHP file that gets the post list template, slicing the template of that page in 2 files. 2) It doesn't really seems that smooth to me.
We just use Javascript to get the post template, add it to the list. Pro: 1) We make it really smooth, without reloading the entire page. 2) We don't need of any PHP file to reload the page. We just use Javascript (jQuery). Cons: 1) How do we get the post html template to add it to the list? 2) How do we get the user (logged) informations without PHP?
Third question: Is it better the 1st or the 2nd solution? Would you provide a even better 3rd solution?
The PHP page
The PHP page that will receive this AJAX call is : ?p=action&a=sendpost. The page require $_POST['myMessage'] to be set and not empty and nothing else. The page itself will get all the user infos from the cookies and will manage to perform the needed query.
The application
It is divided in 3 parts: App, Template, Library. Basically each page of the application has its own .app.php and .tpl.php file.
The .app.php file manages the building
of the basis of the page, using classes
and other stuff from the library. In
our case it retrieves datas from the
database and put them into
variable.
The Template is called at the end of the .app.php file. The .app.php file send to the template the retrieved data and the .tpl.php file outputs them.
The library is used to contain the classes and functions we need in the application file.
Fourth question: Is this a good way of manage my web application?
Edit: What about returning the alert message to the user?
I read about an option, inside $.ajax() that will manage the response on success or in error. The documentation about it is very simple and I didn't get it.
Fifth question: How should I return (from the PHP file) the error
or the success?
First question: Should i just forget about it and use just PHP?
Well, you application will relay on JavaScript if you use ajax, this days i think it just fine ;)
Second question: Should i manage the click event in any other ways? Should i create a function, such as sendpost(post) and attach it into the HTML onclick="" event?
Create a function and bind onclick. Code will be more readable ;)
Third question: Is it better the 1st or the 2nd solution? Would you provide a even better 3rd solution?
My solution: ajax submit the form and on callback insert new comment in to the list or display error message if user can't comment.
Check jQuery serilize() for submitting forms data with ajax.
Fourth question: Is this a good way of manage my web application?
It's just fine ;) When you application get's bigger you will have to redesign it, but don't do it know, do it when current solution becomes to hard to work with.
Read some good book on building MVC framework. And on programming patterns in general.
You seem to be on the right track with everything. There are lot of opinions called "best practices" about how to exactly attach event handlers, how to reload the data on the page and how to organize your application, etc, but I personally would rather build more software instead of worrying about details like that. The details will come to you eventually.
I personally find that updating whole chunks of server-side-rendered HTML on the page is more robust solution, but I have seen people getting excellent results with templates.
I'm trying to build a sort of resource allocation form. I'd like to be able to print a table from a database, and then allow users to click on each cell that they would like to reserve. Also, being able to drag and select multiple cells. Then send all of this via $_POST to another php script.
Problem is, I have no idea where to start.
Any suggestions?
The first and most critical thing you're going to need from what you described is a bunch of hidden fields to store the information you're interested in. You would have to write javascript code on the client side to store the users interaction with your page into these hidden fields.
To receive data via POST, you will need <input type="hidden" name"some_field"> for every bit of data you wish to "know" about that was changed on your page. Table information is not transmitted in a POST operation if it's just text, so you can't see the layout of the modified table on post back to the server.
If you don't have to POST this data to another form, it is probably a better idea to make callbacks via XMLHTTPREQUEST as the user interacts with your page, but I don't know the requirements of what you're trying to do.
I wrote one for my school recently; the trick is to either use buttons/links or addEventListener the cells to JavaScript. If you want the source code to my app, download this zip file:
http://azabani.com/files/busbook.zip
Edit:
My system works in the following way:
addEventListener to cell clicks, calling book()
book() then sets location to book.php
book.php does the database work
book.php sets the location header to immediately go back to the viewer
The system knows which week view to go back to based on session variables.