0
votes

The project i am working in allows logged in users to add a image to their profile by adding the image through a form. I was wondering if i could get the username automatically passed so the user doesn't have to type in his username when adding a image. I would like to get rid of the first input text box by making the site add it automatically. I know i can access it with @{session.get("displayName")} but don't know how to pass it with the form.

@main("addimage")  {
@helper.form(action = routes.Images.processImageForm) {  <!--  <----------**************************----------------->
    <fieldset>
        <legend>Add My Picture</legend>


        @inputText(
            addImageForm("creatorUsername"),
            '_label -> "Add Name",
            '_help -> "Please enter your display name",
            '_error -> addImageForm.globalError
        )

        @inputText(
            addImageForm("url"),
            '_label -> "Add Image",
            '_help -> "Please add your image-url",
            '_error -> addImageForm.globalError
        )

        @inputText(
            addImageForm("description"),
            '_label -> "Add Description",
            '_help -> "Please enter your Description",
            '_error -> addImageForm.globalError
        )


    </fieldset>




    <div class="actions">
        <input type="submit" class="btn primary" value="Add Image">
        <a href="@routes.Application.index" class="btn">Cancel</a>
    </div> }
1

1 Answers

1
votes

As your users are logged in you can use session to identify them, play is using cookie to store session relates information, your session should contains some identifier which identifies the user, in controller just get this identifier from the session and base on it for examaple you can retrieve use from DB, no need to send username in the form :

def formHandling =  Action { implicit request =>
        val userId = request.session.get(userSession)
        // handling form

      }