Laravel 5 can't capture form input - forms

EDIT I am not using resource controller but I believe my route is correct
I have a form on it called recordings I have the form like:
<form class="form-horizontal" role="form" method="POST" action="{{ url('/recordings/create') }}" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label class="col-md-4 control-label">Client Name</label>
<div class="col-md-6">
{!! Form::select('ClientName', $client_options, '', array('class' => 'form-control')) !!}
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">File</label>
<div class="col-md-6">
<input type="file" class="form-control" name="FileUpload">
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Submit
</button>
</div>
</div>
</form>
Then in my RecordingsController
public function store()
{
var_dump(Input::file('FileUpload'));
var_dump(Input::get('ClientName')) ;
}
My route:
Route::get('recordings/create', 'RecordingsController#create');
Route::post('recordings/create', 'RecordingsController#store');
Why is it the var_dump is null? I have a dropdown which has values in it and I already selected one. The other one is file input filed which I also selected already a file.

Try:
public function store(Request $request) {
$ClientName = $request->ClientName:
if ($this->request->hasFile('FileUpload'))
{
$files = $this->request->file('FileUpload');
....
Or simple use
dd($request);
Always a good idea here is to use Firebug - to check out which values are submitted to your script.

Works now. Problem is I am sending huge data in my post. So I did is changed the post_max_size in my php.ini. Weird though I am not getting error regarding that.

Related

Html Form inside another form not redirecting to the correct URL

I've the following form on JSP:
<form class="form-horizontal" style="margin-bottom: 24px">
<fieldset id="myFieldset" disabled>
<div class="form-group">
<label class="control-label col-sm-3" style="text-align: left">Created By</label>
<div class="col-sm-4">
<input class="form-control" type="text" name="created_by" value="${inputConfiguration.getCreatedBy()}" readonly/>
</div>
</div>
.
.
. few more divs of form-group
.
.
</fieldset>
<div class="form-group row">
<div class="col-sm-offset-4">
<form action="${pageContext.request.contextPath}/Configuration/EditConfiguration" method="GET">
<input type="hidden" name="marketplace" value="${param.marketplace}">
<input type="hidden" name="program" value="${param.program}">
<button class="btn btn-primary"> form_Edit </button>
</form>
</div>
<div class="col-sm-1">
<form action="${pageContext.request.contextPath}/Configuration/CopyConfiguration" method="GET">
<input type="hidden" name="marketplace" value="${param.marketplace}">
<input type="hidden" name="program" value="${param.program}">
<button class="btn btn-primary"> form_Copy to New </button>
</form>
</div>
</div>
</form>
However, the forms that are within the outer-form are not redirecting to the correct path on clicking their respective buttons. NOTE: the hidden input fields are just to pass them as url parameters to the paths mentioned in the action and nothing else. Can anyone suggest as to how to pass these as url params and how to make the nested forms work?

How can I return to a form after $request->validate() errors with the input data values showing?

I'm using this code below in a Laravel controller but on errors it doesn't keep the input data when it returns to the form.
public function store(Request $request)
{
$validatedData = $request->validate([
'name' => 'required',
'intro' => 'required|max:140|min:40',
]);
If the intro is too short it sends the user back to the form but with empty fields.
The blade looks like this
<form action="{{route('member.store')}}" id="form" role="form" data-toggle="validator" method="post">
<div class="form-group">
<input type="text" value="" class="form-control" id="name" name="name" placeholder="Name" required>
</div>
<div class="form-group">
<textarea class="form-control" id="intro" rows="2" name="intro" placeholder="A short 15-30 word intro" required></textarea>
</div>
</div>
</form>
Doesn't is come with a return to the form with the data input?
You should use old('input') in the value of the input.
For your code it should be like this:
<div class="form-group">
<input type="text" value="" class="form-control" id="name" name="name" placeholder="Name" value="{{ old('name') }}" required>
</div>
<div class="form-group">
<textarea class="form-control" id="intro" rows="2" name="intro" placeholder="A short 15-30 word intro" value="{{ old('intro') }}" required></textarea>
</div>

How to access to RESTController through a controller?

I am using Spring.
The method in my RESTController is this,
http://localhost:8080/delivery-api/training/submit. It is able to save hard code values into database.
This is part of my html form, it can be open up using this URL: http://localhost:8080/delivery-web/training/apply.
<form th:object="${applyForm}" class="form-horizontal" role="form" method="post" action="http://localhost:8080/delivery-api/training/submit" >
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1" > Country </label>
<div class="col-sm-9">
<input type="text" id="form-field-1" placeholder="Country"
class="col-xs-10 col-sm-7" th:field="*{country}" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1"> Fee </label>
<div class="col-sm-9">
<input type="text" id="form-field-1" th:field="*{Fee}" class="col-xs-10 col-sm-7" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1"> Start Date </label>
<div class="col-sm-9">
<input type="date" id="form-field-1" th:field="*{startDate}"
class="col-xs-10 col-sm-7" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1">End Date </label>
<div class="col-sm-9">
<input type="date" id="form-field-1" th:field="*{endDate}"
class="col-xs-10 col-sm-7" />
</div>
</div>
<br> <br>
<button class="btn btn-info" type="submit">
<i class="ace-icon fa fa-check bigger-110"></i> Submit
</button>
</div>
</div>
</form>
When I click on submit, it can be directed to http://localhost:8080/delivery-api/training/submit and insert the hard coded values into database, but it did not direct to my application-form.html page after that.
My controller
#PostMapping(value = "/apply")
public String apply(#Valid #ModelAttribute("applyForm") DeliveryApplicationForm applyForm, BindingResult errors, Model model) {
model.addAttribute("applyForm", applyForm);
return VIEW_PATH + "application-form";
}
I would like to render html page and also pass data from my form to RESTController method through a controller after I click on the submit button in my html page.
May I know how I can do it?

CodeIgniter function form_open() in Smarty template

I recently started working with the Smarty Template system in my CodeIgniter projects.
All works fine and I was able to echo strings and dates. But now I have a problem with the 'form_open()' function.
view_login.tpl
<form class="contact-form" action="login/process" method="post">
<div class="row">
<div class="form-group">
<label for="username">USERNAME</label>
<input type="text" class="form-control" id="username" placeholder="Enter username">
</div>
<div class="form-group">
<label for="password">PASSWORD</label>
<input type="password" class="form-control" id="password" placeholder="Enter Password">
</div>
<button type="submit" class="btn btn-flat flat-color">LOGIN</button>
<button type="button" class="btn btn-flat pull-right">Forgot your password?</button>
</div>
</form>
As soon as I replace the HTML tags the view doesn't load anymore. I need the form_open() because of the Cross Site Request Forgery (CSRF).
So far I've tried:
{ form_open('login/process') }
{ form url='login/process' }
{{ form_open('login/process') }}
{php} echo form_open('login/process'); {/php}
Anyone else had the same problem or knows how to fix this?
Without Smarty I never had problems with this.
Solved!
I autoloaded the form helper file.
$autoload['helper'] = array('url', 'form');
And then I used the following code:
{form_open('login/process')}
<div class="row">
<div class="form-group">
<label for="username">USERNAME</label>
<input type="text" class="form-control" id="username" placeholder="Enter username">
</div>
<div class="form-group">
<label for="password">PASSWORD</label>
<input type="password" class="form-control" id="password" placeholder="Enter Password">
</div>
<button type="submit" class="btn btn-flat flat-color">LOGIN</button>
<button type="button" class="btn btn-flat pull-right">Forgot your password?</button>
</div>
{form_close()}
Looking at the code given above, it does not seem that the reason why the error occurred was because of the not loading the helper functions, though that may be one of the reason.
I believe the error is mainly because you added spaces between the delimiters { and }.
The default value in Smarty for the right and left delimiters are { and } respectively. Meaning:
{form_open('')} // Ok!
{ form_open('') } // Not Ok!
So, if you would like to use the second version, you will have to change your smarty settings for the right and left delimiter:
$smarty->left_delimiter = '{ ';
$smarty->right_delimiter = ' }';
Also, when you tried
{php} echo form_open('login/process'); {/php}
I believe it did not work because you are using Smarty 3. The {php} tag is deprecated in Smarty 2 and removed in Smarty 3. If you still want to use the {php} tag, you would have to use SmartyBC.

Form submit from Bootstrap 3 and JSP get parameter

I'm new to Bootstrap. But I'm pretty familiar with HTML. The thing is I cannot get parameter values from JSP. The parameters are from HTML page with Bootstrap 3. Here're the code. I don't understand. If I make simple html only page, then I could get the parameters.
<form class="form-horizontal" method="POST" action="makeResv.jsp">
<div class="container">
<div class="row">
<div class="control-group col-md-5">
<label for="checkIn">date1</label>
<div id="date-container">
<div class="input-group date">
<input type="text" id="checkIn" class="form-control"><span
class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
</div>
</div>
<div class="control-group col-md-5">
<label for="checkOut">date2</label>
<div id="date-container">
<div class="input-group date">
<input type="text" id="checkOut" class="form-control"><span
class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
</div>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-success">search</button>
</div>
</div>
</div>
</form>
In a JSP page, I'm just doing the following.
String checkIn = request.getParameter("checkIn");
String checkOut = request.getParameter("checkOut");
out.println(checkIn + " " + checkOut);
What's wrong with the above HTML code with Bootstrap?? Please give me some advise. Thanks!!
BTW, I'm using datepicker JavaScript library, but I don't think that affect the results. I cannot add the library code here but it works great anyway.
https://github.com/eternicode/bootstrap-datepicker
Bootstrap is same as HTML. The problem you are having is because you do not have any name attribute defined in your input element. You define id but to access submited variables via POST (request.getParameter() function) you need to have name attribute defined:
Replace <input> lines like this:
<input type="text" name="checkIn" id="checkIn" class="form-control">
And
<input type="text" name="checkOut" id="checkOut" class="form-control"><