i want to get the form data form one gsp and want to access that data in another gsp and want to insert that data in table, how can i do this? - grails

This is one gsp where i created one form
<div class="form-group">
<label for="msg_to">To</label>
<input type="email" id="msg_to" name="msg_to" class="form-control" style="width:500px;" required="">
</div>
<div class="form-group">
<label for="msg_subject">Subject</label>
<input type="text" id="msg_subject" class="form-control" style="width:500px;"name="msg_subject" required="" maxlength="50">
</div>
<div class="form-group">
<label for="msg_body">Body</label>
<textarea class="form-control" id="msg_body" style="width: 500px; height: 250px" name="msg_body" required="" ></textarea>
</div>
%{--<button type="submit" class="btn btn-default">Send</button>--}%
<g:actionSubmit value="Send" action="g_Inbox" style="color: #000000"></g:actionSubmit>
</form>
The data of above form must be access to another controller after submit and data should be display in the table form on that another view.
I fetch above data in following action:
def g_Inbox(){
def msg_to = params.msg_to;
def msg_subject = params.msg_subject;
def msg_body = params.msg_body;
println msg_to
println msg_subject
println msg_body
render(view: 'g_Inbox', model: [m_to : msg_to , m_sub : msg_subject , m_body: msg_body] )
}
from here i want to send it to view and want to add in new row of table..

You're in luck. What you want to do is very easy with Grails. But... you have to do your homework.
Things to read and digest
(best served with pizza and iced tea)
Groovy Server Pages -
https://grails.github.io/grails-doc/latest/guide/theWebLayer.html#gsp
Controllers - https://grails.github.io/grails-doc/latest/guide/theWebLayer.html#controllers
Once you understand GSP and controllers, you'll know exactly what to do.

Simple if You know how it works
render(view: 'g_Inbox', model:[params:params])
Access the params in gsp by
${params.msg_to}
and for Another Controller
redirect controller:'Controller' action: 'create',params:params

Related

How to temporary store in form data in .NET core

I am learning ASP.Net Core and I am creating a mock Flight booking app. On my home page, I have a search form to find a flight.
On submitting my form it goes to my SearchResultsController and then to my Search() action where I will run a search query.
What's the best way to pass the parameters through to this controller action for use in the Search() action method?
All the methods I've seen this far have involved creating new models but I don't want to save the searches to my database as it's not information that needs retaining. Having come to form a rails background I would use the parms hash which is a temporary data store.
Form:
<form asp-controller="SearchResults" asp-action="Search" method="post">
<div class="form-group">
<label for="fromAirport">Flying from:</label>
<select asp-for="AirportId" asp-items="#(new SelectList(ViewBag.ListOfAirports, "AirportId", "AirportCode"))" class="form-control">
</select>
<div class="form-group">
<label for="toAirport">Flying to:</label>
<select asp-for="AirportId" asp-items="#(new SelectList(ViewBag.ListOfAirports, "AirportId", "AirportCode"))" class="form-control">
</select>
</div>
<label for="fromAirport">Departure Date:</label>
<br />
<input type="date" />
<br />
<label for="fromAirport">No. passengers:</label>
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<button type="submit" class="btn btn-primary mt-3">Search Flights</button>
</div>
</form>

Login MVC redirect to another page

I have a log-in page. When the user hits the log-in button the button will calla another action method. that action method will have two parameter. the user provided userid and password. then it do some validation and redirect to another action method according to the outcome. I am struggling with there. i guess this is pretty simple. i am new to MVC. Any help would be appriciated.
View
<div class="container-fluid">
<div class="starter-template">
<h1>Policy Assessment Tool</h1>
<p class="lead">Are You Following Right?</p>
<button type="button" class="btn btn-primary btn-lg" onclick="location.href='#Url.Action("Create","UserDatas")'">Register for a An Account</button>
<h3><strong>OR</strong></h3>
</div>
<div class="row">
<form class="form-signin" role="form" method="post">
<div class="col-lg-4"></div>
<div class="col-lg-4">
<h2 class="form-signin-heading">Please Sign-In to Continue</h2>
<div class="input-group">
<input type="text" name="input_domain_id" class="form-control text-center" placeholder="Domain ID" autofocus required>
<input type="password" name="input_domain_password" class="form-control text-center" placeholder="Domain Password" required>
<div class="col-lg-12">
<p><button class="btn btn-lg btn-primary btn-block" type="submit" onclick="location.href='#Url.Action("Verify_Login", "Ldap_Login_Verify")'">Login</button></p>
</div>
</div><!-- /input-group -->
</div><!-- /.col-lg-4 -->
<div class="col-lg-4"></div>
</form>
</div><!-- /.row -->
</div>
Controller
[HttpPost]
public ActionResult Verify_Login(string input_domain_id, string input_domain_password)
//Log-in Logic
return View("Success")
Instead of using form tag use Html.BeginForm HtmlHelper and pass Model from Controller to View for the best practice. Here is link for you to get Getting Started With MVC5.
Based on the mark up above you need not worry about it, When the form is posted the values will get bound to the parameters of the action method, As the parameter names are similar to the form field names.
The above concept is called model binding. The below two links should give you a good idea on the same.
http://www.codeproject.com/Articles/710776/Introduction-to-ASP-NET-MVC-Model-Binding-An-Absol
http://dotnetslackers.com/articles/aspnet/Understanding-ASP-NET-MVC-Model-Binding.aspx
I have tried to compile a simple example below.
Lets assume there is a view like below.
#model string
#{
ViewBag.Title = "Injection";
}
<h2>Injection</h2>
#using(Html.BeginForm())
{
<div id="formDetails">
#Html.TextBox("UserName")
</div>
<div>
<input type="submit" id="btnTest" value="Click Me" />
</div>
}
The Action method for the same would be like
[HttpPost]
public ActionResult Injection(string UserName)
{
return View("Injection");
}
So when i click on the submit button, The form is posted , Since the ViewName is injection, and there is a corresponding action method called injection it will automatically hit that action method. Since the parameter name of the method and field is the same, What ever value is there in the username textbox will get automatically bound to the method parameter.

unable to display the validation messages from #Html.ValidationSummary() in MVC view

I have a fairly simple form created in a partial view and loading the form on a jquery dialog. The view is tightly bound to a model. When the user clicks on the submit button with out entering any inputs, I need to show the validation messages.
<div>
<form method="post" enctype="multipart/form-data" id="ssimForm" action="Home/ProcessUploadedFile"
onsubmit="return false;">
<div>
<h3>
Select the file to be uploaded :</h3>
<span>
<input type="file" name="UploadFileName" id="UploadFileName" /></span>
</div>
<div>
<h3>
Select the date range :</h3>
<span class="uslabel">From Date(MM/dd/yyyy): </span>
<input class="usdate" id="usfromdate" name="StartDate" type="date" />
<span class="uslabel">To Date(MM/dd/yyyy): </span>
<input class="usdate" id="ustodate" name="EndDate" type="date" />
</div>
<div>
<br />
<input type="submit" id="submitButton" name="submitButton" value="Process File" />
</div>
#Html.ValidationSummary()
<div class="message-success">
<span>#ViewBag.Confirmation</span>
</div>
<div class="message-error">
<span>#ViewBag.Error</span>
</div>
</form>
</div>
Now comes the actual problem. when I submit the form I am able to see the validationSummary object populated with the messages, but they are not getting rendered on the screen.
I am able to see the messages if I replace the content of the dialog with the response from the jquery ajax call, that fetches the entire view from the server side. I do not want to take this approach as I beleive this is not the correct way to return validation summary in MVC.
Am I missing something? Any help is appreciated.
I don't know why you don't have the #using (Html.BeginForm()) { } block.
Here is my blog post for a quick and easy way to set up Validation Summary + Unobtrusive Validation for MVC3+.
http://geekswithblogs.net/stun/archive/2011/01/28/aspnet-mvc-3-client-side-validation-summary-with-jquery-validation-unobtrusive-javascript.aspx

Create a search page in ActiveAdmin

I'm using ActiveAdmin to deploy my project. And I had some problem when I was developing.
I had some database table, e.g: "Worker", "Product", "Task". I wanted to create a page to search on those table with many situation.
I created a simple page:
ActiveAdmin.register_page "my page" do
content do
panel "Search details" do
panel "By Name" do
render :partial => "form"
end
end
end
end
And this is _form.html.erb
<form action="" method="post">
<input type="text" value="" name="taskid">Task ID</input>
<input type="text" value="" name="productid">Product ID</input>
<input type="text" value="" name="workerid">Worker ID</input>
<input type="submit" value="Submit"/>
</form>
But I don't know how can I call a controller from a form? (which controller was defined)
And How can I render or show the result to the content area of "my_page" in Activeadmin from a controller?
Anyone may help me? plz!
Design the form such that it uses the existing active admin filters and displays the results accordingly. You may want to look at the HTML of your filter forms (using firebug), in order to get the required params, and the submit action. Here is the partial which I use to search my User model (constructed from user filters):
<div class="panel_contents">
<form method="get" id="q_search" class="filter_form" action="/admin/users" accept-charset="UTF-8">
<div class="filter_form_field filter_string">
<label for="q_email" class=" label">Search User Email</label><br/>
<input type="text" name="q[email_contains]" id="q_email" />
<input type="submit" value="Go" name="commit" id="q_submit" />
</div>
</form>
</div>
and displays the result in the existing format. You don't need to design new views for that.

How to add a filter to Active Admin dashboard?

I want to add search functionality for a couple of my models on the Active Admin Dashboard page. How do I do that?
For a regular model I can do that using "filter", but how do I do that on Dashboard view. What are the methods available within section and ActiveAdmin::Dashboards.build?
Adding how I did it (following advice from Sjors), so that someone else may find it useful:
in dashboards.rb:
section "Search User", :priority => 4 do
div do
render "search_user"
end
end
in views/admin/dashboard/_search_user.html.erb (Copied HTML of the user filter using firebug):
<div class="panel_contents">
<form method="get" id="q_search" class="filter_form" action="/admin/users" accept-charset="UTF-8">
<div class="filter_form_field filter_string">
<label for="q_email" class=" label">Search Email:</label>
<input type="text" name="q[email_contains]" id="q_email" />
<input type="submit" value="Go" name="commit" id="q_submit" />
</div>
</form>
</div>

Resources