I added a new field(First name) in Account settings & its machine name is 'field_first_name'
I am trying to load this value in home page like this
<?php print $user->field_first_name ?>
But the above code is not working.
Display Suite for Drupal 7 - Part 3: Fields
http://www.youtube.com/watch?v=mvFP16PJt4c
Related
On one of my webpage, I show a list of customer details with default pagination [Paginator helper]. Each customer row has a corresponding 'edit' button which when clicked shows a DIV populated with that customer information. [This DIV has textboxes etc. where I can change customer info] After re-entering/modifying customer details, when I click on "Save" button, 2 ajax calls are made..
First one to save the edited record
The second one Updates the customer Listing on the same page with modified information
My problem : If I am on page 3 and edit one customer record, the 2nd ajax call refreshes the list but does not go to the page 3. It starts from page 1.
Please help.
You can get your current page here:
<?php echo $this->Paginator->counter(array(
'format' => ('{:page}')
)); ?>
This is part of the solution. :)
You can get your current page here:
$this->request->params['named']['page']
Did you try to use the link from Paginator? It maintains the page # to the controller.
Something like
// same parameters as $this->Html->link
<?php echo $this->Paginator->link( ... ) ?>
Check also the reference documentation for the Paginator Helper
I use jquery / javascript to store the page on a cookie and then read it from the controller.
// -------------------------------------------------------------------------
// on action click remember current page
$('td.actions').click( function( event )
{
var page = $('li.active a').html();
var name = window.location.href.split('-').join('_').split('/').pop();
$.cookie.raw = true;
$.cookie( 'CakeCookie[' + name + '_page]', page, { expires: 365, path: '/' } );
});
I have created a another profile student, and added a field called class. i want to display this form including the class filed.
How to display the student registration form .. Please help
i have used below code in block
<?php
print drupal_render(drupal_get_form('user_register_form'));
$profile = profile2_load_by_user($account);
print drupal_render(field_view_field('profile2', $profile['Student'], 'field_class'));
?>
I developed a Content type of "Car Sales" with following fields:
Manufacturer
Model
Make
Fuel Type
Transmission (Manual/Automatic)
Color
Registered? (Yes/No)
Mileage
Engine Power
Condition (New/Reconditioned/Used)
Price
Pictures (Multiple uploads)
I have developed View of this Content Type to display list of cars. Now I want to develop a screen/view for individual Car Sale Record like this:
Apart from arranging fields, please note that I want to embed a Picture Gallery in between. Can this be achieved through Drupal 7 Admin UI or do I need to create custom CSS and template files? If I need to edit certain template files/css, what are those? I'm using Zen Sub Theme.
I would accomplish this by creating a page, and then creating a node template to accompany it. Start by creating a new node, and then record the NID for the name of the template.
Then, in your template, create a new file, and name it in the following manner: node--[node id].tpl.php
Then, in that file, paste in the following helper function (or you can put it in template.php if you're going to use it elsewhere in your site):
/**
* Gets the resulting output of a view as an array of rows,
* each containing the rendered fields of the view
*/
function views_get_rendered_fields($name, $display_id = NULL) {
$args = func_get_args();
array_shift($args); // remove $name
if (count($args)) {
array_shift($args); // remove $display_id
}
$view = views_get_view($name);
if (is_object($view)) {
if (is_array($args)) {
$view->set_arguments($args);
}
if (is_string($display_id)) {
$view->set_display($display_id);
}
else {
$view->init_display();
}
$view->pre_execute();
$view->execute();
$view->render();
//dd($view->style_plugin);
return $view->style_plugin->rendered_fields;
} else {
return array();
}
}
Then add the following code to your template:
<?php
$cars = views_get_rendered_fields('view name', 'default', [...any arguments to be passed to the view]);
foreach ($cars as $car): ?>
<div>Put your mockup in here. It might be helpful to run <?php die('<pre>'.print_r($car, 1).'</pre>'); ?> to see what the $car array looks like.</div>
<?php endforeach;
?>
Just change the placeholders in the code to whatever you want the markup to be, and you should be set!
As I mentioned above, it's always helpful to do <?php die('<pre>'.print_r($car,1).'</pre>'); ?> to have a visual representation of what the array looks like printed.
I use views_get_rendered_fields all the time in my code because it allows me to completely customize the output of the view.
As a Reminder: Always clear your caches every time you create a new template.
Best of luck!
I have two profile2 profiles defined - main and customer_profile. Also, I have a node type called Customer.
When creating a new Customer node, I would like to load the custom_profile form. The idea is to create a node and a profile simultaneously.
I know it's definately a hook_form_alter solution but can someone tell me how to programmatically load a profile while creating or editing a Customer node.
You can load profile type and data by using these function
$types = profile2_get_types();
profile2_load_by_user($account, $type_name = NULL)
For Example :
$types = profile2_get_types();
if (!empty($types)) {
foreach ($types as $type) {
$profile = profile2_load_by_user($uid, $type->type);
}
}
Even if you are able to load the customer_profile form, you will need to handle the values separately as they are two different nodes.
I would suggest capturing those fields in the customer node form, and then create a customer_profile programmatically from the values.
If you want to get the profile2 form itself then you can use something like
module_load_include('inc', 'profile2_page', 'profile2_page');
$profile2 = profile2_by_uid_load($uid, 'seeker_profile');
$entity_form = entity_ui_get_form('profile2', $profile2, 'edit');
and then add that to the form you want to place it in.
You can load full profile data using profile2_load_by_user();
params like:-
profile2_load_by_user($account,$type_name)
$account: The user account to load profiles for, or its uid.
$type_name: To load a single profile, pass the type name of the profile to load
So code like bellow
$account->uid = $existingUser->uid;
$type_name = 'user_about';
$profile = profile2_load_by_user($account, $type_name);
//$profile variable have full data of profile fields
//changing data profile2 fields
if(isset($_POST['field_user_first_name'])&& !empty($_POST['field_user_first_name'])){
$profile->field_user_first_name['und'][0]['value'] = $_POST['field_user_first_name'];
}
profile2_save($profile);
Well When creating a new Profile , Profile2 fields are not visible until a manual save is done.
To Automatically create the profile2 object , We use rules Module
Step
1) Go to Drupal admin/config/workflow/rules
2) create new rule
3) Give a name and Select in react/event "After saving a new user account"
4) Action,>> Add Action >> Execute custom PHP code
5) insert php code
$profile = profile_create(array('type' => 'profile2 type machine name', 'uid' => $account->uid));
profile2_save($profile);
6)Save >> Save changes.
This will create profile2 field when a new user is Created.
I had a similar need for creating a custom tab at the user page and loading the user profile2 form in it.
Here is a snap code of how I managed to accomplish just that:
MYMODULE.module https://gist.github.com/4223234
MYMODULE_profile2_MYPROFILE2TYPE.inc https://gist.github.com/4223201
Hope it helps.
We list events on our Drupal 7 site, but we'd like our users to be able to register for these events via a simple form. We're using Pathauto to generate URL aliases for events using the following pattern: events/[node:title]. We would like to have another page with the alias events/register/[node:title] which would present the registration form. We would also like to use tpl.php files for creating the templates, like we do for the rest of the site.
Any ideas on how we might accomplish this? Thanks.
You can try the Signup module. It's still in development, but over 7000 sites are using it:
I would put a register button on the event/ page via the node.tpl.php file. If all your nodes are not registerable, then you can check the node by getting the $nid with $node->nid and run a db_query on the url_alias table to see if current node qualifies.
<?php
$nid = $node->nid;
$result = db_query('SELECT alias FROM {url_alias} WHERE source = :source,
array(':source' => 'node/'.$nid));
foreach ($result as $r) {
$alias = $r->alias;
}
if (strpos($alias, 'events')) {
?> <input... or <button...
Have your register button redirect to events/register/$node->title page and make sure you pass the node. There's a few different ways to go from here. If you have questions about this part open another thread.