Forums

How to emulate custom form action with OnSubmit events

solanus 23 Jul, 2011
Hi,
I've been searching these forums for several hours, and so far I haven't seen an answer to my problem. I hope you can help.
I'm running:
Joomla 1.6.3
ChronoformsV4

I had a form I hand-coded to pass data to my gateway, and it worked fine, but I wanted to take advantage of the e-mail and DB capabilities of Chronoforms.
Here's the glitch: in the original, the code for the form action is:
<form action="https://www.linkpointcentral.com/lpc/servlet/lppay" method="post">

In the original handcoded form, I click the submit button, it passes some data to the gateway page and takes me to that page, all is well.

When I ported it to Chronoforms, I had to strip away the form field, of course. The only way I know to make the action act like the original is to put https://www.linkpointcentral.com/lpc/servlet/lppay into the SubmitURL field - but then, "Adding a submit URL will disable all the form "on submit" event functions," which negates my e-mail and DB save functions, so it's no better than handcoded.

Here are the events I have set up:
OnLoad:
[list] Load CSS (just some simple styling)
Show HTML (left the default settings)[/list]
OnSubmit:
[list] DB Save (to table created from the form)
Email #1
Email #2
Email #3[/list]

I tried adding a CURL to OnSubmit with the path https://www.linkpointcentral.com/lpc/servlet/lppay, but that didn't seem to work.
How do I get this form to act as though the form action is https://www.linkpointcentral.com/lpc/servlet/lppay, while at the same time executing all the OnSubmit events?
Thanks.
GreyHead 23 Jul, 2011
Hi solanus,

Can you post a link to the docs for the Gateway that you are using. I took a quick look but couldn't see which of the options matched the code you have here.

The critical questions are (a) does the user need to be redirected and (b) will the gateway accept 'get' as well as 'post'.

If the user doesn't need to be redirected then the cURL action will probably do what you need.

If the user does need to be redirected and 'get' is supported then the ReDirect actions will probably work.

If the user has to be redirected and 'get' is not supported then it gets tricky. The best solution I've seen do far is to set up a 'confirmation page' which is actually a form with all the needed info in hidden inputs and an action set to the gateway url. Then you can either have a 'Confirm' button that submits the form; or use JavaScript to autoamtically submit the form when the age is loaded.

Bob
solanus 23 Jul, 2011
Thanks for your quick response, Bob,
1. The user definitely need to be redirected. My form contains some required information that gets posted to the gateway's secure site to complete the transaction using their forms. Name, e-mail, and price of their selection are required on my form, but I don't collect credit card info - that gets done on the gateway's secure site.
2. I haven't seen any documentation about whether GET can be used, but considering the security issues for GET, and the fact that there is a lot of field data that gets transferred, I would not use GET.

Here's the manual for the gateway.
http://www.firstdata.com/documents/fd_globalgatewayconnect_usermanualnorthamerica.pdf
I know the gateway sends a very minimalist e-mail to the customer, but I also see that it can post data back to the page of my choice at the end of the transaction. I just don't know yet which data gets returned.
If the site sends back ALL of my form data, then I might be able to use my handcoded form to initiate the transaction, and then use Chronoforms to process the data in a confirmation page. This could allow me to add more fields to gather info from the user at that point...
The only issue with that is that I'll need to complete some transactions fully just to test the process (not impossible, it just becomes complicated to delete the dummy data in the gateway records).
GreyHead 23 Jul, 2011
Hi solanus,

I'd go with using post and an auto-submitting form. I would create a ChronoForm, save all of the data to a table, then auto-submit to the Gateway including a unique transaction identifier that will be passed back to you by the gateway (if thre isn’t one as standard add it to the return url).

I see a few references to 'test' in the docs but no clear instructions about running test transactions - that must? be possible somehow.

In ChronoForms you'll need to add a Custom Event to handle the response from the Gateway, you can do this using Add Event on the same form. If the Event is say fd_ggc then you'd need &event=fd_ggc in the url

In a Custom Action in the Custom Event capture the unique identifier; check that it is valid. Then process the results as necessary. You can use any of the standard actions to do this.

Bob
solanus 23 Jul, 2011
Thanks, Bob,

I'm unclear about how to go about creating an auto-submitting form. What events would I need to add to make this happen?
I'm assuming this sequence of events:
1. User fills our Chronoforms and submits
2. Chronoform saves data to DB (and sends e-mails?)
3. Using magic (read: I don't know how to do this) Chronoforms auto-submits the data from the first form to the gateway URL, using POST.
4. The user is redirected to the Gateway site to complete the transaction.

P.S. My original idea of using the returned data from the gateway won't fly, because I have several different forms, and I want different database tables and e-mails for each; but the gateway only supports a total of ONE confirmation page.

P.P.S. I also don't know how the unique identifier would be of use. Currently, my form already contains hidden fields that are required by the gateway ("storename", etc).

P.P.P.S. The "Testing" I was referring to is the use of dummy credit card info to complete an order without actually paying. The gateway supplies those numbers.
GreyHead 23 Jul, 2011
Hi Solanus,

I'm making this up as we go along so my apologies if we go astray.
[list=1]
  • Yes.

  • Yes - up to you when you send emails. The important ones presumably come after the payment is confirmed.

  • [list=a]
  • Add a Custom Code action and build a form in it. You can probably copy and paste the HTML from your 'old' form.

  • Set the variables values from the form data using
    value="<?php echo $form->data['input_name']; ?>"

  • Make sure that the form tag has an id set

  • Make sure that any submit button does not have name or id = submit; use submit_btn instead (otherwise the next bit breaks in some browsers)

  • Add this script to the page
    <script type='text/javascript'>
    window.addEvent('domready', function() {
      $('form_id').submit();
    });
    </script>

  • Test
  • [/list:o][/list:o]

    The unique identifier is just to make sure that you can identify the correct saved record when the response comes from the gateway. ChronoForms has no other way of knowing what transaction is being handled.

    Bob
    solanus 23 Jul, 2011
    Thanks for the magic, Bob!
    I was considering something similar, but I like your solution better.
    I'm using the e-mails to return copies of the applications, not necessarily to be confirmations of payment - the gateway will send an e-mail receipt anyway.

    I'll play with this idea and get back to you later today to let you know how it works.
    solanus 23 Jul, 2011
    Bob,
    Not quite there yet...
    I did what you told me, including adding an id to the form code on the Thanks page, and that same id goes into the javascript. Still hitting a roadblock.
    1st, I'm not getting the data transferred from the Chronoform to the form created in the Thanks page - it just shows the PHP code in the fields.
    Example: in the Chronoform I have a Name field coded like this:

    <input name="bname" size="80" value="" type="text" />

    In the form in the Thanks page, the Name field code is this:

    <input name="bname" size="80" value="<?php echo $form->data['bname']; ?>" type="text" />

    I omitted the javascript so it would stop on the ThankYou form, but instead of transferring the value from the Chronoform, what it shows in the text box is:

    <?php echo $form->data['bname']; ?>

    I know somehow I'm missing something simple. I've been playing with all kinds of syntax, but nothing seems to work - there's a fundamental flaw that I am not getting.

    2nd, the gateway needs me to specify exactly the url that is submitting the form, but the thank you page is different - a minor annoyance, but fixable on my side. I just need to keep the URL lengths to a minimum.

    On the bright side, when I include the javascript, it does automatically try to submit the form to the correct gateway.

    I feel this is in my grasp...
    solanus 23 Jul, 2011
    Breakthrough!
    The whole PHP thing was not necessary. I just use the syntax you use in e-mails!

    So, instead of
    <input name="bname" size="80" value="<?php echo $form->data['bname']; ?>" type="text" />

    I use
    <input name="bname" size="80" value="{bname}" type="text" />

    and it seems to pass the data OK. I'm going to rework the whole thing tonight, after it cools down (we have it around 96F or 35C here, too hot to think!)
    Solanus
    GreyHead 24 Jul, 2011
    Hi Solanus,

    My apologies, I hadn't realised that the Show Thanks Message action doesn't support PHP. I just checked the code and it only has the 'curly replacer'.

    For other readers this means that if you want to include other data (not directly from the form) in the Thanks Page then you have to use a Custom Code action to add it to the $form->data array first. Then you can use the 'curly brackets' syntax to display it in the message.

    Bob
    This topic is locked and no more replies can be posted.