Drupal 7 Webform fills hidden field with current node title - drupal

I'm using a webform as a block on all the pages from a specific content type. The form is the same in all, but on the list of submissions I want to know which page the user was seeing. I thought a hidden field, and a default value of %title would do it, but it's not the case. I tried a bunch of other token values, and a lot of them do work, but none of them gives me an identifier of the current node.

I think the reason it's not working is because the node element of the webform tokens refers to the node of the webform itself, not the current node page. Why webform doesn't use the in-built token system I have no idea, seems like a missed opportunity.
Looking at the webform module I think the easiest way to get this done is to write a quick custom module defining a single table (two columns, nid and url) and then implement hook_webform_submission_insert() to save the current $_SERVER['REQUEST_URI'] for all webforms. You can then use hook_webform_submission_load() and hook_webform_submission_render_alter() respectively to re-attach the URL data to the submission and display it to the page.
You can find all of those hooks in the webform_hooks.php file included in the module, they're pretty well documented.

Related

Auto-associate page metadata?

Links require SDL Live Content login.
We can choose default schema (and a mandatory option) in folder properties. New components in these folders will have the schema selected with appropriate fields filled out.
We can choose default page template for structure group (SG) properties. New pages in these SG will have the page template selected.
Do we have a similar option for page metadata such that in a given SG, author gets both page template and predetermined page metadata (fields) for either:
page creation
page template selection
We can do this easily with Inline Editing (SiteEdit) and page prototypes. But how would you configure or implement this type of requirement with the Content Manager Explorer?
I'd say there are a number of ways to achieve this:
1) Using the UI 'Page Types' - If the page you are using as the page type this should keep that same metadata. *I've not tested this!!! maybe you could confirm?
2) GUI extension - When a page template is selected a page metadata is selected based on the page template.
3) Event system. I'm not sure how well this would work as it would likely have to be on the creation of the page (checking if a default template is used) or on save if a template is used and a metadata schema isn't selected... but then if there is mandatory metadata etc etc.
4) The page template. This will set the metadata (on publish or preview) - or warn a user that a specific metadata should be set for this given page template.
Hope this helps.
Thanks
John
Very interesting question and I can see the benefits of this functionality for Editors. I don't have the answer for you. But AFAIK, even event system might not be relevant here since there are no events fired when you start creating a page unless we save the page. GUI Extension a possibility?
When you create a new item, this takes place via the GetNewitem() method in the API (or GetNewObject() in old money). I always thought there should have been separate events system hooks for this activity than for that of modifying an existing item. I once suggested this on ideas.sdltridion.com with regard to Components, however someone referred me to the OnSchemaGetInstanceDataPost event hook, and the discussion was over.
So in the case of a new component, the schema is automatically queried, and via the hook, you can interfere with the default data. So far so good, but I still believe that it would be generically useful to be able to modify the default data of any item type when first created.

Drupal 7- Passing contextual filters from external form

Here's what I'm trying to do:
I have a form with two fields that appears on each page of the website and a View that has two corresponding contextual filters (arguments).
My problem is I can't seem to make the connection between the form fields and contextual filters, because Drupal Views expect them to be passed like /path/filter_value_1/filter_value_2.
I've searched for or tried the following methods
Get contextual filters fetch their values from $_POST or $_GET variables
Use URL Aliases to route /path?filter_1=value_1&filter_2=value_2 to /path/value_1/value_2
Setting the action to direct me to a php file which makes a header redirect (this actually works, but I don't like this solution)
Any ideas are welcome!
Thanks,
Peter
Ok.
Initially I thought exposed filters can only be used on the same page as the view.
Then I found the "Exposed form in block" option which seems to do the trick.
Now off to customizing exposed filter forms :-)

drupal replacing default nodes with views page

I have created a page view using field style to display a list of teasers as I want. fields configuration in views allows us to link the field to it's node. but what if we have created view for node detail page and want field to link to it's relevant view.
I had the same question, and after a bit of research this is what I've concluded:
The views module isn't intended to replace a default node view. I say this because of the level of difficulty involved in doing this and the lack of information on how to accomplish this. Ryan Weal has posted a way to accomplish this by editing your node template that doesn't look too difficult to accomplish, and here is the link.
However, it seems that a more popular solution, especially if you are like me and don't like to get into editing theme files. You can use the Display Suite module to effectively reformat the default node content as you would like.
I'm not sure if I understand you properly, but it sounds like you are wanting to display a view in a page view of a node?
In order to do this, you could:
create a small module, using hook_nodeapi() or one of the D7 replacements for this function in order to insert the output of the embedded view into this page's content, by conditionally adding a $content element when the node is of the appropriate id
or (easier, but requires allowing input type PHP) embed the view right on the page.
http://thedrupalblog.com/embedding-view-drupal-6-using-views-embed-view for information on embedding views

Drupal6 - Display specific View from a specific user in page

I need a help displaying a specific View result in a page which the user created it.
story...
"User X has created a Page called My Store and UserX has products which was created in custom Content Item."
Now how do I show this UserX's products in his My Store page?
I have already made a view called User_Store_View, I added a Page Display and on Page Settings:Path, the value was "node/%".. now I guess my problem is on the Arguments?
The path should be something like my-store and it should have an argument of user id. Given your requirements I think setting the default behaviour for the argument being invalid or not being supplied to an empty result set would be the most sensible(I think the default is show all). That may be all you really need.
However, if your product is a type that you've created yourself you will need to do some behind the scenes wiring to expose all your fields to Views; it's almost always better to build a content type using CCK so it's already hooked up to Views. And D7 is a different beast in this regard, with fields part of core and whatnot, so I can't help you out there.

How to create a custom form in drupal

I need help on how to create a 'custom form' using the same fields provided by cck.
Drupal gives you the ability to add fields to 'nodes' and how to theme their output. But I would like to be able to post a data from my own form (that pops-up) and sends data to the drupal database using the same drupal cck.
How do I access the specific form inputs to add data to my content types ? because the default form is kind of 'ugly' and loads on different page(without ajax).
Help would be much appreciated
There are several routes you could go down.
The easier option is to use the Webforms module. While this gives you similar fields to cck, they are not exactly the same, and if you have a module that implements a specific cck field type, it won't be available to webforms.
The second choice is to write your own module using the forms api. This can mean a lot of learning, add it takes time to get up to speed, but ultimately you have total control over how your form will look and behave. The forms api doesn't give you exactly the same fields, but all the tools are there to create them. Sometimes you need to hack open a module to find out haw a specific field is implemented.
A third option would be to use cck itself. You could create a content type and add the field types you want on your form. You would them give users permission to create but not view or edit the content type. The form submissions would them be nodes on your website. This would make me slightly nervous, so make sure all your permissions are correct!
The second part of your question: you can use a theme file to override the appearance of most forms and make them pretty.
James

Resources