how to include/call profile2 registration form in drupal 7 - drupal-7

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'));
?>

Related

Drupal Webform submission : use submitted values in php block

After a webform is submitted, I redirect it to its "webform result submission page" automatically.
Here all values are shown.
I want to access the values of that submission, to use them in some simple "if then" php statements.
This logic will add some text above that results page. (for example: if the submitted value of formelement_1 == 2 , then add this text "warning, formelement_1 has great value!").
Anybody some input ? Thanks
Try like this way
<?php
include_once(drupal_get_path('module', 'webform') .'/includes/webform.submissions.inc');
$nid = arg(1); // need to hard-code nid if this is a custom page
$sid = $_GET['sid'];
$submission = webform_get_submission($nid, $sid);
$first_name = $submission->data[1]['value'][0];
$last_name = $submission->data[2]['value'][0];
$thanks = $first_name . " " . $last_name;
?>
<h2>Thank you <?php print $thanks ?>... Your registration has been sent.</h2>
?>
I hope, it will works.

Send image email cakephp without storing it

I'm using Cakephp 3 with Cake\Network\Email\Email.
I have a form to send a message with two input fields. Those fields are stored in database.
I'd like to join an image to this form without storing it: only in attachment.
Here is my input file :
<?php echo $this->Form->file('photo', ['class' => 'form-control','value'=>'','accept'=>'image/*']); ?>
My Controller :
$Email = new Email('default');
$Email->theme('Front')
->template('my_template1')
->viewVars(['sender'=> $user, 'recipes'=> $recipes])
->attachments([$this->request->data['photo'] => $this->request->data['photo']['tmp_name']])
->emailFormat('html')
->to('xx#xx.com')
->from($user['email'])
->send();
Text inputs are well stored and sent. But no image attached in my email...
What's wrong?
Thanks!
I was stuck here to i got it, in your create form add
'enctype'=>'multipart/form-data'
So it should be
echo $this->Form->create($email, ['enctype'=>'multipart/form-data']);
This is added in the other controller by default but when you use a model less form it doesn't do this.

Display newly added field value of account settings

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

Styling/Theming Drupal 7 Content Type Record

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!

Drupal 7 load profile2 programmatically

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.

Resources