I've searched through forums, documentation, etc. for some help on this, but I'm afraid this is slightly over my head. If you visit the URL above you'll see a "donate" form generated by your plug-in. What I'd like to do is use your form to send a bunch of data to a PayPal payments page. The HTML below is what a really simply form should do in order to get the correct data to PayPal:
Your plug-in makes it easy to change the form action, but how do I get the input fields on the "donate" form to match up with what PayPal is looking for? I've read some things about using cforms' "tracking tables" to store and manipulate data, but I'm not certain where these are and how I use them.
Can you help at least point me in the right direction? Thanks Oliver!
First you need to upgrade to the latest version of cforms as earlier releases did not support custom names for input fields & hidden fields.
After upgrade, enable custom names and setup your form. Essentially all fields will be hidden fields and one single line input field "amount".
The content of the hidden fields can be set with 'default values' (see Help page) or even be driven by post/page custom fields, in case you want to have different donation pages in different product/serviice contexts.
Post action will be redirected to the paypal address.
In the cformsII admin, the way I typed it is this:
business|email@domain.com
When I submit the form data to PayPal, it tells me the email address is invalid. Upon inspection of the source code, I see that the '@' symbol has been transformed to a % sign, so what PayPal is getting is:
Is there a way to preserve the @ symbol? I tried HTML character equivalents and placing the string in quotes, but no luck.
Also, I'm not sure what you meant in your reply by "one single line input field 'amount'". This may be outside of your realm, but what I'd like to do is let the user choose a donation amount from the dropdown menu and assign that option value to the "amount" hidden field. So if a user elects to donate $75, the "amount" hidden field would be:
<input type="hidden" name="amount" value="75.00">
I know you can work with variables via the cforms admin, but it looks like it's limited to WordPress custom fields. Is there a way to adjust the value of "amount" based on what is chosen via the dropdown menu? I.e., the associated hidden field would look something like:
Right, this line converts any default values for hidden fields to a URL encoded string – I guess the idea was to make sure that users don't accidentally mess up the HTML…
rawurlencode($field_value)
Simply find the above line in cforms.php and replace with:
$field_value
This should fix the first issue.
I know you can work with variables via the cforms admin, but it looks like it’s limited to WordPress custom fields. Is there a way to adjust the value of "amount" based on what is chosen via the dropdown menu?
That is currently not possible. Hence my suggestion to use a free form entry field (and not the drop down).
There might be another alternative:
If you're savvy with Javascript, you could write a couple of lines that would sit on-top the mouse_up event (associated with the drop down field) and in case of change would automatically update the hidden field.
The only drawback: this would only work correctly with Javascript. Which any other solution would have to, too, because you're redirecting the POST action and thus there is no "post-processing" possible in non-ajax mode. Hope this makes sense.
I've got a basic form submitting to PayPal with the changes you gave. Thanks! However, I have another question. I have another form that offers three subscription rates via select menu. To get the option values sent to PayPal in the right form, the select menu has to look like this:
<select name='item_price'>
<option value='1.00'>8oz</option>
<option value='2.00'>16oz</option>
<option value='3.00'>24oz</option>
</select>
The only problem is that I don't know how to change the 'name' of the select menus via the cforms control panel. I can't very well have the 'label' reading "item_price" because that wouldn't make sense to the visitors. Is there any way to make this modification?
I'm not sure why my response was on a different thread… thanks for your creative solution – it works.
I've posted my solution below in case anyone else is looking to use cforms to send data to PayPal. I know there are millions of ways someone would want to submit data, and that this is just one. In my case, (deviating from the original problem with the select menu), I wanted to allow a user to enter a donation amount in a text input field. The way to do this normally is by using the following input field:
Note that the input name must be set to amount (lower case). Currently, cforms does not allow you to separate the label name from the input name; what that means is you either have a label that says "amount" – which in most cases won't look right to your site's visitors – or you have to do some CSS trickery.
In the cforms form-builder, the proper way to do it is to create two text input fields. The first one will have the label you want your users to see. In my case, this is "Gift Amount". The second will have the label "amount". The goal is to hide the ugly "amount" label, then shift the "amount" input box up, so it looks like it is associated with the "Gift Amount" label.
Here's how it looks in the cforms form-builder:
Note the second line uses a regular expression to verify that the user enters a dollar amount (100, 100.00, $100, or $100.00 format).
Without any CSS mods, you'll have two input fields on your screen:
Again, the idea is to hide the second label and shift the second input box up. I inserted the following CSS lines into cforms.css:
Be sure to replace "2" with the number of your form and "5" or "6" with the list item number (view source or look at the numbers on the far left of the form-builder to determine the list item number). You'll almost certainly have to adjust the margins and absolute positioning to get the input where you want – it depends on how you've got your form styled elsewhere.
No problem. I actually found a better way of passing along data without doing any CSS madness. It requires enabling alternative form action (which I think has caused another issue me – see end of post) and pointing to a PHP file, which processes the form data. This PHP approach works really well if you need to capture the form data (have it sent to you in an email) and then send it to PayPal with the click of one "buy now" or "donate" button.
As it turns out, you need not worry about the field names at all, since you can change them in the PHP in one line. Suppose, as in the above example, that I want the label for my field to read "Gift Amount". If I turn on custom IDs, the field name will be "Gift_Amount"; e.g.:
In the PHP file, all I need to do is assign this field name to the variable "amount":
$amount = $_POST['Gift_Amount'];
Because PayPal only understands a lowercase "amount", we have to make the variable name the same.
Below the PHP section is a new HTML page that redirects the user to PayPal and sends along the form data. If you're using unencrypted buttons, PayPal looks for the following line to determine the amount:
<input type="hidden" name="amount" value="50.00">
To dynamically change the amount, replace that line with:
The amount is replaced with whatever amount you entered in the "Gift Amount" field above. I'm not sure how people can get in touch with me if they have questions, but there it is.
Now, I've been having trouble with field validation using this method. It worked, then it didn't, so I added regular expressions. I know you have a note about validation not working if you enable alternative form action, but shouldn't the form fail to send if I have required fields flagged and use regex? I suppose my real question is…what do you think could be wrong here?
It requires enabling alternative form action (which I think has caused another issue me – see end of post) and pointing to a PHP file, which processes the form data.
Very nice workaround! I didn't even think that you could "pass on" a POST request…this is great!
Now, I’ve been having trouble with field validation using this method. It worked, then it didn’t, so I added regular expressions. I know you have a note about validation not working if you enable alternative form action, but shouldn’t the form fail to send if I have required fields flagged and use regex? I suppose my real question is…what do you think could be wrong here?
If you have Ajax enabled then all the form validation (incl. regexp) is done by Javascript. So this works. Non javascript however can not work, since the form action points to a different php file.
I just tried hitting the "Donate Button" and there seems to be validation in place, or am I missing the issue?
I actually duplicated the form and redid the validation and it worked fine. I'm not sure what the issue was, but everything is smooth now. Thanks so much for your help on this. I'm planning on setting up a weblog in the near future and I'd like to post my code-related findings on it. I'll come back here when it's set up and post a link so anyone who is interested can read a more indepth solution.
Is there any way you can post the php file information on here? I'm having a tough time with this, and it looks like you have the method I am looking for.
Ideally, I need a Select menu for the user to select a product with a fixed price, in addition to gathering their user data (normal submit form stuff – name, age, address, etc) and sending that to an email as well as launching the paypal screen.
I noticed that on your example page :http://www.rmfu.org/give/, it does just that.