Does anyone know how to modify this code to make it redirect at different price points based on an entry in the database?Thanks in advance!!schult70"> Redirect based on database entry? - Forums

Forums

Redirect based on database entry?

schult70 05 Mar, 2011
Looking for help...

I have created a registration form for my local running club for runners to sign up for a special event. The event has several price points: $10 for Friday events only, $20 for Friday and Saturday, etc. In the form, I have created an entry (radio button) for people to choose between the different price points. However, I am having trouble figuring out how, when I redirect people to paypal to pay for their registrations, I can send the correct price to paypal based on the radio button they chose in the form (Friday only, Friday and Saturday, etc).

I am a ChronoForms newbie, but I have made quite a bit of progress so far just by searching the thread for info. Here's what I have done so far:

1. I have created the form (including the radio button w/ pricing options)
2. I set up email notifications for when new entries are submitted
3. I set up a database for entries
4. I used ChronoConnectivity to report out certain database items to a "Who Has Registered" site
5. I have set up the form to redirect to paypal (after creating email/database), BUT ONLY TO REDIRECT AT A SINGULAR PRICE POINT, AND NOT BASED ON WHAT THEY CHOSE TO PURCHASE IN THE FORM. Here is the code I used:

OnSubmit-before code: None

OnSubmit-after code:
Press the "Buy Now" button below to complete the transaction: <br />
<br />
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="post@domain.com">
<input type="hidden" name="item_name" value="Runner Registration">
<input type="hidden" name="amount" value="69.00">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="return" value="http://www.domain.com">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" name="submit" alt="Make payments with payPal - it's fast, free and secure!">
<img alt=""
src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>


Does anyone know how to modify this code to make it redirect at different price points based on an entry in the database?

Thanks in advance!!
schult70
GreyHead 05 Mar, 2011
Hi shult70,

I've just posted an answer to your serch for the ReDirect plug-in in another thread. I would use this plug-in in preference to the Buy Now button but either wioll work OK.

You need to calculate the value of the 'amount'. I would probably do this using a JavaScript snippet in the form itself so that the process is transparent to the user. They check the radio button and the amount is (a) displayed and (a) addd to a hidden input ready to be passed to PayPal. (You might also double check the result using PHP after the form is submitted.)

You can use {amount} in the OnSumit After Email box to add the value of the amount input from the form.

Bob
schult70 05 Mar, 2011
I think my problem is in writing the code in the form for the "Javascript snippet" you mentioned. I'm sure it's pretty easy, but I haven't written code since Fortran in college. 🙂 Capturing data from the radio button is what is hanging me up.

A description of what is in my form:
Label in Chronoform = Registration Option
Radio Choice 1 = Friday Only ($10)
Radio Choice 2 = Friday and Saturday ($20)

I need to add code to capture whether they chose Radio Choice 1 (fixed price = $10) or Radio Choice 2 (fixed price = $20) and apply the correct cost it to some type of hidden variable. (I don't think I'll need to redisplay the dollar amount to the user.) Later, I need to recall that hidden variable to send the correct cost to Paypal. It seems as if this is just an if/else statement, but the complexity of the radio button code is confusing me. Seems like the code is saving data to either "radio10 OR radio 11" AND "radio1" (See below)? Not sure which to refer to in the new code (nor how to write the line in Javascript)!

Here is the code from my form:
<div class="form_item">
  <div class="form_element cf_radiobutton">
    <label class="cf_label" style="width: 150px;">Registration Option</label>
    <div class="float_left">
      <input value="Friday Only ($10)" title="" class="radio validate-one-required" id="radio10" name="radio1" type="radio" />
      <label for="radio10" class="radio_label">Friday Only ($10)</label>
      <br />
      
<input value="Friday and Saturday ($20)" title="" class="radio validate-one-required" id="radio11" name="radio1" type="radio" />
      <label for="radio11" class="radio_label">Friday and Saturday ($20)</label>
      <br />
</div>
    
  </div>
I know this is fairly pathetic, but thanks for helping someone stuck in the DOS era!!!
GreyHead 05 Mar, 2011
Hi schult70,

Please try this:

In the Form HTML add:
<input type='hidden' name='amount' id='amount' value='' /> 


And in the Form JavSCript box:
window.addEvent('domready', function() {
  $('radio10').addEvent('click', calculate);
  $('radio11').addEvent('click', calculate);
});
function calculate() {
  var amount = 10;
  if ( $('radio11').checked ) {
    amount = 20;
  }
  $('amount').value = value;
};


Bob
schult70 05 Mar, 2011
OK. So I added that code, but unfortunately I don't know if it's working or not because I can't get the redirect plugin to work. When I submit the form, I just get blank body text... I am redirected nowhere.

Here is what I have in the redirect plugin:
Field Names from your Form:
I have copied all of the same things that are to the right of the textboxes. For example, for 'text_1' field, typed text_1 in box, etc., all the way down the list.

For "Extra field values to send", I put the following in box:Field names from your form
cmd=_xclick
business=your_paypal_email@whatever.com
item_name=Runner Registration
currency_code=USD
return=http://www.yahoo.com

I did not know how to link the code you sent above into the redirect link. Seems like there should be something somewhere that refers to that tag you created in the javascript above to send that data to paypal, but I'm not seeing where that is happening.

In URL Parameters, I entered a target url of http://www.paypal.com/cgi-bin/webscr", flow control = After Email.

I have nothing in the CURL part.

What am I missing here?
GreyHead 05 Mar, 2011
Hi schult70,

Please check that the plug-in is enabled on the form Plug-ins tab. A **green** bar is enabled and red is disabled. Please only enable the plug-ins you are actually using otherwise they may interfere with each other. Also check the plug-in order to make sure that makes sense -- you can drag the bars to change the order.

Bob
schult70 05 Mar, 2011
Oh, thank goodness. That worked. Kind of. At least it is redirecting!

So now the form redirects to paypal, but does not specify a dollar amount for the item. How do I get the dollar amount gathered in the Javascript snippet you coded earlier to transfer to paypal via the redirect?
schult70 05 Mar, 2011
I'm getting increasingly nervous that this redirect plugin is not going to work for me. I just realized that I have another layer of complexity in this form that may make this more difficult.

So here is the layout.
Question 1 on form is for Payment Option. Options are the following radio buttons:
Pay via Paypal
I will mail a check
I will pay you in person

Question 2 on form is the one I alluded to earlier for Registration Type. Options are the following radio buttons:
Friday Only
Friday and Saturday

I need the form to do the following:
-If user chooses to mail a check, I need to NOT redirect to paypal, but just display a text box with address to send check to (simple HTML code).
-If user chooses to pay in person, I need to NOT redirect to paypal, but just display a different text box with a thank you message (simple HTML code).
-If user chooses to pay via paypal, THAT is when I need the form to do what we were talking about earlier (capture data if they wanted Friday Only or Friday and Saturday, assign the appropriate fixed dollar amount, and send that data/redirect to Paypal).

It seems really easy with a string of IF/ELSE statements in the OnSubmit After box (if I knew how to write the code). Is there a way to write the code to NOT use the redirect plugin for the first two scenarios (use HTML code instead and not execute redirect plugin), else execute redirect plugin?
GreyHead 06 Mar, 2011
Hi schul70,

Hmm . .. there is no (easy) way in the present version of stopping a plug-in. When the code was first written I don't think that Max envisaged such complex work-flows. (It has been built in to ChronForms v4 though).

Your best bet is, as you say, not to use the plug-in but to build the ReDirect URL manually - you can use the code from the plug-in if that helps.

Bob
schult70 06 Mar, 2011
OK. I am SO CLOSE.

I have developed the following code and placed it in my OnSubmit After box:

<?php
$radio2 = JRequest::getString('radio2');
switch ($radio2 ) {

case "I already gave/sent a check.":
echo "
<h2>Thank you for registering for the Run!</h2>
<p><strong>Don't forget to pay us!</strong></p>
<p>If we do not receive your payment by the Early Bird cut off, sucks to be you!</p>
";
break;

case "I'll need instructions for mailing a check.":
echo "
<h2>Thank you for registering for the Run!</h2>
<p><strong>You may send your payment to:</strong></p>
<p>blah blah</p>
<p> blah blah</p>
<p> blah blah</p>
";
break;
default: echo " 
<h2>To pay by credit card, follow the paypal link and click on the button that says \"I don't have a PayPal account\". It will then give you the option to enter a credit card.</h2> 
<p>(There will be a small processing fee charged by PayPal)</p>"; 

$radio1 = JRequest::getString('radio1');
switch ($radio1 ) {

case 'Friday and Saturday ($20)':
echo '
<h2>I want it all!</h2>
';
break;

default: echo '
<h2> Press the\"Buy Now\" button below to complete the transaction:</h2>';
 form action='https://www.paypal.com/cgi-bin/webscr' method='post'
   input type='hidden' name='cmd' value='_xclick'
   input type='hidden' name='business' value='post@domain.com'
   input type='hidden' name='item_name' value='IndyScent 2011 Prom Registration'
   input type='hidden' name='amount' value='10.00'
   input type='hidden' name='no_shipping' value='1'
   input type='hidden' name='no_note' value='1'
   input type='hidden' name='currency_code' value='USD"
   input type='hidden' name='return'value='http://www.domain.com'
   input type='image'src='https://www.paypal.com/en_US/i/btn/x-click-but23.gif' name='submit' alt='Make payments with PayPal - it's fast, free and secure!'
   img alt='' 
   src='https://www.paypal.com/en_US/i/scr/pixel.gif' width='1'height='1',
</form>

break;
}

;
break;
}
?>

Basically, the format is a nested switch. The "outside" switch (the one that controls "I'll need to send a check", "I already sent a check", or "I'd like to pay via PayPal [default]) works fine. Also, half of the "inside" switch (Friday and Saturday) works fine too (returns text "I want it all" as a placeholder). The one that I am working on is the Friday Only (default) part of the inside switch.

When running this code, "I get a Parse Error, Unexpected T String" at line 37 (start of the inside default string). I have stared and stared at the code, and can't figure out what the error is. I believe it probably has something to do with the form_action that follows it... but unfortunately I copied this code for the Paypal redirect from another thread and don't fully understand how it works, and so I am having issues debugging it.

Any ideas? I'm going crazy... and SO CLOSE to finishing the form!!!!
GreyHead 06 Mar, 2011
Hi schult70,

There were a scattering of quote problems and a lot of missing < & /> in this block:
default: echo "
<h2> Press the\"Buy Now\" button below to complete the transaction:</h2>';
 <form action='https://www.paypal.com/cgi-bin/webscr' method='post'/>
   <input type='hidden' name='cmd' value='_xclick' />
   <input type='hidden' name='business' value='post@domain.com' />
   <input type='hidden' name='item_name' value='IndyScent 2011 Prom Registration' />
   <input type='hidden' name='amount' value='10.00' />
   <input type='hidden' name='no_shipping' value='1' />
   <input type='hidden' name='no_note' value='1' />
   <input type='hidden' name='currency_code' value='USD' />
   <input type='hidden' name='return' value='http://www.domain.com' />
   <input type='image'src='https://www.paypal.com/en_US/i/btn/x-click-but23.gif' name='submit' alt='Make payments with PayPal - it\'s fast, free and secure!' />
   <img alt='' 
   src='https://www.paypal.com/en_US/i/scr/pixel.gif' width='1'height='1' />
</form>";

Bob
schult70 06 Mar, 2011
Nevermind. I figured it out finally. For anyone who is interested, this is the code that I used to make it work:

<?php
$radio2 = JRequest::getString('radio2');
switch ($radio2 ) {

case "I already gave/sent a check.":
echo "
<h2>Thank you for registering for the Run!</h2>
<p><strong>Don't forget to pay us!</strong></p>
<p>If we do not receive your payment by the Early Bird cut off, too bad!</p>
";
break;

case "I'll need instructions for mailing a check.":
echo "
<h2>Thank you for registering for the Run!</h2>
<p><strong>You may send your payment to:</strong></p>
<p>blahblah</p>
<p> blahblah </p>
<p> blahblah </p>
</br>
<p>Please remember: Your payment must be received by the Early Bird Cutoff Date to receive reduced prices. Be sure to take into account postal delivery times!</p>
";
break;
default:

$radio1 = JRequest::getString('radio1');
switch ($radio1 ) {

case 'Friday and Saturday':
header('Location: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&add=1&business=test@domain.com&item%5Fname=Runners%5Fname=Run& item%5Fnumber=Friday and Saturday &amount=20%2E00&return=http%3A%2F%2Fwww%2Epaypal%2Ecom&cancel%5Freturn=http%3A%2F%2Fwww%2Epaypal%2Ecom');
//www.paypal.com/cgi-bin/webscr?cmd=_cart&add=1&business=fakeemail@test.com&item%5Fname=I&item%5Fname=123456&amount=40%2E00&return=http%3A%2F%2Fwww%2Epaypal%2Ecom&cancel%5Freturn=http%3A%2F%2Fwww%2Epaypal%2Ecom');

break;

default:
header('Location: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&add=1&business=test@domain.com&item%5Fname=Runners&item%5Fname=Run&item%5Fnumber=Friday Only&amount=40%2E00&return=http%3A%2F%2Fwww%2Epaypal%2Ecom&cancel%5Freturn=http%3A%2F%2Fwww%2Epaypal%2Ecom');
//www.paypal.com/cgi-bin/webscr?cmd=_cart&add=1&business=fakeemail@test.com&item%5Fname=I&item%5Fname=123456&amount=40%2E00&return=http%3A%2F%2Fwww%2Epaypal%2Ecom&cancel%5Freturn=http%3A%2F%2Fwww%2Epaypal%2Ecom');
break;
}

;
break;
}
?>
This topic is locked and no more replies can be posted.