Skip to content

Instantly share code, notes, and snippets.

@guoxiangke
guoxiangke / dale_js_form_behaviors
Last active August 26, 2017 05:33
1.drupal 7,表单如果有必填项没有填写,提交的话,自动focus到未填项。
//form behaviors
$('form .form-submit').click(function(e){
$('input.required').each(function(){
if($(this).val()==''){
$(this).focus();
e.preventDefault()
return false;
}
});
});
@guoxiangke
guoxiangke / add a Cancel button to Drupal forms
Created January 18, 2013 03:42
关键点: '#type' => 'submit', '#limit_validation_errors' => array(), '#submit' => array('yourmodule_cancel_buttons_callback')
/**
* @file
* Defines a Cancel button on node forms
*/
function yourmodule_cancel_form_node_form_alter(&$form, &$form_state) {
$form['actions']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#weight' => 20,
'#executes_submit_callback' => TRUE,
@guoxiangke
guoxiangke / Entity metadata wrappers.php
Created October 9, 2012 09:51
Entity metadata wrappers
<?php
// Create wrapper around the node.
$wrapper = entity_metadata_wrapper('node', $node);
// We can do it also using only $nid.
$wrapper = entity_metadata_wrapper('node', $nid);
// Get the value of field_name of the nodes author's profile.
$wrapper->author->profile->field_name->value();
$wrapper->author->profile->field_name->set('New name');