How to format email link in Drupal cck Computed Field? - drupal

I am trying to create in Drupal a cck computed field that copies an email address from a cck field in a "job post" node content type to this computed field in the "job application" node content type.
I have found the following code that works perfectly, when I paste it into the "Computed Code:" box in the cck computed field
// obtain node id from nodereference cck field that links
// the job application node to the job post node
$item_nid = $node->field_appl_position[0]['nid'];
//load and build the information from the referenced job post node
$item_node = node_load($item_nid);
$item_node = node_build_content($item_node);
//get the email address from the cck email field in the referenced job post node
$item_email = $item_node->field_job_email[0]['email'];
//copy the email address to the computed field in the job application node
$node_field[0]['value'] = $item_email;
However, when I try to send an email using the content of the computed field nothing happens. I believe this is the case because the computed field is not formatted as a mailto link. I have tried to change the parameters in the "Display Format:" box in the computed field, but have not succeeded.
Can anybody please help? Thanks!

you can use the following Drupal API function to format your link:
http://api.drupal.org/api/drupal/includes--common.inc/function/l/6
so in this case the value for your computed field would be the following:
l('Mail me', 'mailto:'.$item_email);

Related

Drupal 7 "Can't add fields to content type?"

Drupal 7
I have a problem with adding more "fields" to my content type (node).
to explain it in details, I have contact type called "staff" with 17 fields.
I want to add more one field called "Staff ID no" after writing field name it is not taking me to next "field settings page" instead it keeps me in the same page!
When I try to add the field again it gave me the below error message"
"The machine-readable name is already in use. It must be unique."
which mean it is already been created from the first attempt but yet still not shown in "staff" content type fields area?
is there any limitation of fields quantity per content type?
Please advise?
"The machine-readable name is already in use. It must be unique."this error occour when a field with same machine name exist.suppose u have field named Staff ID and it created with machine name staff_id and then u have another field with name Staff IDs and you r saving it's machine name as staff_id it will show that error.if u save it with staff_ids.it will save.

sequence of error messages for required field in drupal 7

I have a content type which has 4 CCK fields.
Field name are :
field_device_data_card_id
field_device_model
field_device_type
field_device_id
These fields are in their respective sequence.
all fields are marked as mandatory. when i click submit button without filling any data in required fields, it generate error messages for mandatory fields but the sequence of error messages are not proper.
it is displayed in following sequence ->
Device Data Card ID field is required.
Device ID field is required.
Device Model field is required.
Please select a device type.
while it should be like ->
Device Data Card ID field is required.
Device Model field is required.
Please select a device type.
Device ID field is required.
Please provide me a solution so that i can sequence the error messages.
Thanks
.. add your custom validator via hook_form_alter and:
function form_name_validate($form, &$form_state) {
$tmp_msg = drupal_get_messages('error');
// change order or modify on your own of $tmp_msg
drupal_set_message($tmp_msg,'error');
}

Drupal 7 Views 3: Exposed Filters that search specific FIELDS

I'd really appreciate some help with this.
I'm trying to create two different exposed filters in Views. I currently have 6,000 nodes with 75 fields each inside one content type. I'm using a Page View with an exposed form in a block. I also have the Better Exposed Filters module installed.
The first one, I want to make a text box for searching terms, but have it only search my specified fields. I would have it search 3 fields (to do a search on the full name): First Name, Middle Name, Last Name. They are all in different fields. The only thing I've been able to make it search so far is EVERY TERM in a content type (where it searches every field, not just name). I did that by exposing this filter:
Search: Search Terms
The terms to search for.
The next filter I am trying to do is for the field "Graduation Class." It might be best to do search terms for this too (if I can figure out how to search ONE field, like above), but I was hoping to have a select dropdown that lists every Graduation Class. These classes in this field range from 1905-1972. When you click a year in this box, it filters the current results by that year.
This sounds pretty basic, but I can't seem to get it and would REALLY appreciate some help.
For your reference (if needed), here are the types of filters I can add. (Off topic: I'm actually not so sure what the ":format" ones exactly are). For the "Content:" filters, I'll only show the "Name" ones, because there are 73 others. Many of these filters are from the Feeds module, because that's what I used to import my nodes:
Content: First Name (field_cinfo_fname)
Appears in: node:cadet.
Content: First Name (field_cinfo_fname:format)
Appears in: node:cadet.
Content: Middle Name (field_cinfo_mname)
Appears in: node:cadet.
Content: Middle Name (field_cinfo_mname:format)
Appears in: node:cadet.
Content: Last Name (field_cinfo_lname)
Appears in: node:cadet.
Content: Last Name (field_cinfo_lname:format)
Appears in: node:cadet.
Content access: Access
Filter for content by view access. Not necessary if you are using node as your base table.
Content revision: Log message
The log message entered when the revision was created.
Content revision: Title
The content title.
Content revision: Updated date
The date the node was last updated.
Content revision: Vid
The revision ID of the content revision.
Feeds item: Import date
Filter on a Feeds Item's import date field.
Feeds item: Item GUID
Filter on a Feeds Item's GUID field.
Feeds item: Item URL
Filter on a Feeds Item's URL field.
Feeds item: Owner feed nid
Filter on Feed Items by the Feed they were generated from using the Node Id of the Feed Node.
Feeds log: Feed node id
Filter on a Feeds Source's feed_nid field.
Feeds log: Importer id
Filter on an importer id.
Feeds log: Log time
The time of the event.
Feeds log: Request time
The time of the page request of an event.
Feeds log: Severity
Filter on the severity of a log message.
Feeds source: Feed node id
Filter on a Feeds Source's feed_nid field.
File Usage: Entity type
The type of entity that is related to the file.
File Usage: Module
The module managing this file relationship.
File Usage: Use count
The number of times the file is used by this entity.
Page Title: Title
A Page Title alternative to the Node: Title field.
Search: Links from
Other nodes that are linked from the node.
Search: Links to
Other nodes that link to the node.
Search: Search Terms
The terms to search for.
I might be mid-understanding you but don't you want to use:
Content: First Name (field_cinfo_fname)
Content: Middle Name (field_cinfo_mname)
Content: Last Name (field_cinfo_lname)
as your filters?
I'm guessing your fields are text areas which is why you've got the :format options; 'format' is another column in the longtext field type so will be available (just like 'alt' and 'title' would be available for an image field type).
If I understand the question correctly, you've got three name fields and you want a single text box to search all three fields. The easiest way to do this is to combine those three fields into a single field that is not displayed but can be searched using an exposed filter. One option is to use the Auto Nodetitle module to make the node title a combination of the three names. (I do this a lot with personnel directories so that a given entry displays as Lastname, Firstname). Then you could search on a the node title in your exposed filter.
If using the title is not an option for your project, you could add another field to your content type, eg: full_name, and write a small module to implement hook_node_save that would simply fill in the full_name field with "first middle last" whenever a node is saved. Then remove the full_name field from the display and use it for your exposed filter.
re: graduation year: If you're using a "List (Integer)" field type, that should be no problem. If you're using a plain text field type, that makes things more difficult. If you are using plain text, you may want to redo the field so that you could do cool filters such as "graduated before 1950" type filters or using jQuery sliders to select a range of graduation years.
Hope that helps.

Error in copying the content of a cck field between 2 nodes using cck computed field

I have two content types (job_post and job_application) linked using the node reference + node reference url nodes. When I click a link in a job_post node, a new job_application node is created, so that candidates can fill out their job application. My goal is to automatically copy the content of an cck email field from the referenced job_post node to a cck email field in the job_application node.
To achieve this, I am trying to use a cck computed field, as suggested in: http://drupal.org/node/298951.
In my computed field I have placed the following code:
$node_field[0]['value'] = db_result(db_query("SELECT field_emailfieldjobpost_value FROM content_type_job_post WHERE nid=%d",$node->field_referencefieldjobapplication[0][nid]));
where the field_referencefieldjobapplication, is the node reference field in my job_application node.
In the display format box of the computed field I have:
$display = $node_field_item['value'];
I have selected the option to store it in the database as a varchar.
However, nothing seems to happen. I never see the cck field or its content both when I create or after I save a new job application (I have even tried to see it in views and failed). Any suggestion on what might be wrong?
Thanks
What I would do, is give a parameter with the link (the id of the job_post). and catch the parameter and place it in a disabled cck field.
Then write a module using the hook_node_api when a jobapplication is saved, you get the data from the job_post (using node_load) and use the data from the job-post however you want.

How do I validate a nodereference field in a custom node form in Drupal 6?

I have an autocomplete nodereference field (field_hostnamelastref) in a custom pass-node-form.tpl.php. The field references four items (last name, first name, an id #, and status) generated from tokens in an autotitle from another content type.
When entering a last name in the nodereference field, if the corresponding status for that last name is "SUSPENDED", I would like to be able to validate that field with an error message and block form submission.
This is my first attempt at writing my own validation and am not having any luck. Have tried many different ways ereg, preg-match and strpos. Below is my latest attempt:
<?php
function pass_validate($form_id,$form_values) {
$status = 'SUSPENDED';
if (strpos ($form_values['hostnamelastref'], $status)) {
form_set_error('hostnamelastref', t('The account for this person has been suspended.', array('#type' => $type->name)));
}
}
?>
Not sure if I'm even in the ball park on this. Any help much appreciated!
If you can pass the SUSPENDED information somehow to views, then you can limit the nodes one chooses in the nodereference using a view. Then nodereference will take care for validation if the user entered a node not in the list.
But I am not sure I understood your question.

Resources