문제

I am trying to make a form in play framework which has a email field already defined,for this i have set a value in session. I just want to set attributes placeholder and value in my input email field through this session ,i am doing this

@(userForm: Form[models.User] )

@import helper._
@import helper.twitterBootstrap._


@main(Html("Create")) {


<fieldset>
    <legend>Add a new User</legend>

   @form(action = routes.ShopController.submit(), 'id -> "shopCreationForm", 'class -> "form-horizontal", 'role->"form") {

    <div class="form-group"><label>Name:</label><input type=text class="form-control" label="Shop Name"></div>

    <div class="form-group"><label>Email:</label><input type=text class="form-control" label="Email" placeholder=@session.get("email") value=@session.get("email") readonly></div>




 <div class="form-group">
    <div class="actions">
        <input type="submit" class="btn btn-primary" value="Create">
        <a href="@routes.ApplicationController.index" class="btn">Cancel</a>
    </div>
</div>

</fieldset>
        }
        }

but it doesnt showing the email of a person set in email session field value. I tried to google it out but unable to get anything Any help would be appreciated

도움이 되었습니까?

해결책

Just create a... new User object and set required values WITHOUT saving it to DB in the controller (pseudo code!):

User user = new User();
user.email = session("email");
Form<User> userForm = Form.form(User.class);
return ok(newUserView.render(userForm.fill(user));

Benefit: using this approach + several conditions in the view you can use single view for creating/editing users.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top