Form validation issues.

outtolunc - September 3, 2008 - 03:38
Project:Donation
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work
Description

While attempting to make this module more non-profit/political friendly, i noticed (due to the additional fields), that this module was not doing any validation of required fields. (at least it wasn't working for me)

I am new to drupal so i am probably missing something completely obvious.

Here is a link to the donation.module i modified. http://dynx.net/donation.module.txt

Basically.. i added fields with validation, and to get the validation to work (which it does now), i had to ..

comment out: $form['#action'] = simple_paypal_get_url();

change:
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Proceed to paypal.com for payment'),
'#name' => 'submit',
);

to:
$form['submit'] = array(
'#type' => 'button',
'#value' => t('Proceed to paypal.com for payment'),
'#name' => 'submit',
);

added: function donation_form_build_validate($form_id, $form_values)
Which is not needed, but works for additional validation.

added: function donation_form_build_submit($form_id, $form_values)
In an attempt to submit the validated form to paypal (which is not working).

It has been a long day, and due to misfiring braincells and lack of drupal understanding, i was hoping one of you could hit me with a cluex4 before i lose any more of my already thinning hair.

Disclaimer: Any/all of these modifications to this module i have done are disclaimed to this project. (just in case there is that issue)

Thank you in advance for your time.

AttachmentSize
donation.module.txt28.12 KB

#1

kbahey - September 3, 2008 - 03:57
Status:active» needs work

I agree that it is best to validate the input. This is a nice feature to have.

The issue here is that a #action redirects to a external URL, which simple paypal provides (either the sandbox or the live site). This is required.

So, it boils down on how can one do validation locally, then submitting to an external URL.

One approach is to do validation locally, and then use cURL to submit the form to Paypal. However, this creates a dependency on cURL and not all sites have it installed.

Another is using http://api.drupal.org/api/function/drupal_http_request/5 with a POST method. Not sure if that would work seamlessly or not.

I'd rather find a way to do it without external dependencies (cURL).

All working and tested patches welcome.

#2

outtolunc - September 6, 2008 - 04:48

Updated: http://dynx.net/donation-npp/

More changes.

note the following defines..

define('DONATION_DEBUG', 0);
define('DONATION_HTTPS', 1);

Still not a lot of real world testing, but seems to behave fairly well. I have not done a fresh test install to see if table creation proceeds correctly.

 
 

Drupal is a registered trademark of Dries Buytaert.