       beforeSubmit: (data) ->
         console.log "Sending these data to the server: #{$.param(data)}"
 
+  setFormStep($form)
+
   $form.bind "step_shown", (event, data) ->
+    setFormStep($form)
+
     if data.previousStep is data.firstStep
       console.log("Adding additional Ajax events")
       # adds additional Ajax events now that we have the update URL


  wizard_buttons = '<input type="reset" /><input type="submit" />'
  $fieldsets.find("div.buttons").html wizard_buttons

  $form.formwizard
    formPluginEnabled: true,

#= require vendor_js

updateForm = (form, metadata) ->
  setFormAction(form, metadata)
  setFormStep(form)

setFormAction = (form, metadata) ->
  $form = $(form)
  $form.attr("action", metadata.url)
  $form.attr("method", metadata.method)

setFormStep = (form) ->
  $form = $(form)
  $form.prepend(createStepInput($form))

createStepInput = (form) ->
  $form = $(form)
  step = $form.formwizard("state").currentStep
  console.log "Current form step: #{step}"
  """<input type="hidden" name="_ht_meta[step]" id="ht_step" value="#{step}" />"""

createAjaxEvents = (form, firstStep=true) ->
  $form = $(form)
