3 replies [Last post]
nicoloconte's picture
Offline
Joined: 03/20/2009
Juice: 54
Was this information Helpful?

Hi guys,
I'm writting a new module to create a new field for the checkout. The field appear without problem but I'm unable to write the value on the database.

I wont to specify that it's the first time that I create a new module.

Someone could help me?

PreviewAttachmentSize
uc_cfiva.zip3.26 KB
nicoloconte's picture
Offline
Joined: 03/20/2009
Juice: 54
Re: Adding new field to checkout pane, same problem.

No one can help me?

jfarhat's picture
Offline
Joined: 11/04/2008
Juice: 12
Did you resolve this already?

I know this is an old post. But have you resolved it? If not I will take a look at the zip file.

lazhorus's picture
Offline
Joined: 10/11/2009
Juice: 2
I have the same issue/problem...

I would like to add a field to the checkout pane allowing the purchaser to enter the name/ID of the referer to the site [so we can track and reward referrers] I can add the element to the "form" yet -- how to save the value to the database eludes me.

in function uc_cart_form_alter of uc_cart.module, I made the following modifications to add form element [text field] to the checkout pane

/**
* Implementation of hook_form_alter().
*/
function uc_cart_form_alter(&$form, $form_state, $form_id) {
// Redirect shopper back to checkout page if they go to login from there.

//*************************************
//BEGIN ADDED CODE
//*************************************
if ($form_id == 'uc_cart_checkout_form')
{
//code mods start here-0001
//return print_r($form);
//exit;
$form['panes']['billing']['ref_agent'] = array(
'#type' => 'textfield',
'#title' => t('Referring Agent'),
'#default_value' => t('HOMEOFFICE'),
'#size' => 60,
'#maxlength' => 64,
'#required' => 1,
'#description' => t('Select name of referring agent [required] If not known, leave default value'),
);
}

//*************************************
//END ADDED CODE
//*************************************

if ($form_id == 'user_login' || $form_id == 'user_edit' || $form_id == 'user_register') {
// Parse the existing #action url.
$p = parse_url($form['#action']);
$query = array();
if ($p['query']) {
parse_str($p['query'], $query);
}
if ($p['scheme']) {
// Path is an absolute URL.
$path = $p['scheme'] .'://'
. ($p['user'] ? $p['user'] . ($p['pass'] ? ':'. $p['pass'] : '') .'@' : '')
. ($p['host'] ? $p['host'] : '')
. ($p['path'] ? $p['path'] : '');
}
else {
// Path needs to be an internal path so we can pass it to url() later.
// Strip off the base path.
$path = substr($p['path'], drupal_strlen(base_path()));
}

// Figure out the destination.
if ($_SESSION['checkout-redirect'] == TRUE) {
$query['destination'] = 'cart/checkout';
}
else {
// Compare the referer to checkout page URLs.
if (uc_referer_check('cart/checkout') && uc_referer_uri() != '') {
$query['destination'] = 'cart/checkout';
}
elseif (uc_referer_check(array('cart/checkout/review', 'cart/checkout/complete')) && uc_referer_uri() != '') {
$query['destination'] = 'user';
}
}

// Build the new #action url.
$form['#action'] = url($path, array('query' => $query, 'fragment' => $p['fragment']));
}

if ($form_id == 'user_login' || $form_id == 'user_login_block') {
$form['#submit'] = array_merge(array('uc_cart_user_login_form_submit'), (array) $form['#submit']);
}
}

The form element appears on the checkout pane as expected. I have added the appropriate column to the uc_order table. How do i submit the user inputted value to the database?