$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#attributes' => array(
'onclick' => 'javascript:var s=this;setTimeout(function(){s.value="Saving...";s.disabled=true;},1);',
),
);
Monday, 29 December 2014
How can I disable a Drupal form submit button when it is clicked to prevent double submission?
Monday, 22 December 2014
Multipel status change for drupal 7
multiple status for drupal 7 change
$form['name'] = array(
'#type' => 'textfield',
'#title' => t(''),
'#description' => '',
'#default_value' => isset($name) ? $name : '',
'#attributes' => array('placeholder' => array('Search')),
'#prefix' => '<div class="span3 custom-nomargin">',
'#suffix' => '</div>',
'#states' => array(
'visible' => array(
'#agent_order' => array(
array('value' => 'OrderID'),
array('value' => 'Event Name')
),
),
),
single status for drupal 7 change
$form['name'] = array(
'#id' => 'name',
'#type' => 'textfield',
'#title' => t(''),
'#description' => '',
'#default_value' => isset($name) ? $name : '',
'#attributes' => array('placeholder' => array('Search')),
'#states' => array(
'invisible' => array('#status' => array('value' => 'ALL'),
),
),
'#prefix' => '<div class="span3 custom-nomargin">',
'#suffix' => '</div>',
);
Wednesday, 3 December 2014
Confirmation Dialog box for Delete or not in druapl 7
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#attributes' => array('onclick' => 'if(!confirm("Really Delete?")){return false;}'),
);
Thursday, 27 November 2014
OR condtion in drupal 7
That's not correct, the default is AND. To use or, you need to use:
$or = db_or();
$or->condition();
$or->condition();
$query->condition($or);
Saturday, 1 November 2014
Upload images in drupal 7
$form ['boxthird'] ['thirdcontentlogo'] = array (
'#type' => 'managed_file',
'#prefix' => '<div class = "row-fluid">',
'#suffix' => '</div>',
'#description' => '<p style="font-size:12px"><span class="icon-hand-right"> </span> Uploaded Inner logo Image Size should be 165 x 61 pixels. </p></span>',
'#upload_location' => 'public://sitefiles/',
'#default_value' => isset ( $gethomestaticdata ['boxthird'] ['thirdcontentlogo'] ) ? $gethomestaticdata ['boxthird'] ['thirdcontentlogo'] : ''
);
if ($form_state ['values'] ['kitphotos'] != "") {
$validators = array ();
$dest = file_default_scheme () . '://sitefiles/';
$file = file_save_upload ( 'slider_image', $validators, $dest );
if (is_null ( $file )) {
$file = file_load ( $form_state ['values'] ['kitphotos'] );
$file->status = "1";
$fileobject = file_save ( $file );
$buffet_img_fid = $fileobject->fid;
// file usuage
$fileusuage = new stdClass ();
$fileusuage->fid = $fileobject->fid;
file_usage_add ( $fileusuage, 'file', 'mediakit', '111' );
} else {
$file->status = "1";
$fileobject = file_save ( $file );
$buffet_img_fid = $fileobject->fid;
// file usuage
$fileusuage = new stdClass ();
$fileusuage->fid = $fileobject->fid;
file_usage_add ( $fileusuage, 'file', 'mediakit', '111' );
}
}
Friday, 31 October 2014
add class to drupal 7
$form['myboxes']['foo'] = array(
'#attributes' => array('class' => array('ok')),
);
'#attributes' => array('class' => array('ok')),
);
Thursday, 30 October 2014
Active search get rebuild the form using drupal 7 seach
function specialoffers_manage_validate($form, &$form_state) {
drupal_set_title('Special Offers');
drupal_add_css(drupal_get_path('module', 'specialoffers') .'/css/specialoffers.css');
$acitiveinactive = '';
$form['#method'] = 'post';
$acitiveinactive = isset($_POST['filterset']['filteroptions']) ? $_POST['filterset']['filteroptions'] : 1;
if(($acitiveinactive == '1') || ($acitiveinactive == '0') ){
$offerstatusresult = new offersoverview();
$offerstatusresult->status = $acitiveinactive;
$result = $offerstatusresult->getoffersOrderbyPosition();
} else{
$offersall = new offersoverview();
$offersall->status = $acitiveinactive;
$result = $offersall->getoffersAll();
}
global $base_url;
$form['filterset'] = array(
'#type' => 'fieldset',
'#prefix' => '<div class="fleetviewcontain">',
);
$form['filterset']['filteroptions'] = array(
'#id' => 'filteroptions',
'#type' => 'select',
'#options' => array( 'All' => 'All' ,'1'=>'Active','0'=>'Inactive'),
"#limit_validation_errors" => array(),
'#default_value' => $acitiveinactive,
);
$form['filterset']['btn'] = array(
'#type' => 'submit',
'#value' => 'Go',
);
function specialoffers_manage_validate($form, &$form_state) {
if ($form_state['triggering_element']['#value'] == 'Go') {
$form_state['rebuild'] = TRUE;
return;
}
}
Tuesday, 28 October 2014
get role id from role name in drupal 7?
This is quite straightforward with user_roles() and array_search(). Below is a function which will return the role ID if there is a role matching the name and FALSE otherwise.
function get_role_by_name($name) {
$roles = user_roles();
return array_search($name, $roles);
}
// Sample usage
$rid = get_role_by_name('administrator');
One liner would be:
$rid = array_search('administrator', user_roles());
Create new user in drupal 7
public function createNewUser(){
$result=true;
try{
$roles = user_roles();
$selectedRole=array();
foreach($roles as $key => $value){
if($key==$this->role_id){
$selectedRole[$key]=$value;
}
}
$newUserData = array(
'name' => $this->user_name,
'pass' => $this->password, // note: do not md5 the password
'mail' => $this->mail,
'status' => $this->status,
'timezone' => variable_get('date_default_timezone'),
'init' => $this->mail,
// 'roles' => array(
// DRUPAL_AUTHENTICATED_RID => 'authenticated user',
// $this->role_id='tess',
// ),
'roles'=>$selectedRole,
'data' => '',
);
//Step 1 : Save the User Details in Drupal built in function user_save
//The Data stored in users and user_roles table
$new_user = user_save(@$account, $newUserData);
//Success
if($new_user){
//Step 2 : Save the User Details in user_details Table
try {
$query=db_insert('user_accounts');
$query->fields(array(
'uid'=>$new_user->uid,
'first_name'=>$this->firstname,
'last_name'=>$this->last_name,
'company_name'=>$this->company_name,
'phone'=>$this->phone,
'address'=>$this->address,
));
$userid=$query->execute();
if($userid){
$result=$new_user->uid;
//return $userid;
//success
}else{
$result=false;
//failed
watchdog("userdetails", 'userdetails record insertion failed');
}
}catch (Exception $e){
$result=false;
watchdog("userdetails", $e);
}
}
}catch(Exception $e){
$result=false;
watchdog("userdetails", $e);
}
return $result;
}
$result=true;
try{
$roles = user_roles();
$selectedRole=array();
foreach($roles as $key => $value){
if($key==$this->role_id){
$selectedRole[$key]=$value;
}
}
$newUserData = array(
'name' => $this->user_name,
'pass' => $this->password, // note: do not md5 the password
'mail' => $this->mail,
'status' => $this->status,
'timezone' => variable_get('date_default_timezone'),
'init' => $this->mail,
// 'roles' => array(
// DRUPAL_AUTHENTICATED_RID => 'authenticated user',
// $this->role_id='tess',
// ),
'roles'=>$selectedRole,
'data' => '',
);
//Step 1 : Save the User Details in Drupal built in function user_save
//The Data stored in users and user_roles table
$new_user = user_save(@$account, $newUserData);
//Success
if($new_user){
//Step 2 : Save the User Details in user_details Table
try {
$query=db_insert('user_accounts');
$query->fields(array(
'uid'=>$new_user->uid,
'first_name'=>$this->firstname,
'last_name'=>$this->last_name,
'company_name'=>$this->company_name,
'phone'=>$this->phone,
'address'=>$this->address,
));
$userid=$query->execute();
if($userid){
$result=$new_user->uid;
//return $userid;
//success
}else{
$result=false;
//failed
watchdog("userdetails", 'userdetails record insertion failed');
}
}catch (Exception $e){
$result=false;
watchdog("userdetails", $e);
}
}
}catch(Exception $e){
$result=false;
watchdog("userdetails", $e);
}
return $result;
}
Include files in drupal 7 .info
; $Id$
name = fleet management
description = Fleet Management Back End
core = 7.x
package = LSN Software Services
dependencies[] = ckeditor
files[] = classes/hide_show.inc
files[] = classes/fleetoverview.class.inc
files[] = classes/fleetvirtualtour.class.inc
files[] = classes/fleetmiddlecontain.class.inc
files[] = classes/fleetgallery.class.inc
files[] = classes/fleetnav.class.inc
files[] = classes/fleetdelete.class.inc
name = fleet management
description = Fleet Management Back End
core = 7.x
package = LSN Software Services
dependencies[] = ckeditor
files[] = classes/hide_show.inc
files[] = classes/fleetoverview.class.inc
files[] = classes/fleetvirtualtour.class.inc
files[] = classes/fleetmiddlecontain.class.inc
files[] = classes/fleetgallery.class.inc
files[] = classes/fleetnav.class.inc
files[] = classes/fleetdelete.class.inc
Insert delete drupal 7 classs
<?php
class Fooandbarcat{
public static $tableName="foodandbarcat";
public $catName='';
public $catId='';
public $status;
public $position;
public function insertFoodandBarCategoriesData(){
try{
$record = array( 'catName' => $this->catName);
$results= db_insert(self::$tableName)
->fields($record)
->execute();
return $results;
}catch(Exception $e){
}
}
public function getFoodandBarategoriesData(){
try{
$result = db_select(self::$tableName, 'g')
->fields('g')
->condition('catId', $this->catId, '=')
->execute()->fetchObject();
return $result;
}catch(Exception $e){
drupal_set_message(t('db_select failed. Message = %message, query= %query',array('%message' => $e->getMessage(), '%query' =>$e->query_string)), 'error');
}
}
public function getActiveFoodandbarEvents(){
try{
$result = db_select(self::$tableName, 'p')
->fields('p')
->condition('status',$this->status ,'=')
->orderBy('position', 'ASC')
->execute()->fetchAll();
return $result;
}catch(Exception $e){
drupal_set_message(t('db_select failed. Message = %message, query= %query',array('%message' => $e->getMessage(), '%query' =>$e->query_string)), 'error');
}
}
public function getAllFoodandbarEvents()
{
try{
$result=db_select('foodandbarcat','h')
->fields('h')
->orderBy('h.position')
->execute()
->fetchAll();
return $result;
}catch(Exception $e){
drupal_set_message(t('db_select failed. Message = %message, query= %query',array('%message' => $e->getMessage(), '%query' =>$e->query_string)), 'error');
}
}
public function getFoodandBarUpdateData(){
db_update(self::$tableName)
->fields(array('catName' => $this->catName))
->condition('catId', $this->catId, '=')
->execute();
}
public function deleteDataFromwwcfoodandbarcat(){
db_delete(self::$tableName)
->condition('catId', $this->catId)
->execute();
}
public function updateFoodandBarStatus(){
db_update(self::$tableName)
->fields(array('status' => $this->status))
->condition('catId', $this->catId, '=')
->execute();
}
public function orderbyPositionfoodandbar(){
$results= db_update('foodandbarcat')
->fields(array('position' => $this->position))
->condition('catId', $this->catId, '=')
->execute();
return $results;
}
}
class Fooandbarcat{
public static $tableName="foodandbarcat";
public $catName='';
public $catId='';
public $status;
public $position;
public function insertFoodandBarCategoriesData(){
try{
$record = array( 'catName' => $this->catName);
$results= db_insert(self::$tableName)
->fields($record)
->execute();
return $results;
}catch(Exception $e){
}
}
public function getFoodandBarategoriesData(){
try{
$result = db_select(self::$tableName, 'g')
->fields('g')
->condition('catId', $this->catId, '=')
->execute()->fetchObject();
return $result;
}catch(Exception $e){
drupal_set_message(t('db_select failed. Message = %message, query= %query',array('%message' => $e->getMessage(), '%query' =>$e->query_string)), 'error');
}
}
public function getActiveFoodandbarEvents(){
try{
$result = db_select(self::$tableName, 'p')
->fields('p')
->condition('status',$this->status ,'=')
->orderBy('position', 'ASC')
->execute()->fetchAll();
return $result;
}catch(Exception $e){
drupal_set_message(t('db_select failed. Message = %message, query= %query',array('%message' => $e->getMessage(), '%query' =>$e->query_string)), 'error');
}
}
public function getAllFoodandbarEvents()
{
try{
$result=db_select('foodandbarcat','h')
->fields('h')
->orderBy('h.position')
->execute()
->fetchAll();
return $result;
}catch(Exception $e){
drupal_set_message(t('db_select failed. Message = %message, query= %query',array('%message' => $e->getMessage(), '%query' =>$e->query_string)), 'error');
}
}
public function getFoodandBarUpdateData(){
db_update(self::$tableName)
->fields(array('catName' => $this->catName))
->condition('catId', $this->catId, '=')
->execute();
}
public function deleteDataFromwwcfoodandbarcat(){
db_delete(self::$tableName)
->condition('catId', $this->catId)
->execute();
}
public function updateFoodandBarStatus(){
db_update(self::$tableName)
->fields(array('status' => $this->status))
->condition('catId', $this->catId, '=')
->execute();
}
public function orderbyPositionfoodandbar(){
$results= db_update('foodandbarcat')
->fields(array('position' => $this->position))
->condition('catId', $this->catId, '=')
->execute();
return $results;
}
}
Drupal 7 form for every one
function agentregistration_menu(){
$items = array();
$items['agentregistration'] = array(
'title' => 'Agent Registration',
'page callback' => 'drupal_get_form',
'page arguments' => array('agent_registration'),
'file' => 'inc/agentregistration.inc',
'access callback' => 'user_access',
'access arguments' => array('access content'),
);
return $items;
}
$items = array();
$items['agentregistration'] = array(
'title' => 'Agent Registration',
'page callback' => 'drupal_get_form',
'page arguments' => array('agent_registration'),
'file' => 'inc/agentregistration.inc',
'access callback' => 'user_access',
'access arguments' => array('access content'),
);
return $items;
}
Monday, 27 October 2014
data base create in drupal 7
CREATE TABLE IF NOT EXISTS `fleet_overview` (
`Id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`data` LONGTEXT COMMENT 'Data',
`position` INT( 11 ) DEFAULT NULL ,
`status` INT( 11 ) DEFAULT 1,
PRIMARY KEY ( `Id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 AUTO_INCREMENT =9
CREATE TABLE IF NOT EXISTS `fleet_virtual` (
`Id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`mainid`INT(11) NOT NULL,
`virtualimage` LONGTEXT COMMENT 'virtualimage',
PRIMARY KEY ( `Id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 AUTO_INCREMENT =9
CREATE TABLE IF NOT EXISTS `fleet_middle_slider` (
`Id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`mainid`INT(11) NOT NULL,
`middleimage` INT(11) NOT NULL COMMENT 'middleimage',
`accomodations` LONGTEXT COMMENT 'accomodations',
PRIMARY KEY ( `Id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 AUTO_INCREMENT =9
CREATE TABLE IF NOT EXISTS `fleet_gallery` (
`Id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`mainid` INT( 11 ) NOT NULL ,
`galleryType` VARCHAR( 256 ) ,
`galleryData` VARCHAR( 256 ) ,
`position` INT( 11 ) NULL ,
PRIMARY KEY ( `Id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 AUTO_INCREMENT =9
`Id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`data` LONGTEXT COMMENT 'Data',
`position` INT( 11 ) DEFAULT NULL ,
`status` INT( 11 ) DEFAULT 1,
PRIMARY KEY ( `Id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 AUTO_INCREMENT =9
CREATE TABLE IF NOT EXISTS `fleet_virtual` (
`Id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`mainid`INT(11) NOT NULL,
`virtualimage` LONGTEXT COMMENT 'virtualimage',
PRIMARY KEY ( `Id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 AUTO_INCREMENT =9
CREATE TABLE IF NOT EXISTS `fleet_middle_slider` (
`Id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`mainid`INT(11) NOT NULL,
`middleimage` INT(11) NOT NULL COMMENT 'middleimage',
`accomodations` LONGTEXT COMMENT 'accomodations',
PRIMARY KEY ( `Id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 AUTO_INCREMENT =9
CREATE TABLE IF NOT EXISTS `fleet_gallery` (
`Id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`mainid` INT( 11 ) NOT NULL ,
`galleryType` VARCHAR( 256 ) ,
`galleryData` VARCHAR( 256 ) ,
`position` INT( 11 ) NULL ,
PRIMARY KEY ( `Id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 AUTO_INCREMENT =9
include css in drupal 7
drupal_add_css(drupal_get_path('module', 'affilationbackend') . '/css/affilationbackend.css');
Add placeholdert to druapl 7 form
$form['Subscribe_Email'] = array(
// '#id' => 'footer-signup',
'#type' => 'textfield',
'#prefix' => "<div class='span4'>
<div class='footer-signup'>
<div class='footer-signup-inner'>
Sign-up for Specials & News
<div class='signupInner'>",
'#required' => TRUE,
'#attributes' => array ('placeholder' => 'Newsletter Signup'),
);
// '#id' => 'footer-signup',
'#type' => 'textfield',
'#prefix' => "<div class='span4'>
<div class='footer-signup'>
<div class='footer-signup-inner'>
Sign-up for Specials & News
<div class='signupInner'>",
'#required' => TRUE,
'#attributes' => array ('placeholder' => 'Newsletter Signup'),
);
Tuesday, 21 October 2014
Validate E-mail Addresses Drupal 7
<?php
$mail = $form_state['values']['submitted_tree']['email_address'];
if (!valid_email_address($mail)) {
form_set_error('[submitted][email_address]', t('The email address appears to be invalid.'));
}?>
Drupal 7 ajax form validation and submit
Drupal 7 ajax form validation and submit
Ajax is one of the best interactive way to validate and submit Drupal custom form.
Using below steps, we can achieve ajax form validation and submit.
Steps :
1) Declare form elements
2) Call back definitions.
1) Declare form elements.
01 $form['submit'] = array(
02 '#type' => 'submit',
03 '#value' => t('SUBMIT'),
04 '#validate' => array('validate_callback'), // custom form validate.
05 '#ajax' => array(
06 'callback' => 'submit_callback',
07 'effect' => 'fade',
08 'wrapper' => 'specific-wrapper',
09 'event' => 'click',
10 'progress' => array('message' => '', 'type' => 'throbber'),
11 ),
12 );
2) Call back definitions.
1 function submit_callback($form, $form_state) {
2 if (form_get_errors()) {
3 $form_state['rebuild'] = TRUE;
4 return $form;
5 }
6
7 $response = my_form_submit($form, $form_state); // write your form submit logic here.
8 return $response;
9 }
"validate_callback" is our normal hook_form_validate().
- See more at: http://kali-dasan.blogspot.in/2014/07/drupal-7-ajax-form-validation-and-submit.html#sthash.9wFmbiMI.dpuf
- See more at: http://kali-dasan.blogspot.in/2014/07/drupal-7-ajax-form-validation-and-submit.html#sthash.9wFmbiMI.dpuf
- See more at: http://kali-dasan.blogspot.in/2014/07/drupal-7-ajax-form-validation-and-submit.html#sthash.9wFmbiMI.dpuf
- See more at: http://kali-dasan.blogspot.in/2014/07/drupal-7-ajax-form-validation-and-submit.html#sthash.9wFmbiMI.dpuf
- See more at: http://kali-dasan.blogspot.in/2014/07/drupal-7-ajax-form-validation-and-submit.html#sthash.9wFmbiMI.dpuf
Ajax is one of the best interactive way to validate and submit Drupal custom form.
Using below steps, we can achieve ajax form validation and submit.
Steps :
1) Declare form elements
2) Call back definitions.
1) Declare form elements.
01 $form['submit'] = array(
02 '#type' => 'submit',
03 '#value' => t('SUBMIT'),
04 '#validate' => array('validate_callback'), // custom form validate.
05 '#ajax' => array(
06 'callback' => 'submit_callback',
07 'effect' => 'fade',
08 'wrapper' => 'specific-wrapper',
09 'event' => 'click',
10 'progress' => array('message' => '', 'type' => 'throbber'),
11 ),
12 );
2) Call back definitions.
1 function submit_callback($form, $form_state) {
2 if (form_get_errors()) {
3 $form_state['rebuild'] = TRUE;
4 return $form;
5 }
6
7 $response = my_form_submit($form, $form_state); // write your form submit logic here.
8 return $response;
9 }
"validate_callback" is our normal hook_form_validate().
- See more at: http://kali-dasan.blogspot.in/2014/07/drupal-7-ajax-form-validation-and-submit.html#sthash.9wFmbiMI.dpuf
Drupal 7 ajax form validation and submit
Ajax is one of the best interactive way to validate and submit Drupal custom form.
Using below steps, we can achieve ajax form validation and submit.
Steps :
1) Declare form elements
2) Call back definitions.
1) Declare form elements.
2) Call back definitions.
"validate_callback" is our normal hook_form_validate().
Using below steps, we can achieve ajax form validation and submit.
Steps :
1) Declare form elements
2) Call back definitions.
1) Declare form elements.
01 | $form['submit'] = array( |
02 | '#type' => 'submit', |
03 | '#value' => t('SUBMIT'), |
04 | '#validate' => array('validate_callback'), // custom form validate. |
05 | '#ajax' => array( |
06 | 'callback' => 'submit_callback', |
07 | 'effect' => 'fade', |
08 | 'wrapper' => 'specific-wrapper', |
09 | 'event' => 'click', |
10 | 'progress' => array('message' => '', 'type' => 'throbber'), |
11 | ), |
12 | ); |
2) Call back definitions.
1 | function submit_callback($form, $form_state) { |
2 | if (form_get_errors()) { |
3 | $form_state['rebuild'] = TRUE; |
4 | return $form; |
5 | } |
6 |
7 | $response = my_form_submit($form, $form_state); // write your form submit logic here. |
8 | return $response; |
9 | } |
Drupal 7 ajax form validation and submit
Ajax is one of the best interactive way to validate and submit Drupal custom form.
Using below steps, we can achieve ajax form validation and submit.
Steps :
1) Declare form elements
2) Call back definitions.
1) Declare form elements.
2) Call back definitions.
"validate_callback" is our normal hook_form_validate().
Using below steps, we can achieve ajax form validation and submit.
Steps :
1) Declare form elements
2) Call back definitions.
1) Declare form elements.
01 | $form['submit'] = array( |
02 | '#type' => 'submit', |
03 | '#value' => t('SUBMIT'), |
04 | '#validate' => array('validate_callback'), // custom form validate. |
05 | '#ajax' => array( |
06 | 'callback' => 'submit_callback', |
07 | 'effect' => 'fade', |
08 | 'wrapper' => 'specific-wrapper', |
09 | 'event' => 'click', |
10 | 'progress' => array('message' => '', 'type' => 'throbber'), |
11 | ), |
12 | ); |
2) Call back definitions.
1 | function submit_callback($form, $form_state) { |
2 | if (form_get_errors()) { |
3 | $form_state['rebuild'] = TRUE; |
4 | return $form; |
5 | } |
6 |
7 | $response = my_form_submit($form, $form_state); // write your form submit logic here. |
8 | return $response; |
9 | } |
Drupal 7 ajax form validation and submit
Ajax is one of the best interactive way to validate and submit Drupal custom form.
Using below steps, we can achieve ajax form validation and submit.
Steps :
1) Declare form elements
2) Call back definitions.
1) Declare form elements.
2) Call back definitions.
"validate_callback" is our normal hook_form_validate().
Using below steps, we can achieve ajax form validation and submit.
Steps :
1) Declare form elements
2) Call back definitions.
1) Declare form elements.
01 | $form['submit'] = array( |
02 | '#type' => 'submit', |
03 | '#value' => t('SUBMIT'), |
04 | '#validate' => array('validate_callback'), // custom form validate. |
05 | '#ajax' => array( |
06 | 'callback' => 'submit_callback', |
07 | 'effect' => 'fade', |
08 | 'wrapper' => 'specific-wrapper', |
09 | 'event' => 'click', |
10 | 'progress' => array('message' => '', 'type' => 'throbber'), |
11 | ), |
12 | ); |
2) Call back definitions.
1 | function submit_callback($form, $form_state) { |
2 | if (form_get_errors()) { |
3 | $form_state['rebuild'] = TRUE; |
4 | return $form; |
5 | } |
6 |
7 | $response = my_form_submit($form, $form_state); // write your form submit logic here. |
8 | return $response; |
9 | } |
Drupal 7 ajax form validation and submit
Ajax is one of the best interactive way to validate and submit Drupal custom form.
Using below steps, we can achieve ajax form validation and submit.
Steps :
1) Declare form elements
2) Call back definitions.
1) Declare form elements.
2) Call back definitions.
"validate_callback" is our normal hook_form_validate().
Using below steps, we can achieve ajax form validation and submit.
Steps :
1) Declare form elements
2) Call back definitions.
1) Declare form elements.
01 | $form['submit'] = array( |
02 | '#type' => 'submit', |
03 | '#value' => t('SUBMIT'), |
04 | '#validate' => array('validate_callback'), // custom form validate. |
05 | '#ajax' => array( |
06 | 'callback' => 'submit_callback', |
07 | 'effect' => 'fade', |
08 | 'wrapper' => 'specific-wrapper', |
09 | 'event' => 'click', |
10 | 'progress' => array('message' => '', 'type' => 'throbber'), |
11 | ), |
12 | ); |
2) Call back definitions.
1 | function submit_callback($form, $form_state) { |
2 | if (form_get_errors()) { |
3 | $form_state['rebuild'] = TRUE; |
4 | return $form; |
5 | } |
6 |
7 | $response = my_form_submit($form, $form_state); // write your form submit logic here. |
8 | return $response; |
9 | } |
Wednesday, 2 April 2014
media print css
<style type="text/css" media="print">
@media print{
@page {
size: auto; /* auto is the initial value */
margin: 10%;
}
@page :first {
margin-left: 2mm;
}
body * { visibility: hidden; }
.printconfirmationdiv * { visibility: visible; }
.printconfirmationdiv { position: absolute; top:40px;}
.confirmationContainerright * { display:none; }
.confirmationContainerleft{width:100% !important; }
.bookingTicketDetails{width:80% !important;}
.printcss{width:80% !important;}
.printcssfee{width:80% !important;}
a{display: none ; }
</style>
<a href="#" onclick="window.print();">
@media print{
@page {
size: auto; /* auto is the initial value */
margin: 10%;
}
@page :first {
margin-left: 2mm;
}
body * { visibility: hidden; }
.printconfirmationdiv * { visibility: visible; }
.printconfirmationdiv { position: absolute; top:40px;}
.confirmationContainerright * { display:none; }
.confirmationContainerleft{width:100% !important; }
.bookingTicketDetails{width:80% !important;}
.printcss{width:80% !important;}
.printcssfee{width:80% !important;}
a{display: none ; }
</style>
<a href="#" onclick="window.print();">
Tuesday, 18 March 2014
form validation using drupal7 using rules
$('#feedbackform').validate({
rules: {
feedbackFirstName: {
required: true
},
feedbackLastName: {
required: true
},
feedbackEmail: {
required: true,
email: true
},
feedbackConfirmemail: {
required: true,
email: true,
equalTo: "#feedbackEmail"
},
feedbackDescription: {
required: $(this).addClass('error'),
minlength: 1,
maxlength: 35
}
},
messages: {
}
});
/////////////////////
<form id="feedbackform" name="feedbackform">
<div class="modal-body">
<div class="row-fluid">
<div class="span12">
We would love to hear your thoughts, concerns or problems with anything so we can improve!<br>
<small> Required fields*</small>
<div class="row-fluid">
<div class="span12">
<fieldset>
<div class="row-fluid">
<div class="span12">
<br>
<label>Feedback Type</label>
<div class="row-fluid">
<div class="span3"> <label class="radio">
<input type="radio" name="feedbacktype" value="Comments" checked> Comments
</label></div>
<div class="span3">
<label class="radio">
<input type="radio" name="feedbacktype" value="Bug Reports"> Bug Reports
</label>
</div>
<div class="span3">
<label class="radio">
<input type="radio" name="feedbacktype" value="Questions"> Questions
</label>
</div>
</div><!-- row-fluid end -->
</div>
</div><!-- row-fluid end -->
<hr/>
<div class="row-fluid">
<div class="span12">
<!-- <label ></label> -->
<textarea placeholder="*Describe Feedback" rows="4" class="textareaStyle" id="feedbackDescription" name="feedbackDescription"></textarea>
</div>
</div><!-- row-fluid end -->
<hr/>
<div class="row-fluid">
<div class="span6">
<!-- <label></label> -->
<input type="text" placeholder="*First Name" class="inputfieldSmall inputfiledStyle" name="feedbackFirstName" id="feedbackFirstName"/>
</div>
<div class="span6">
<!-- <label></label> -->
<input type="text" placeholder="*Last Name" class="inputfieldSmall inputfiledStyle" name="feedbackLastName" id="feedbackLastName"/>
</div>
</div><!-- row-fluid end -->
<!-- <hr/> -->
<div class="row-fluid">
<div class="span6">
<!-- <label>*</label> -->
<input type="text" placeholder="*Email" class="inputfieldSmall inputfiledStyle" name="feedbackEmail" id="feedbackEmail"/>
</div>
<div class="span6">
<!-- <label>*</label> -->
<input type="text" placeholder="*Confirm Email" class="inputfieldSmall inputfiledStyle" name="feedbackConfirmemail" id="feedbackConfirmemail"/>
</div>
</div><!-- row-fluid end -->
</fieldset>
</div>
</div><!-- row-fluid end -->
</div>
</div><!-- row-fluid end -->
</div>
<div class="modal-footer">
<!--<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>-->
<!-- <button class="btn btn-primary" id="feedback">Submit</button>-->
<!--feedbackformSubmit-->
<span class="loadergif" style="display:none;"><img src="<?php echo base_path() . path_to_theme(); ?>/assets/img/status-active.gif" /></span>
<!--<input type="button" class="btn btn-primary" id="feedbackformSubmit" value="Submit"/>-->
<div class="requestbutton">
<input type="button" class="requestbuttonInner" id="feedbackformSubmit" value="Submit"/>
</div>
</div>
</form>
</div>
Subscribe to:
Comments (Atom)