Creating a custom contact page -- page-contact.tpl.php - drupal

I'm new to Drupal. I want to create a contact page, so I copied page.tpl.php and renamed it to page-contact.tpl.php. I created some new elements in the page, so I can see that if I click on the "contact" link, I'll know that I went to the correct page.
Right now I don't see any change. Was there something I missed? Do I need to do something in the admin settings so Drupal knows which file I need to open?
I also tried clearing my cache.

In theory, this is a valid approach. Problem is, you'll be able to create a new layout for your contact page this way, but not necessarily change the contact form. If you wish to alter the form as well, I'd recommend using the webform module. It's pretty flexible when it comes to creating contact forms, plus, it creates a node, so you can style it with ease (either in you standard node.tpl.php or - even better - in node-webform.tpl.php). This is what I usually do.
There might be other solutions too, but it would help if you made it clear what kind of alterations you wish to introduce in your contact page.

When you say cleared my cache do you mean the browser cache or drupal's cache? Ensure drupal's theme registry has been cleared by going to /admin/build/themes, or logging out and back in.
I also recommend trying the webform module as mingos suggests.

Drupal core's built in contact module does not use any templates, so you'll have to use something like Webform if you want a per-contact template.

Related

Drupal know from where things are showed

I have a strange question but I don't find any hint about that (if it's possible), for a drupal 7 website I have to modify some content of a page in the backoffice, but I really don't know from where some content of this page is created (a table, similar to a view table but not a view table).
I just want to know if there is any way to show which php function the page use to finally be showed. I know there is something like that for the theme (drupal theme debug) but I don't find something for my case.
Any idea ?
You need PHP profiler to check all functions called on page, there's a module for Drupal7 for XHProf integration. But I would suggest you to use your browsers inspector as mentioned by 2pha before. For example if there's a form on the page just use the form ID to find it. Custom classes are very useful in these cases, parts of the html codes etc. In your case search for table headers...
The code you are looking for is most probably in custom modules and the
general suggestion is to keep you custom modules in separated folder from contributed ones.

Silverstripe URL Mapping

I'm trying to understand how URL Mapping works. I've gone through numerous pages, but I can't seem to wrap my head around what I'm trying to do.
Its really simple, I use DataObjects as pages approach and I have a member extension written to the member class. And I have the typical actions, show, edit, add.
So if I go to www.mywebsite.com/members/show/1 I can see the first user. If I change show to edit, I can edit the first user. Now if I go to www.mywebsite.com/members/add I can create a new user. This is working all as expected due to the functionality I created in the add method.
My problem is in the fact that when you go any website, you don't register to the website by going to members/add, you register by going to website.com/Register or something similar. From code management perspective, it is a lot easier for me to leave the code the way it is now. I don't want to have to create a Register page and move the code there, instead I am trying to figure out if it is possible to go to www.mywebsite.com/Register and have it load www.mywebsite.com/members/add. I am not talking about a redirect link that would update the url, I want users to still see Register in the url and not see /members/add.
Vice versa, if users were to go to www.mywebsite.com/members/add I want the link to update to Register or say page not found.
Is this possible with Silverstripe Framework?
I am not 100% sure, but I believe this is called URL Masking.
This is very possible, firstly I'd advise that you look over...
silverstripe-memberprofiles
...because even if you dont' want to use an existing module I'm sure there would be useful information. There is a great example of "pure" routing (i.e. silverstripe no cms) that leads on to "nested" routes - which is what I think you are asking for, so I highly recommend reading the slides below and then the created todo app
silverstripe-framework-building-without-the-cms
todo app source

Migating from CakePHP to Drupal, functionality question

(I've posted this on the drupal forum too btw)
I'm converting the company websites to use Drupal, or at least trying to check that its going to be the best way forward. I have a background in PHP development, and I'm currently using the CakePHP framwork. I've built this site (not my design) and I can see how to replicate most of the functionality using Drupal, most likely using the CCK module.
http://preview.tinyurl.com/yk6u8mt
As you can see from the homepage:
A user chooses a country.
The country is passed using an ajax call to a script that decides which phone is best based on 'in country' network coverage.
A div is shown recommending the visitor the best phone for that country.
I'm wondering how to go about this in Drupal, I'm definitely not after a step by step guide, I just want to know if this kind of thing is possible with Drupal, and what approach to use.
If someone can help that would be superb. Thanks.
Okay, so you've got a path you're defining in hook_menu, which is where your form is being presented - or else you've got it set up as a webform in a node, that could work too.
Either way, in your form you're going to be using AHAH - check out http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#ahah and http://drupal.org/node/348475 .
Basically, you're going to define another path in hook_menu that's of type MENU_CALLBACK, and which will receive the country as input, and then will return the div that you'll display on the screen.
One core example of AHAH that may be useful to you is where you're entering a password and it lets you know if the password is secure enough - check that out.
Edit: There's also some good examples at http://drupal.org/project/examples.
I would look into using CCK and views. you can set up filters for the views. If filters don't work, you have the ability to include php code. I have also successfully added jquery code in the header of a view through which I was then able to have my view filtered by what is typed in a text box.
Coming from CakePHP using Drupal is a pain in the a** - even more for developers.
It's application structure might be designed to ease extensibility but this only means you have a system to enable your own plugins and themes.
While modules are basically the M+C-part the themes are the V-part of an MVC-application. The problem is that this seperation is not very strict in Drupal - in fact you have to break it sometimes in order to make things work (e.g. you have to include a theme_mymodule_myfunction() into your module as default output which you then can override with your theme using mytheme_mymodule_myfunction() ) And don't even bother looking for classes ( see http://drupal.org/node/547518 ).
Also there is no real link from a module to a theme. On many occations this is a good thing as you can switch modules and themes seperatly without creating a problem. For application builders coming from CakePHP (or any other framework) you often feel a lack of "wholesomeness" - you create parts for a base software and have to live with it's drawbacks.
IMHO I wouldn't recommend this step. Drupal is fine if you have to manage a website and might add a few modules to add neccessary value (image gallery etc.) but I definetly don't recommend it as a base for a customized web-app.

How to change Css class using JQuery?

I have an multi user application with basic layouts where i want to change the layout and style of the page for individual user .
I have one way in mind that to change the css at run time but if i am changing the css then it will take effect for every user and if i will refresh the page then it shows basic page again.
Help me for this problem that if i will change the css then it will take effect only for the same user.
and it will not change after refresh.
Or any buddy has any other idea then please suggest me.
$("div#somediv").addClass("specialuserclass");
JQuery reference or have a stylesheet per user;
You might be interested in doing this using themes and the theme manager plugin I built. The plugin is built to work with jQuery UI themes, but could easily be adapted to your own custom CSS-based themes. This plugin works with individual user preferences for a particular theme stored in a database, though I suppose you could also use a cookie. the latter would take more customization. You can find more info on my blog, http://farm-fresh-code.blogspot.com.
You have to persist the style chosen by each user.
Your can design your function/screen to something like:
1. On create of a new user, give the user the default basic layout and persist this in the server side (you can probably save the user preference in your DB).
2. When he changes style, update the user's user preference record/file
3. On load of the page, retrieve the user preference and change the css style on the server side
If you want to implement this yourself, store your user-specific styles in a dedicated store such as a database, indexed by user. At page construction time (server side) consult your database, looking up the customizations for that user, and apply the CSS you want to that page.
Alternatively there are a variety of theming applications available. These will depend on your server-side tools. For example, ASP.NET offers the Web Parts Framework.

Where is the best place to put a DB query in drupal?

I have a few forms who's data needs to be written to the main database in their own tables. Just simple name-email collection forms, that are part of regular pages in drupal. I suspect the right way to do this would be to write a module that would have the query in a function, but this is just a guess. I've never written a module before, and don't know how the form would be processed that way.
It's also a guess that to perform the db query within a node would be insecure?
The only other idea I have would be to use a php file on the server to do the form processing, with the db query written there, but that seems very non-drupal, as far as I can tell.
How to??
http://drupal.org/node/508 is Drupal's info on module development
You'll be wanting to use the function "db_query()"
You can use Drupal's built in methods to build forms though that will save the data for you. Have a look at the module developers guide though and you should be able to figure it out. Module development sounds intimidating but it's not as hectic as it seems once you actually know what's going on with Drupal (hence, read the guide).
Have you checked what's already out there? Webform may be able to solve your needs without any custom code.
Also, I highly recommend the book Pro Drupal Development if you want to learn more about Drupal and basic module development.
I'd second the Webform module. Create a really simple webform with name and email (results can be emailed or stored automatically in the DB, and can be exported easily in several formats). Then check out the Webform Block module to put that webform in a block and place wherever you need it on your site. No custom coding required!
Here is an excerpt from the Webform Block project page:
Allows embedding a webform node into a block which can be positioned in any block region (theme space permitting).
Handles redirecting back to the current page on validation errors.
A good use for this is to add a site wide contact form inline on your pages, such as in the footer or sidebar.
Multiple webforms can appear on the same page. The contents of the block is simply a node, so theme work can be done in the node-webform.tpl.php file as usual.

Resources