Displaying a Live Preview of a Form while editing in Drupal - drupal

I have developed a custom module which creates a specific content type in Drupal and allows users to add Images and some text. Now I want to add a preview section to my module for users to see the final out-put, the preview with real Images and text content while they are completing the form. I would like to know if this is possible to do Drupal and if so, what would be the best approach.
PS. I don't want to do any hacks and ruin the Drupal core.
Cheers!d

You'll probably need to make this custom and might want to consider the Drupal ajax framework for this. There's a question Adding AJAX to existing node form on DrupalStackExchange providing an answer for ajax use with the Drupal Form API.
In your custom module upon the custom code you already have, add hook_form_alter() to hook into your content type by$form_id and implement ajax on your form elements as the answer in the link describes. Then you can add a form field of type markup in which you render the form elements ajax callback output.
$form['live_preview'] = array(
'#type' => 'markup',
'#markup' => $some_ajax_rendered_output,
);

Related

Write the content page 'Home' on the code or let the user customize it?

Let's say I have to code the page 'Home' of this site, what should I do as a programmer? Write the content in the template and if the user needs a modification make him call me or show the content by reading a specific posts of a determined category?
For example, create a category 'slideshow' and loop through it and add as many slides as posts are or a category 'why love us' and do the same?
How senior programmers in WordPress face this?
You have create one template as you say that will be home, Now if i am a developer for this site , i will divide this i.e.
Slider => May use plugin or custom post type.
Why Love Us => May be a custom filed is this is fixed in size, or may create custom post type
Our Teachers => Will be a custom post type.
Courses => Another custom post type
Testimonial => Another Custom post type
Gallery => It is easy to use plugin or wordpress built in media gallary
Blog => Will be popular or recent post
Other general things will be a theme options
So, you can manage your back-end like this so use can easily understood and easy to modify or update content.

Drupal 7 - Taxonomy terms based on pages?

No idea if this is the best way to do this but here is what i'm thinking.
I have a content type called 'Widgets' and each widget is a little piece of content. I wish to then have a generic 'View' which goes off and grabs all the widgets for the current page that the user is on.
Here is how I see it working in my head.. just not sure how to do it.
-When creating a content 'widget' the admin can somehow select a page they want it to appear on from a list taxonomy terms based on the site structure (as new pages are added they are also added to this tree automatically somehow)
-When a user then browses a page the generic view then works out what page the user is on and fetches all the widgets that have been tagged with this current page
Is this possible? and if so can someone please give me some pointers.
I figured this out, in the fields for the main pages you can add a term reference field that allows you to enter a new tag into the vocabulary.
The 'widget' content type can then select this new tag using a term select field. My view then automatically displays it because it is related.

What's meaning of '#programmed' attribute of a form array in drupal?

What's meaning of '#programmed' attribute of a form array in drupal?
I didn't find any documentation for it in drupal.org
Drupal allows you to submit forms from a programmatically, which can be really useful for making comments/nodes etc from a custom module. '#programmed' is set to true when a form is submitted by a function using drupal_execute. see more here: http://api.drupal.org/api/function/drupal_execute/6

How do I put a custom version of node/add form in a view using customfield in drupal 6?

I'm trying to add a pre-filled 'add reply' form to a view of nodes. Reply is a content-type (reply) with certain fields that need to be prefilled based on what is in the view. This way a user can see only the selected fields from the node/add/reply.
At the moment I'm building the forms manually - copy the form from node/add, do some modifications using php & views customfield, but I would like to be able to just push default values to some fields and hide some others and then make drupal render it with all the javascript glory like date select etc.
Can this be done?
How about using Form Block to place the node add form on a page in a block below a view.
About conditional defaults... I guess javascript.

Drupal Nodereference in a custom form

I have a custom Drupal FAPI form that supports a fairly complex workflow and I would like to add a Nodereference field to it. Although I've found people who have included Nodereference fields on custom forms, I have been unable to find any examples of the FAPI declaration for the field (other than this question which uses a text field with the Nodereference AHAH callback: Is it possible to customise drupal node reference and pass your search and a argument from another field).
So: what is the best way to add a Nodereference field to a custom form (FAPI)?
Bonus question: is there a simple way to allow for multiple values like CCK supports in a node form?
Starting learning ahah here: 'add another item' in non-CCK Drupal forms
Someone who try investigate this: http://drupal.org/node/266584#comment-870376
You can go to check the article: Adding dynamic form elements using AHAH http://drupal.org/node/331941

Resources