-1

ユーザーが規則のフォームや要素を表示する必要がないように、commerc_paypal_wps フォームの単純なコピーを論理的な場所に作成するモジュールを作成しようとしています。

フォームの値を取得して保存するのに問題があります。

私のコードは次のとおりです。

<?php

//Create the admin page
function sb_paypal_settings_menu() {

$items['admin/commerce/config/paypal'] = array(
  'title' => 'Paypal settings',
  //'description' => 'Set values for your site such as site name.',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('site_settings_admin_1'),
  'access arguments' => array('administer paypal settings'),
  'file path' => drupal_get_path('module', 'rules_admin'),
  'file' => 'rules_admin.inc',
  'type' => MENU_NORMAL_ITEM,
);
return $items;

}

//Valid permissions for this module
function sb_paypal_settings_permission() {
return array(
'administer paypal settings' => array(
  'title' => t('Administer Paypal settings')      
),
);
}

//Create the form
function site_settings_admin_1() {

$form = drupal_get_form('commerce_paypal_wps_settings_form');


unset($form['ipn_logging']);

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);

return($form);

}

モジュールのコードはhttp://drupalcontrib.org/api/drupal/contributions!commerce_paypal!modules!wps!commerce_paypal_wps.module/function/commerce_paypal_wps_settings_form/7にあります。

フォームが必要とする情報は rules_config テーブルに保存されます。

4

1 に答える 1

0

解決策は、値を変更するモジュールを作成することでした。.module ファイルのコードは次のとおりです。

<?php
// $Id$

//Create the admin page
function paypal_settings_menu() {
$items['admin/commerce/config/paypal_settings'] = array(
  'title' => 'Paypal payment settings',
  'description' => 'Add your paypal email address',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('paypal_settings_admin'),
  'access arguments' => array('administer paypal payment settings'),
  'file path' => drupal_get_path('module', 'rules_admin'),
  'file' => 'rules_admin.inc',
  'type' => MENU_NORMAL_ITEM,
);
return $items;
}

//Valid permissions for this module
function paypal_settings_permission() {
return array(
'administer paypal payment settings' => array(
  'title' => t('Administer Paypal payment settings')      
),
);
}

//Create the form
function paypal_settings_admin() {

$query = db_query("SELECT * FROM rules_config WHERE name='commerce_payment_paypal_wps'")->fetchAll();
if (count($query) == 1) {
$settings = unserialize($query[0]->data);
}


$pay_settings;

$actions = $settings->actions();

foreach ( $actions as $action ) {
$pay_settings = &$action->settings['payment_method']['settings'];
break;
} 

$saveval = serialize($settings);

$form['business_email'] = array(
'#type' => 'textfield',
'#title' => t('PayPal e-mail address'),
'#description' => t('The e-mail address you use for the PayPal account you want to receive payments.'),
'#default_value' => $pay_settings['business'],
'#required' => TRUE,
);

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);  
$form['#submit'][] = 'paypal_settings_form_submit';
return $form;

}

function paypal_settings_form_submit(&$form, &$form_state) {

$query = db_query("SELECT * FROM rules_config WHERE name='commerce_payment_paypal_wps'")->fetchAll();

if (count($query) == 1) {
$settings = unserialize($query[0]->data);
}

$pay_settings = null;

$actions = $settings->actions();

foreach ( $actions as $action ) {
$pay_settings = &$action->settings['payment_method']['settings'];
break;
}

$pay_settings['business'] = $form_state['values']['business_email'];  

$insertquery = db_update('rules_config')
->fields(array(
'data' => serialize($settings),
))
->condition('name', 'commerce_payment_paypal_wps')
->execute();

}
于 2012-09-12T12:13:05.470 に答える