How to set custom button?

pebosi - November 10, 2008 - 10:30
Project:lm_paypal
Version:6.x-1.x-dev
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

How to set a custom url to an alternate subscribe button? ( = http://www.paypal.com/de_DE/i/btn/x-click-but20.gif)

regards

#1

lyricnz - November 10, 2008 - 11:42

You want to change the graphic? This probably falls into #328023: Change all the output blocks so they can be themed more easily. There is currently no capability to do this in the UI, but you may be able to do it in a third-party module (hook_form_alter) or in your custom theme (theming the LM Paypal Subscriptions block). The low-level function in the code actually has the ability to use custom graphics for the button (third parameter to function lm_paypal_subscribe()).

#2

pounard - May 3, 2009 - 23:12

<?php
 
if (isset($button_url) && $button_url) {
   
// TODO button as url
   
$form['submit'] = array(
     
'#type' => 'submit',
     
'#value' => $button_text,
     
'#name' => 'submit',
    );
  }
  else {
   
$form['submit'] = array(
     
'#type' => 'submit',
     
'#value' => $button_text,
     
'#name' => 'submit',
    );
  }
?>

AHAH ! :)

Seriously, we have to find a way to tell Drupal's theme or form API that we want a "custom" button.

#3

pounard - May 3, 2009 - 23:20

I finally found how to tell Drupal to put an image submit button YaY!
It was pretty simple, I just wasn't looking at the right place!

I quickly do a simple administration setting to let the user put an external button url and commit it!

<?php
 
if (isset($button_url) && $button_url) {
   
$form['submit'] = array(
     
'#type' => 'image_button',
     
'#value' => $button_text,
     
'#attributes' => array('src' => $button_url),
     
'#name' => 'submit',
    );
  }
  else {
   
$form['submit'] = array(
     
'#type' => 'submit',
     
'#value' => $button_text,
     
'#name' => 'submit',
    );
  }
?>

The only thing to do is *DO NOT* use the form "image_button" element "#src" attribute, else it will just add a "/" before (or whatever your $path is).

This method can be used in any hook_form_alter(), even in [theme]_[form_id]_preprocess() hook.

#4

lyricnz - May 4, 2009 - 10:10

I just checked ecommerce, and they have paypal buttons in their CVS

http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/ecommerce/e...

The (default) buttons we'd want are at

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=develo...

I couldn't find a reference that said definitively that we were allowed to copy these to our site....

 
 

Drupal is a registered trademark of Dries Buytaert.