Class: Omnipay::AutosubmitForm

Inherits:
Object
  • Object
show all
Defined in:
lib/omnipay/autosubmit_form.rb

Overview

This class is responsible for generating an html page which will redirect its visitor to an arbitrary url, with arbitrary POST parameters in the request body.

It does so by including an hidden form in the page, and submitting it via javascript on page load.

Constant Summary collapse

HEADER =
<<-HEADER
<!DOCTYPE html>
<html>
  <head>
<title>You are being redirected</title>
  </head>
  <body>
<h1>Redirecting...</h1>
HEADER
<<-FOOTER
    <script type="text/javascript">
      document.getElementById('autosubmit-form').submit();
    </script>
  </body>
</html>
FOOTER

Instance Method Summary collapse

Constructor Details

#initialize(action, fields) ⇒ AutosubmitForm

Initializes the form with its action, and its inputs name/value pairs

Parameters:

  • action (String)

    The url the form must be submitted to. Will be the value of its <action> attribute

  • fields (Hash)

    The key/value pairs of parameters to be sent as POST to the action. Will be a set of hidden <inputs> in the form.



35
36
37
38
# File 'lib/omnipay/autosubmit_form.rb', line 35

def initialize(action, fields)
  @action = action
  @fields = fields.map{|name, value| {:name => name, :value => value}}
end

Instance Method Details

#htmlString

Returns the full html page

Returns:

  • (String)


43
44
45
# File 'lib/omnipay/autosubmit_form.rb', line 43

def html
  HEADER + form_html + FOOTER
end