i have two views, view-1 and view-2.
view-1 has form, which will store data temporary.
i want to get data from view-1 and send it to view-2, which has user profile, where temporary data from view-1 will be shown.
how we can achieve it in Laravel, i know we can store data in SQL
and then fetch it, but how to do it without storing to SQL.
my code:
view: 1
<form >
<div class="form-group">
<label class="col-form-label" >Date</label>
<input type="text" name="sdate" class="form-control">
<input type="submit" class="btn btn-primary" value="Add date" >
</div>
</form>
view 2 Controller:
public function report2($id)
{
$teacher = Teacher::teacher($id);
return View('teachers.report2' ,compact('teacher','today','sdate'));
}
Route:
Route::get('teachers/{id}/report2', 'TeachersController#report2');
Use session, for example in view1 you pass variable of date do this on your controller of view 1
session(['sdate' => $request->sdate]);
and then you can get the value of the session in your controller or view by calling this
$date = session('sdate');
further reading see the docs
i was able to do it using simple php;
in view 1 i added this code:
<form action="report2" method="get">
Date: <input type="text" name="today" placeholder="Date of Birth" class="datepicker form-control"><br>
<input type="submit">
</form>
Laravel view 2:
<?php echo $_GET["today"]; ?><br>
Related
I'm trying to get the id of the selected subscription and pass it to the controller, but for some reason when I dd() or print_r() the id in the controller, it returns the same id regardless of which subscription I click.
Regardless if i click the first '+' button or the second one it always returns the same id when I print_r() it.
Array ( [_token] => iFimNDCv0q4rq7OmmUWGN8SGr2Bq0brsiRMLIzBD [subscription] => 2 )
Even when I click the first one, which should have '1' as the id, it still returns '2'.
This is my route for it in web.php
Route::post('/transaction/store', 'TransactionController#store')->name('transaction.store');
This is the function in the controller
public function store(Request $request)
{
// continue here
print_r($request->input());
}
And this is the form tag that's responsible for send the id (which is inside a foreach statement in blade)
<form id="batch" action="{{route('transaction.store')}}" method="POST">
#csrf
<input type="hidden" name="subscription" value="{{$subscription->id}}" form="batch">
<button type="submit" class="btn btn-sm btn-outline-dark" form="batch">+</button>
</form>
Thanks very much for any help!
I just had to make the form id dynamic!
<form id="batch-{{$subscription->id}}" action="{{route('transaction.store')}}" method="POST">
#csrf
<input type="hidden" name="subscription" value="{{$subscription->id}}" form="batch-{{$subscription->id}}">
<button type="submit" class="btn btn-sm btn-outline-dark" form="batch-{{$subscription->id}}">+</button>
</form>
I am trying to give the user to select the date he wants, and it will display the reservations for the day he selected. I am using Codeigniter, the MVC framework.
How am I setting a default value of the current date for an input date selection?
How am I sending the value to the controller and then I am using it for a function in the model.
<form id="form_reDate" name="form_reDate" method="POST" action="form_reDate.php">
<?php $r_date=#date('d-m-y'); ?>
<label for="reservations">Display reservations for :
<input type="date" id="date" name="re_date" style="margin-left: 0;"
min="2020-01-01" max="2020-12-31" value="<?php $r_date?>">
</label>
</form>
Controller:
public function form_reDate(){
$newDate = date("Y-m-d",strtotime($this->input->post('re_date')));
$data['tables'] = $this->Hosting_model->get_tables($newDate);
}
If you're using the default html of input type="date" to set its value you only use this php code.
<?php echo date('Y-m-d') ?>
to sum it:
<input type="date" id="date" name="re_date" style="margin-left: 0;"
min="2020-01-01" max="2020-12-31" value="<?php echo date('Y-m-d') ?>">
and for question #2 on how to send your input value to your Controller. Just make sure you get the data before sending it to your Model.
I'm using Spring+Thymeleaf to see and modify the users in a database. I would like to set the input fields to the actual values of an original user but I've tried with different styles and it doesn't work.
With the present configuration I can update information of users and see the id of original user (it's not in a input field) but I can't show the actual configuration in input field as default.
CONTROLLER:
#GetMapping(value = {"/", ""})
public String subusersPage(HttpSession session, Model model) {
String idUser = BaseController.getLoggedUser(session);
UserDTO userDTO = userService.getUserById(idUser);
model.addAttribute("subusersDTO", userService.getSubusersDTO(userDTO.getSubusers()));
model.addAttribute("populations", userDTO.getPopulations());
model.addAttribute("configurations", userDTO.getConfigurations());
model.addAttribute("attributes", userDTO.getAttributes());
model.addAttribute("subuserDTO", new SubuserDTO());
return "subusers";
}
HTML:
<th:block th:each="subuserDTO_original : ${subusersDTO}">
<hr>
<form action="#" th:action="#{/subusers/__${subuserDTO_original.id}__}" th:object="${subuserDTO}" method="post">
<div>
<p th:text="${'Id: ' + subuserDTO_original.id}"></p>
<p>Name: <input type="text" th:field="*{name}" th:name="name" th:value="${subuserDTO_original.name}"/></p>
<p>Population: <input type="text" th:field="*{population}" th:name="population" th:value="${subuserDTO_original.population}"/></p>
<p>Configuration: <input type="text" th:field="*{configuration}" th:name="configuration" th:value="${subuserDTO_original.configuration}"/></p>
<p>Attributes: <input type="text" th:field="*{attributes}" th:name="attributes" th:value="${subuserDTO_original.attributes}"/></p>
<p>
<button type="submit" th:name="action" th:value="update">Update</button>
<button type="submit" th:name="action" th:value="delete">Delete</button>
<button type="reset" th:name="action" th:value="clear">Clear</button>
</p>
</div>
</form>
<form action="#" th:action="#{/subusers/__${subuserDTO_original.id}__}" method="get">
<button type="submit">Default</button>
</form>
</th:block>
Any help will be very appreciated, thank you!
If you want to edit an existing user, then your th:object (which is ${subuserDTO} in this case) needs to be populated with the values of the original user. This is because when you use the attribute th:field="*{name}", it actually overwrites the name, id, and value of the html tag (which is why th:value="${subuserDTO_original.name}" isn't working.
Two other options you could do:
You could also set name="name" and use th:value instead.
Or another option, you could use ${subuserDTO_original} as your th:object.
I want to parsing my label name="predictDataTemp" in form into my controller, I already set the value form my label, but when I want to request the data still null
content.blade.php
<div class="form-group" align="center">
<label for="exampleResult" name="result">Result</label>
<label for="examplePredict" id="predictData" class="form-control">
<input type="hidden" name="predictDataTemp">
</label>
</div>
controller
public function result(Request $request){
$this->validate($request,[
'mCalories'=>'required',
'mCholesterol'=>'required',
'mFat'=>'required',
'mProtein'=>'required',
'mSugars'=>'required'
]);
$item= array();
array_push($item,array('Calories'=>$request->mCalories,'Cholesterol'=>$request->mCholesterol,'Fat'=>$request->mFat,'Protein'=>$request->mProtein,'Sugars'=>$request->mSugars,'Predict'=>$request->predictDataTemp));
return json_encode($item);
}
Your input has no value.
If you want to give it a value with jQuery (looking at your previous comments)
Give the input an id
<input type="hidden" name="predictDataTemp" id="predictDataTemp">
Then assign it in jQuery
$('#predictDataTemp').val('pass value here');
label don't have name attribute, it has only two attribute for and form so you can pass value in hidden input tag, Read this article
Instead
<label type="text" for="examplePredict" id="predictData" name="predictDataTemp" class="form-control"></label>
Use this
<label type="text" for="examplePredict" class="form-control"></label>
<input type="hidden" name="predictDataTemp" id="predictData" value="something">
i wanna ask something about codeigniter
here is the view
<input class="mws-textinput" name="div_id" type="text" readonly="readonly">
<input class="mws-textinput" name="div_name" type="text" readonly="readonly">
<input id="mws-jui-dialog-mdl-btn" class="mws-button blue small" type="button" value="Show Modal Dialog">
<div id="mws-jui-dialog">
<p><? (**i wanna call the function here**) ?></p>
</div>
here is the function in controller
function dialog(){
$query = mysql_query('select * from tbl_divisi');
while($isi=mysql_fetch_array($query)){
echo '';
}
}
what should i do?
There is two way either you can define this method in model and then call the method of that model in your view file or you can fetch all these values from controller. Here is the detail of how to use model in ci. http://ellislab.com/codeigniter/user-guide/general/models.html