How to make SignUp/Login action in one form - asp.net-mvc

I working on my first ASP.net MVC project and and i got some problems using multiple buttons in one form.
When my user type username&password and then hit login means it will go to welcome page
if user try to Sign Up means it will go to another form field to get Personal information.
and finally all given information need to store in database and redirect user to welcome page .
#using (Html.BeginForm("about", "home", FormMethod.Post, new { #id = "msform" }))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary()
<!-- progressbar -->
<ul id="progressbar">
<li class="active"></li>
<li></li>
<li></li>
</ul>
<!-- fieldsets -->
<fieldset>
<h2 class="fs-title">Create your account</h2>
<h3 class="fs-subtitle">Take 60 Seconds With Us</h3>
<input type="text" name="UsersName" placeholder="Username" />
<input type="password" name="Passsword" placeholder="Password" />
<input type="button" name="next" class="next action-button" value="Sign Up" />
<input type="button" name="next" class="nexts action-login" value="Log In" />
<input type="submit" value="+" />
</fieldset>
<fieldset>
<h2 class="fs-title">Personal Information</h2>
<h3 class="fs-subtitle">We will never share</h3>
<input type="text" name="phone" placeholder="Email" />
<input type="text" name="phone" placeholder="Phone Number" />
<input type="text" name="date" placeholder="Date of Birth" />
<input type="text" name="gender" placeholder="Gender" />
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset>
<h2 class="fs-title">Make SomeOne Alive</h2>
<h3 class="fs-subtitle">A donor today! A hero tommorow!</h3>
<input type="text" name="fname" placeholder="Blood Group" />
<input type="text" name="lname" placeholder="Are You ?" />
<input type="text" name="phone" placeholder="State" />
<input type="text" name="phone" placeholder="City" />
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="submit" name="submit" class="action-button" value="Submit" />
</fieldset>
}
But now that I have a login button placed on my view form, I'm totally lost. I don't know how to make when user click login button means it will redirect ,if signUp means it will redirect to another form. How to implement the form

Give your button names, and then test for their existence in the posted data server-side. Only the one that is clicked will be there:
<button type="submit" name="_SignUp">Sign Up</button>
<button type="submit" name="_LogIn">Log In</button>
Then, in your action:
if (Request.Unvalidated["_SignUp"] != null)
{
// do sign up
}
if (Request.Unvalidated["_LogIn"] != null)
{
// do log in
}
Or, you can alternatively just divine the user's intention, by attempting to retrieve the user object to sign them in, and if you get no match, then doing the signup instead. However, that pretty much makes the buttons unimportant and could result in the user clicking "Sign Up" and actually being logged in, instead, or vice versa. It doesn't really matter, but it's better to manage user's expectations. If they think they don't have an account, but actually do, they might want to know that.

Related

Search box and asp-route

I have just added search box to an index view
<form asp-action="Index" asp-route-account="#Model.First().AccountId" method="get">
<div class="form-actions ">
<p>
<input id="searchStringId" type="text" name="searchString" value="#ViewData["currentFilter"]" />
<input type="submit" value="Search" class="btn btn-primary">
<a asp-action="Index" asp-route-account="#Model.First().AccountId">Back to Full List</a>
</p>
</div>
</form>
This gives me:
https://localhost:44377/MainUsers/Funds?searchString=aldi
But I need
https://localhost:44377/MainUsers/Funds?account=1&&searchString=aldi In other words I need the search string to also include the route id.
Any ideas?
I need the search string to also include the route id. Any ideas?
You can try to achieve the requirement by using a hidden input field as below.
<input name="account" type="hidden" value="#Model.First().AccountId" />
<input id="searchStringId" type="text" name="searchString" value="#ViewData["currentFilter"]" />
Test Result

Get method : form input not in url

I am doing my first ASP.NET mvc project, on the home page, Index.cshtml, I have a small form:
<form action="ChoixFormulaire" method="get">
<fieldset>
<label>NAS</label>
<input id="nas" type="text" placeholder="###"/>
<br />
<label>Date of birth</label>
<input id="date" type="text" placeholder="AAAA-MM-JJ"/>
<br />
<label>Employee number</label>
<input id="numEmployee" type="text" placeholder="######"/>
<br />
</fieldset>
<input type="submit" value="Soumettre" onclick="return VerifierFormulaire()" />
</form>
When the button is clicked, there is some verification made in the 'VerifierFormulaire()' method, which is defined in the same Index.cshtml file. Then the ChoixFormulaire.cshtml is displayed (called from the ChoixFormulaire() method in my HomeController, which returns View()).
I was expecting the form inputs to be in the URL as parameters. For example, If I enter '123' for NAS, '1989-01-01' for date of birth and '123456' for employee number, I am redirected to http://localhost:15778/Home/ChoixFormulaire? but I would expect to be redirected to http://localhost:15778/Home/ChoixFormulaire?nas=123&dateBirth=1989-01-01&numEmployee=123456
Try adding the name attribute:
<input id="nas" name="nas" />

Redirect to a specific site after login via spring security

I have coded a sign up page:
<div class="container">
<div class='fheader'>
<g:message code="springSecurity.login.header" />
</div>
<g:if test='${flash.message}'>
<div class='login_message'>
${flash.message}
</div>
</g:if>
<form action='${postUrl}' method='POST' id='loginForm'
class="form-signin" autocomplete='off'>
<h2 class="form-signin-heading">Please sign in</h2>
<input type='text' class="form-control" name='j_username'
id='username' placeholder="Username" /> <input type='password'
class="form-control" name='j_password' id='password'
placeholder="Password" />
<p id="remember_me_holder">
<input type='checkbox' class='checkbox'
name='${rememberMeParameter}' id='remember_me'
<g:if test='${hasCookie}'>checked='checked'</g:if> /> <label
class="checkbox" for='remember_me'><g:message
code="springSecurity.login.remember.me.label" /></label>
</p>
<!-- <label class="checkbox"> <input type="checkbox"
value="remember-me"> Remember me
</label> -->
<input class="btn btn-lg btn-primary btn-block" type='submit'
id="submit" value='${message(code: "springSecurity.login.button")}' />
</form>
</div>
<!-- /container -->
<script type='text/javascript'>
<!--
(function() {
document.forms['loginForm'].elements['j_username'].focus();
})();
// -->
</script>
Into the page I have integrated the spring-security-core:2.0-RC2 plugin.
However, when I start the server and try to log in with my created users I get nothing. No notification that it worked, no redirect.
In fact I just want to redirect to my main page mapped as "/"(view:"/index") in the URLMappings.groovy
How to change the redirect?
I really appreciate your answer!
In your config file:
grails.plugins.springsecurity.successHandler.defaultTargetUrl="/someController/someAction"

Jquery Mobile Dialog with Form

I have a JQuery Mobile dialog with a form on it:
<form action="send" method="post">
<input type="text"/>
<input type="submit" />
</form>
What I want is that when the form is submitted, I just want to close the dialog or go back to the previous page. How to do it with JQM.
Try adjust next sample to your solution:
<div data-role="popup" id="popupLogin" data-theme="a" class="ui-corner-all">
<form>
<div style="padding:10px 20px;">
<h3>Please sign in</h3>
<label for="un" class="ui-hidden-accessible">Username:</label>
<input type="text" name="user" id="un" value="" placeholder="username" data-theme="a" />
<label for="pw" class="ui-hidden-accessible">Password:</label>
<input type="password" name="pass" id="pw" value="" placeholder="password" data-theme="a" />
<button type="submit" data-theme="b">Sign in</button>
</div>
</form>
</div>

Accessing HTML tags in a RUBY Controller

I have the following code in my HTML.erb
<form>
<input id="do" type="hidden" value="0" />
<button type="submit" value="Next">SUBTRACT</button>
</form>
<form>
<input id="do" type="hidden" value="1" />
<button type="submit" value="Next" >ADD</button>
</form>
Now When I click the any of the 2 buttons, I want to check the value of the input id="do" inside my Ruby Controller. What would the syntax look like ?
This should optimally be separated into two actions in the controller where each of the forms would submit (using the action attribute).
<form action='add'>
<input id="do" type="hidden" value="0" />
<button type="submit" value="Next">SUBTRACT</button>
</form>
<form action='subtract'>
<input id="do" type="hidden" value="1" />
<button type="submit" value="Next" >ADD</button>
</form>
#in your controller
def add
# do the addition processing
end
def subtract
# do the subtraction processing
end
If you really need to implement them in 1 action, then you could use Rails params object.
You need to set the name attributes, the name attributes get sent to the controller in the params hash
<form>
<input id="do" name="subtract" type="hidden" value="0" />
<button type="submit" value="Next">SUBTRACT</button>
</form>
<form>
<input id="do" name="add" type="hidden" value="1" />
<button type="submit" value="Next" >ADD</button>
</form>
In the controller,
the params[:subtract] or params[:add] will have the value depending on subtract clicked or add clicked .

Resources