Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8420435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:53:12+00:00 2026-06-10T02:53:12+00:00

I have a footer template which has a input and submit for email subscription.

  • 0

I have a footer template which has a input and submit for email subscription. The footer is used by every page. When subscription succeeds, it will redirect back to current page. However, I found out I am passing a string value to indicate what current page is. What is the best way to have a footer template for Play 2.0 application?

footer.scala.html

@(page: String)
<div id="footer">
    <div class="input-append">
        <form action="@routes.ApplicationController.saveSubscription(page)"
                                method="post">
        <input type="text" name="emailAddress" placeholder="Your Email" />
        <input class="btn" type="submit" value="Subscribe" />
        </form>
    </div> <!-- /input-append -->  
</div> <!-- /footer -->

ApplicationController.java

public class ApplicationController extends Controller {
    public static Result saveSubscription(String page) {
        ..........
        flash("success", "success message");
        if (page.equals("page1")) {
            return redirect(routes.ApplicationController.page1());
        } else if (page.equals("page2")) {
            return redirect(routes.ApplicationController.page2());
        } 
    }
}

page1.scala.html

@main("Page 1") {
    <div>
    <p>page 1</p>
    </div>
    @footer("page1")
}

page2.scala.html

@main("Page 2") {
    <div>
    <p>page 2</p>
    </div>
    @footer("page2")
}

EDIT 1

I follow @virtualeyes but it seems the subscribe.js is never been called. Here is the New setup.

main.scala.html

<html>
    <head>
        <script type="text/javascript" src="@routes.Assets.at("javascripts/jquery.min.js")"></script>
    <script type="text/javascript" src="@routes.Assets.at("javascripts/vendor/jquery.validate.min.js")"></script>
    <script src="@routes.Assets.at("javascripts/main.js")" type="text/javascript"></script>
    <script src="@routes.Assets.at("javascripts/subscribe.js")" type="text/javascript"></script>

    </head>
    <body>
       @footer()
    </body>
</html>

footer.scala.html

<div id="footer">
    <div class="input-append">                  
      <form id="_form" action="@routes.ApplicationController.simpleSubscription()">
        <input type="text" name="emailAddress" placeholder="Your Email" />
        <input id="_process" class="btn" type="submit" value="Subscribe" />
      </form>
    </div> <!-- /input-append -->  
</div> <!-- /footer -->

routes

POST    /subscribe  controllers.ApplicationController.simpleSubscription()

Now I got his error:
Action not found
For request ‘GET /subscribe?emailAddress=fdsaf%40rte.com’

I am not sure if it is because method=”post” is removed. If I put it back, then the result will return but will redirect to /subscribe page. I also set a breakpoint at subscribe.js but it doesn’t seem to be called at all.

EDIT 2 – Working

after I changed a little bit for subscribe.coffee and get rid of main.coffee, now it’s working.

subscribe.coffee

$('#_process').click (e) ->
  e.preventDefault()

  isValid = $('#_form').validate().form()
  if isValid
    $('#_process').spin()
    $.ajax
      type: "POST"
      url:  $('#_form').attr('action')
      data: $('#_form').serialize()
      success: (data) ->
        $('#_status > div').removeClass('alert-error').addClass('alert-success')
        $('#_status > div').html( data )
        $('#_status').fadeIn()
        fade = () -> $('#_status').fadeOut('slow')
        setTimeout fade, 2000
        $('#_process').spin('stop')

      error: (data) ->
        $('#_status > div').removeClass('alert-success').addClass('alert-error')
        $('#_status > div').html( data.responseText )
        $('#_status').fadeIn()
        fade = () -> $('#_status').fadeOut('slow')
        setTimeout fade, 2000
        $('#_process').spin('stop')

      complete: () -> $('#_process').spin('stop')

footer.scala.html

 <div id="_status">
    <div class="alert alert-error"></div>
 </div>
 <div class="input-append">
    <form id="_form" action="@routes.ApplicationController.simpleSubscription">
       <input type="text" name="emailAddress" placeholder="Your Email" />
       <input id="_process" class="btn" type="submit" value="Subscribe" />
    </form>
    <div id="_spin"></div>
  </div> <!-- /input-append -->

The spin() function is from https://github.com/pshizzle/spin.coffee

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:53:13+00:00Added an answer on June 10, 2026 at 2:53 am

    AJAX is the way™

    //footer.scala.html
    <div id="footer">
      <div class="input-append">
        <form id="_form" action="@routes.ApplicationController.saveSubscription">
          <input type="text" name="emailAddress" placeholder="Your Email" />
          <input id="_process" class="btn" type="submit" value="Subscribe" />
          <img id="spinner" src="/assets/img/loader.gif" alt="loading..." />
        </form>
      </div>
    </div>
    
    <div id="status">
      <div class="alert alert-error"></div>
    </div>
    <style type="text/css">
      #spinner, #status { display: none; }
    </style>
    
    //ApplicationController.java
    public class ApplicationController extends Controller {
      public static Result saveSubscription() {
        // save subscription
        ...
        // pseudo code
        if(success) 
          Ok( i18n("subscription success").toJson() );
        else
          Conflict( i18n("subscription fail").toJson() );
      }
    }
    
    //main.coffee
    jQuery ->
      $.ajaxSetup
        type:     "POST"
        cache:    false
        dataType: "json"
    
      # prevent form submit on keypress
      $('form').find('input').keypress (e) -> e.preventDefault() if(e.which == 13)
    
      jParse = (data) -> 
        try jQuery.parseJSON(data)
        catch e
          data
    
      jText = (data) -> jParse(data.responseText)
    
      toSuccess = (msg) -> 
        $('#status > div').removeClass('alert-error').addClass('alert-success')
        $('#status > div').html( jParse(msg) )
        $('#status').fadeIn()
    
      toFail = (data) -> 
        $('#status > div').html( jText(data) )
        $('#status').fadeIn()
    
    //subscribe.coffee
    jQuery ->
      $('#_process').click (e) ->
        e.preventDefault()
    
        isValid = $('#_form').validate().form() // assumes jQuery validation plugin
        if isValid
          $('#spinner').show()
          $.ajax
            data: $('#_form').serialize()
            success: (msg) ->
              toSuccess(msg)
              fade = () -> $('#status').fadeOut('slow')
              setTimeout fade, 2000
    
            error: (data) -> toFail(data)
    
            complete: () -> $('#spinner').hide()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have a footer which will appear on every page of my web
I got a template which frames every page with a header and a footer.
I have a Telerik Grid which has a footer that needs to display column
I am trying to have a sticky header and footer on my template, which
In a framework template engine let's say we have files for header,body,footer and body
When creating templates I typically have 3 separate parts (header, body, footer) which I
I have a custom editor template for a vehicle part that is used in
I want to create a page, which I will be able to browse like
I have a gridview to which I have created an Insert Template in the
I have a function called get_header() which includes the header file in a template

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.