I am new to drupal, currently i am creating a new module for forms. inside of the module i added the code as follows .
$form['first name'] = array(
'#type' => 'textfield',
'#title' => t('First Name'),
);
in this case i wanted to use place holders for text fields.
So how can i do ?
Give them in #attributes like below
'#attributes' =>array('placeholder' => t('placeholder text goes here'))
Related
I'm new to Drupal making a plugin that hooks into the ckeditor widget. I absolutely can't figure out why my implementation of a hook that is defined in ckeditor is never called.
Here are some details
my module is enabled
I'm able to use more basic hooks like exceltohtml_plugin instead of exceltohtml_ckeditor_plugin and reach my test statement.
I'm can't think of any more troubleshooting ideas to reveal the issue so any help would be greatly appreciated.
exceltohtml.module
<?php
error_log("TEST: this will print to log");
// implementation of hook_ckeditor_plugin()
function exceltohtml_ckeditor_plugin()
{
error_log("TEST: but this will never run");
return array(
'exceltohtml' => array(
'name' => 'exceltohtml',
'desc' => t('Excel sheet upload'),
'path' => drupal_get_path('module', 'exceltohtml') .'/plugins/exceltohtml',
'buttons' => array(
'excel_to_html' => array('label' => 'Insert spoiler','icon' => '/images/image.gif' ),
)
)
);
}
ckeditor.api.php (the file in ckeditor that Im basing my hook on)
/**
* Hook to register the CKEditor plugin
*/
function hook_ckeditor_plugin() {
return array(
'plugin_name' => array(
// Name of the plugin used to write it.
'name' => 'plugin_name',
// Description of the plugin - it would be displayed in the plugins management section of profile settings.
'desc' => t('Plugin description'),
// The full path to the CKEditor plugins directory, with the trailing slash.
'path' => drupal_get_path('module', 'my_module') . '/plugin_dir/',
'buttons' => array(
'button_name' => array(
'icon' => 'path to button icon',
'label' => 'Button Label',
)
)
)
);
}
If the function in your module is new, then the slightly older version of your module code might be cached.
Visit the module listing page in Drupal, that should reload the modules PHP code:
admin/modules
I am new to Drupal development. I want to create a registration form for visitors of my site. Default registration page only has two fields: Username and Email address.
How can I add more fields to it, e.g password, picture and timezone. I also want to capture tow other information - Date of Birth and Gender. These two fields are not available in default users table. How can I tie these information with a user account? Do I have to create a new table and put these information there referencing the uid of user table? If it is possible how can I pull the joined record?
Is there any possibility that I create a new content type for this purpose but records still go to default users table and can be used for login?
If 2 above is not possible I probably have to use hook_form_alter but where should I put this function?
When creating a custom registration form shall I use default registration page i.e. /user/register and customize it?
I am sorry if above questions look very childish and silly! Hope you will consider my my newbie status. If possible please help me with a step by step solution.
Thanks!
UPDATE
To accomplish the requirement I created a custom module called user_signup and in user_signup.module file I have written the following code.
<?php
/*
Implements hook_menu()
*/
function user_signup_menu(){
$items = array();
$items['user/signup'] = array(
'title' => 'Sign Up',
'page callback' => 'drupal_get_form',
'page arguments' => array('user_signup_registration_page'),
'access arguments' => array('access content'),
);
return $items;
}
function user_signup_registration_page($form, &$form_state){
$form['name'] = array(
'#title' => 'Username',
'#description' => 'choose a username',
'#type' => 'textfield',
'#required' => TRUE,
);
$form['mail'] = array(
'#title' => 'Email',
'#description' => 'enter a valid email address',
'#type' => 'textfield',
'#required' => TRUE,
);
$form['pass'] = array(
'#title' => 'Password',
'#description' => 'Enter a strong password',
'#type' => 'password',
'#required' => TRUE
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Create Account'),
);
return $form;
}
function user_signup_registration_page_submit($form, &$form_state){
$new_user_id = db_insert('users')
->$fields(array( **//this is line number 45**
'name' => $form_state['values']['name'],
'mail' => $form_state['values']['mail'],
'pass' => $form_state['values']['pass'],
))
->execute();
drupal_set_message(t('New user created'));
}
Everything works perfectly but when I hit the submit button I am getting this error:
Fatal error: Method name must be a string in D:\xampp\htdocs\imdbind\sites\all\modules\user-signup\user_signup.module on line 45
I have marked line number 45 in above code snippet as **//this is line number 45**. I did not find any difference when comparing my code with theirs. What I am doing wrong?
Just change line 45 with following
From:
->$fields(array( **//this is line number 45**
To
->fields(array( **//this is line number 45**
You can add Fields here /admin/config/people/accounts/fields int eh People Account settings Manage Fields form.
I'm trying to display data in cakePHP with a Google Chart.
I downloaded the GoogleCharts plugin on https://github.com/scottharwell/GoogleCharts and put it in my App/Plugin directory. I load all plugins in my application's bootstrap file with
CakePlugin::loadAll();
In my Controller, I put
App::uses('GoogleCharts', 'GoogleCharts.Lib');
and
public $helpers = array('GoogleCharts.GoogleCharts');
, so cakePHP is able to detect I will work with this plugin. Of course, I created the GoogleChartHelper.php in App/View/Helper.
Before working with my data, what I want is just to display an example of chart to see if it is working. Which is not! I copied the example of the above-provided link (on github.com), so here is my Controller class:
<?php
App::uses ( 'AppController', 'Controller');
App::uses ('GoogleCharts', 'GoogleCharts.Lib');
class StatisticsController extends AppController{
public $helpers = array('GoogleCharts.GoogleCharts');
public $components = array (
'Paginator',
'Session'
);
public function index(){
//Setup data for chart
$chart = new GoogleCharts();
$chart->type("LineChart");
//Options array holds all options for Chart API
$chart->options(array('title' => "Recent Scores"));
$chart->columns(array(
//Each column key should correspond to a field in your data array
'event_date' => array(
//Tells the chart what type of data this is
'type' => 'string',
//The chart label for this column
'label' => 'Date'
),
'score' => array(
'type' => 'number',
'label' => 'Score',
//Optional NumberFormat pattern
'format' => '#,###'
)
));
//You can also manually add rows:
$chart->addRow(array('event_date' => '1/1/2012', 'score' => 55));
//Set the chart for your view
$this->set(compact('chart'));
}
}
In my View, I put the code
<div id="chart_div"><?php $this->GoogleChart->createJsChart($chart);?></div>
(without "s" to "GoogleChart" (not like on the download page, where is it written "GoogleCharts"), which took me 3 hours to notice)
My charts should be displayed on the page, but I got the following error:
Warning (512): Method GoogleChartHelper::createJsChart does not exist
[CORE\Cake\View\Helper.php, line 192]
(and if I put the "s" in the View, my page displays like without any error but without any chart...)
Am I missing something?
N.B. : I didn't copy the first method given on the github page, because with it a new worst error appears:
Error: Call to a member function find() on null
That method is:
//Get data from model
//Get the last 10 rounds for score graph
$rounds = $this->Round->find(
'all',
array(
'conditions' => array(
'Round.user_id' => $this->Auth->user('id')
),
'order' => array('Round.event_date' => 'ASC'),
'limit' => 10,
'fields' => array(
'Round.score',
'Round.event_date'
)
)
);
Please help me, I just want to display some random data in a chart and it should not be complicated (but with cakePHP, everything seems complex)...
The problem is that one step was missing:
you have to write
<?php echo $this->fetch('script'); ?>
in View/Layouts/bootstrap.ctp and if you followed all other steps, it should work!
I have created a module that adds a field to the user profile. I used field_create_field and field_create_instance to do this. When I disable the module, I want the field to no longer show up on the user profile, but I do not want to destroy it. I want to be able to enable the module and have the field show up and the data to still be there as originally entered. Can anyone tell me how to accomplish this?
Here is the code I used to create the field:
$field = array(
'field_name' => $field_name,
'type' => 'text',
'visibility' => 1,
'category' => 'API',
);
$field = field_create_field($field);
$field_instance = array(
'field_name' => $field_name,
'entity_type' => 'user',
'bundle' => 'user',
'label' => t('API Token'),
'cardinality' => 1,
'translatable' => 0,
'description' => t('By using this API token, you agree to the site Terms and Conditions and to acknowledge that your submission does not include protected health information or personal identifiers.'),
'widget' => array(
'type' => 'text_textfield',
'weight' => 10,
),
'formatter' => array(
'label' => t('field formatter label'),
'format' => 'text_default'
),
'settings' => array(
),
);
When you have created field using drupal entity like user, node etc then on that entity crud operation automatically apply.
As you have used api to "field_create_field" field then it automatically create field using api of entity vise verse its delete field when you uninstalled module.
First tell me when you uninstall your custom module then your custom field deleted from profile.? If yes then it's difficult to handle your use case. If no then in system table of Drupal you get status of your module whether it's disable or enable if status is 0 then used form alter hook of user profile and hide field
I was not able to accomplish exactly what I wanted, but I ended up installing the field extra widgets module and hiding the field completely on the edit form. Then, I used hook menu alter to create a local task tabs and I display the field on that tab.
i am creating a plugin with plugin hooks when plugin activate it creating product attributes it working fine also i adding attributes terms it also working fine and on plugin deactivate i am deleting it but i see only attributes deleting but terms not delete.
i using this code for deleting attributes it working fine
enter code here
// attributes parameters
$wpm_attributes = array(
array(
'label' => 'Size',
'name' => 'size',
'type' => 'select',
),
array(
'label' => 'Color',
'name' => 'color',
'type' => 'select',
)
);
foreach ( $wpm_attributes as $attr ) {
$attribute = array(
'attribute_label' => $attr['label'],
'attribute_name' => $attr['name'],
'attribute_type' => $attr['type'],
'attribute_orderby' => 'menu_order'
);
$wpdb->delete( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute );
delete_transient( 'wc_attribute_taxonomies' );
}
I recommend not deleting the terms at the point of deactivation.
Instead why don't you delete the terms at the point of uninstallation?
You can use the uninstall hook:
http://codex.wordpress.org/Function_Reference/register_uninstall_hook
Or bypass that.
The plugin should create a file named 'uninstall.php' in the base plugin folder. This file will be called, if it exists, during the uninstall process bypassing the uninstall hook.
This may be easier to manage code wise and sometimes people would like to deactivate a plugin and not lose all their data.