I am trying to get this button
<button type="submit" class="btn btn-default btn-block btn-lg" name='submit'>
Retrieve
</button>
in my Middleware and I want to verify if I'm pushing this button, this is my middleware:
public function handle($request, Closure $next){
$var = isset($_POST[$request->submit]);$other = ((bool) $var);
if (redirect('retrieve_money')) {
return redirect()->guest(route('home'));
} else if ($other) {
return redirect()->guest(route('retrieve_money.index'));
}
}
I don't know how to verify how to know if someone is pushing this button.
I am considering your form is GET.
Just have this inside your VerifyCsrfToken.php
$submit = $request->submit;
if (isset($submit)) {
echo $submit;
}
And then your button should be changed like
<input type="submit" class="btn btn-default btn-block btn-lg" >
Then if you click the submit then you should see the submit's value in the top of the page.
Tip :
You shall see the output directly by page's source by
view-source:http://localhost/yourproject/?submit=1221
Related
I have a Datatable with form inputs.
This is how I create it
public function getpurchasedata(Request $request)
{
if($request->get('orderID')){
$id = $request->orderID;
$orderNo = PurchaseOrder::find($id);
$order_items = PurchaseOrderItem::where('order_id',$orderNo->order_id)
->with('material')->get();
return DataTables::of($order_items)
->addColumn('name',function($order_items){
$name = $order_items->material;
return $name['name'];
})->addColumn ('expdate',function($order_items){
return '<input type ="date" id="expdate"
name="expdate" class="form-control">';
})->addColumn('action', function ($order_items) {
$buttons ='<button id="edit"
class="btn btn-info btn-sm">
<i class="far fa-edit"></i>
</button>
<button id="remove"
class="btn btn-danger btn-sm">
<i class="far fa-trash-alt"></i>
</button>';
return $buttons;
})->rawColumns(['expdate','action'])->make(true);
}
}
I use the following method to pass Data table values to the controller
grn_tableData:grn_table.data().toArray(),
but when i submit data using an ajax function i get html markups instead on input values for the expdate column. how can i get the real value ? explain me
You can add a hidden column next to your expdate column. Doing this, you can get the real value after form submission.
I want To Store the current user $emp->id from href , and use in the input value as like in my code that is written below. Is is possible? or if possible then please help me? and if this Question is not a big problem so i am sorry for that in advance.
<a href="{{'/employee'}}?id={{$emp->id}}" type="button" name="user_id" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Apply Attribute
</a>
<form action="{{'/rating'}}" method="post">
{{csrf_field()}}
<input type="hidden" name="user_id" value="{{store here current user}}">
</form>
Seems you just need paste your current user inside INPUT:
<form action="{{'/rating'}}" method="post">
{{csrf_field()}}
<input type="hidden" name="user_id" value="{{ $emp->id }}">
</form>
.....
If you want to use an id from a url you can :
Route::get('/url/{emp}', 'YourController#method');
In your controller:
public function method(Employee $emp) {
//Your code
return view('youre.view', compact('emp'))
}
Now in your view you have $emp and can acces id like $emp->id.
Offcourse name it what you want but be sure to name it the same in your route,controller and view.
Now you don't need a forEach loop, because of the binding you already have the employee from the url
p.s: Employee model is just an assumption..name it whatever your model is called.
You can use route function in blade for this.
Try this on web.php :
Route::get('/employee/{id}', 'YourController#YourMethod')->name('routename');
on your Controller your method need to have an arguments
public function YourMethod($id){
// Code here
}
And on your blade make your href with route
Link
Href Like That:
<a href="{{$emp->id}}" type="button" id="uu_id" class="btn btn-primary uu"
data-toggle="modal" data-target="#myModal"> Apply Attribute </a>
Using This Script To get Value from Href:
<script type="text/javascript">
$(document).ready(function() {
$(".uu").click(function(event) {
var u_id = $(this).attr('href');
event.preventDefault();
document.getElementById("hiddenVal").value = u_id;
});
});
</script>
And in your Form like this:
<form action="{{'/rating'}}" method="post">
{{csrf_field()}}
<input type="submit" style="margin-bottom: 10px;" class="btn btn-success
pull-right" name="apply" value="Apply"/>
<input type="hidden" name="hiddenVal" id="hiddenVal" />
</form>
And Last How to get this Value in the Controller And save to Database:
public function store(Request $request)
{
$rates = new Rating;
$user_id = $_POST['hiddenVal'];
$rates->user_id = $user_id;
$rates->save();
return redirect('/employee');
}
Here its my view i have 2 buttons one is save and exit and other is save and stay Here
View
<button type="submit" name="submit_1"> Submit and Exit</button>
<button type="submit" name="submit_2">save and stay Here</button>
Controller
public function store(Request $request)
{
$data['name'] = $request->input('name');
$data['adr'] = $request->input('adr');
$myuser = Data::create($data);
if(Input::get('submit_1')) {
return redirect()->route('myuser.index');
} elseif(Input::get('submit_2')) {
return redirect()->route('myuser.create');
}
}
I tried this but its not working for me kindly help me
you can try as:
<input type='submit' name='submit' value='submit_1'>
<input type='submit' name='submit' value='submit_2'>
Try this:
View
<button type="submit" name="submit_1" value="submit_1"> Submit and Exit</button>
<button type="submit" name="submit_2" value="submit_2">save and stay Here</button>
Controller
public function store(Request $request)
{
if($request->get('submit_1') == "submit_1") {
return redirect()->route('myuser.index');
} else if($request->get('submit_2') == "submit_2") {
return redirect()->route('myuser.create');
}
}
I am trying to load a page on click,
I created an email verification link which open the page and updates my Database all it works fine, but the page contains a button which i want to be clicked by user and open first page which have login window.
My verify.html:
<div class="container container-table">
<div class="row vertical-center-row">
<div class="text-center col-md-4 col-md-offset-4" style="background:blue">
<h3> Thankyou For Veryfing</h3>
<p>You Are Verified</p>
<form action="login.php/verify_to_login" method="post">
<button type="submit" class="btn btn-success" >Sign Up>Go To Login</button>
</form>
</div>
</div>
</div>
My Controller function which loads the verify page like this : http://localhost/index.php/login/verify/1567af19e10ce4
public function verify($VerificationCode){
$this->load->model('My_model');
$this->load->helper('url');
$this->My_model->verifymail($VerificationCode);
/* Send to the verification page */
$this->load->view("verify.html");
}
This is my verify_to_login() function which i want when i click on button it should open header.html, This should work like http://localhost/index.php/login/verify_to_login
but instead this it is showing http://localhost/index.php/login/verify/login.php/verify_to_login when i click on the button
public function verify_to_login(){
$this->load->view("header.html");
}
I am unable to understand why is this happening.?? :(
On html
<form method="" action="<?php echo base_url(); ?>controller_name/function_name">
<button id="submit-buttons" type="submit" >Submit 1</button>
</form>
And on Controller
function functionname(){
$this->load->view('some_view')
}
So basically your controller is fine, so just fix the button by putting the controller name and then the function name and all should work hopefully.
try
this
<button type="submit" class="btn btn-success" onclick="window.location.replace('YOUR_LINK_HERE');">Sign Up>Go To Login</button>
OR
<button type="submit" class="btn btn-success" onclick="window.location.href('YOUR_LINK_HERE');">Sign Up>Go To Login</button>
I have 4 buttons,and also an exportexcel button.I want to set the excel filename.If i clicked getToday button, i want to set the today date to the excel.
<div class="span3 btns_state">
<div data-toggle="buttons-radio" id="toggleButton" class="btn-group clearfix sepH_a">
<button type="button" name="getTday" id="getToday" class="btn btn-info rep_data tip-bottom active" data-original-title="<?php echo $today;?>"onclick = "show()">Today</button>
<button type="button" name="getWeek" id="getWeek" class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $this_week;?>"onclick = "show()">This Week</button>
<button type="button" name="getMonth" id="getMonth" class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $this_month;?>"onclick = "show()">This Month</button>
<button type="button" name="getPreMonth" id="getpremon"class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $previous_month;?>"onclick = "show()">Last Month</button>
</div>
</div>
My php code to get the dates.
$str = $_GET['getTday'];
if($str == 'getToday')
{
$var=$today;
}
else
{
$var=$this_week;
}
I want to retrieve the dates corresponding to the button i clicked,but only else part is working.
Here is the excel export.
saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), Report-<?php echo $var?>.xlsx");
You can use query string to pass the value of clicked button
refer the "Today" button below.
You can set the value of variable "$var" to your execel or anything.
[Note:I done in the same page,create "test.php" and paste the following code and try,it will works well]
Thank You.
<?php
//Assume Variables $today and $this_week like below
$today = date('Y-m-d');
$this_week = "This week";
$var = "";
if(isset($_GET['getTday'])):
$str = $_GET['getTday'];
if($str == 'getToday')
{
$var=$today;
}
else
{
$var=$this_week;
}
endif;
echo $var;
?>
<div class="span3 btns_state">
<div data-toggle="buttons-radio" id="toggleButton" class="btn-group clearfix sepH_a" >
<button type="button" name="getTday" id="getToday" class="btn btn-info rep_data tip-bottom active" data-original-title="<?php echo $today;?>"onclick = "show('getToday')">Today</button>
<button type="button" name="getWeek" id="getWeek" class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $this_week;?>"onclick = "show()">This Week</button>
<button type="button" name="getMonth" id="getMonth" class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $this_month;?>"onclick = "show()">This Month</button>
<button type="button" name="getPreMonth" id="getpremon"class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $previous_month;?>"onclick = "show()">Last Month</button>
</div>
</div>
<script>
function show(val)
{
if(val == 'getToday')
{
location.href = "test.php?getTday=getToday";
}
}
</script>
Make button type submit with form tag
<form>
<button type="submit" name="getTday">
and so on...
</form>
Then you will get in php like $_GET['getTday'] this will get name attr of field so keep id and name same
else you need to use jquery/js to get id of button
add value attribute in your button like this value="getToday".
You can get this in php file.
Example
<button type="button" name="getTday" id="getToday" value="getToday" class="btn btn-info rep_data tip-bottom active" data-original-title="<?php echo $today;?>"onclick = "show()">Today</button>
Using jquery click event to perform your action. You have to remove all click event inside html
$(".btn.btn-info.rep_data.tip-bottom").click(function(){
var name=$(this).attr("name");
// you can get what ever it is
// this.id;
// this.value
});
DEMO
NOTE: Dont write event in html it is not good practis