Getting the Form input value in Laravel - php

Are there other ways to get value of an <input> in laravel besides Input::get('name'); ?
Here is my route that tries and get the value
Route::get('delete_comment_action/{id}', function($id)/
{
$status_Id = Input::get('status_Id');
print_r($status_Id);
exit();
return Redirect::back();
});
here is the form that should have the data in it
<form action="" method="get">
<input type="hidden" name ="status_Id" value="{{$swagger->status_Id}}">
<button type="button" class="btn btn-danger">Delete</button>
</form>
Status_Id should at least equal 1, when i try using, but instead it just displays a blank page.
$variable = Input::get('status_Id');
print_r($variable);

your routes looks okay but change form submit tag instead link
Route::get('delete_comment_action/{id}', function($id){
$status_Id = Input::get('status_Id');
print_r($status_Id);
exit();
return Redirect::back();
});
In Form view change form action and replace anchor tag link with
submit button
<form action="{{{ url("delete_comment_action/$swagger->Id") }}}" method="get">
<input type="hidden" name ="status_Id" value="{{$swagger->status_Id}}">
<input type="submit" value="Delete">
</form>

You are trying to use same route twice. You can't use it. What you have to do is separate routes like the following
This route is to show view
Route::get('test', function() {
return View::make('example');
});
This route will handle when you submit your form
Route::get('newtest', function() {
dd(Input::all());
});
In your example.blade.php
<form action="" method="get">
<input type="text" name="hello">
<input type="submit" value="Submit">
</form>

Related

window.print function call after form validating form in php

I have a problem, i want to print a a div after form validating and then submitting. Issue is, when call print.window function in submit button, it display print window without validating form fields.
input type="submit" value="Submit" class="button" name="submit" onclick="window.print()">
while the div which to be print is in
if($_POST['submit'])
{
echo"print div here";
}
Please help.
Thanks
If you want to print something after form validating and then submitting, you are supposed to do it in client side.
You can do something like this:
<form name="myForm" action="action.php" onsubmit="return validateForm()" method="post">
Name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
Then, validate form like this and print.
<script>
function validateForm() {
// validate your form here
window.print();
}
</script>
Hope it helps.

need to do a query when button is pressed php

I want to so when a button is pressed on my page it runs a query in the database
View
<form method="POST" action="evcccontroller/query">
<input type="submit" name="nw_update" value="NW_Update"/>
</form>
Controller
public function query()
{
// load the index view
$this->load->view('querycheck');
}
querycheck.php
<?php
if(isset($_POST['nw_update']))
{
echo("You clicked button one!");
//and then execute a sql query here
}
else
{
echo" dhur";
}
An Error Was Encountered
The action you have requested is not allowed.
I think problem with your action attr of form try like
<form method="POST" action="<?php echo base_url(); ?>/evcccontroller/query">
<input type="submit" name="nw_update" value="NW_Update"/>
</form>
add base url to form action
action="<?php echo base_url(); ?>/evcccontroller/query"
Just try
<form method="POST" action="<?php echo site_url('evcccontroller/query')?>">
<input type="submit" name="nw_update" value="NW_Update"/>
</form>
code is looking fine. I think the form action url is wrong. try this:
<form method="POST" action="<?=base_url('index.php/evcccontroller/query')?>">
<input type="submit" name="nw_update" value="NW_Update"/>
</form>

Use form parameters in a route with Laravel 5

Imagine I have the following in my routes.php file:
Route::get('/test/{system}/{link}', function($system,$link)
{
return "test ok";
});
Then, I wanna access this route with a form from my view:
<form action="/" method="get">
<input type="text" name="system">
<input type="text" name="link">
<button type="submit">Go!</button>
<form>
What would be the best way to do that? I know I can do something like:
Route::get('/',function(){
$input = Request::only('link','system');
$url = 'test/'.$input['system'].'/'.$input['link'];
return redirect($url);
});
But I'm not sure if it's the correct way to achieve it.
Thanks in advance!
You could have js change the form action and then submit it. Your way is ok, but make sure to put it at the end of the routes file. I would actually have the form submit to some specific route (instead of / maybe /redirect-to or something) and from there redirect.
You can do this. I'm not sure if this is the best process.
In routes.php, do this:
Route::get('/form', function(){
return View::make('formview');
});
Route::get('/formaction', function(){
$link = Request::input('link');
$system = Request::input('system');
return "$link";
});
And in the view, as usual, the following:
<form method="get" action="formaction">
System: <input type="text" name="system" />
Link: <input type="text" name="link" />
<input type="submit" value="ok" />
</form>
The Request of Laravel does not depend on the verb used for the request.

Passing HTML Input Value To The Form Action in a New Window Using Javascript

Here is my javascript and php code.
js
function validate()
{
myform.submit();
}
php
<form action="http://myurl/" method="post" name="myform" target="_blank">
<input type="id" name="txtid" value="3">
<input type="button" value="Submit" onClick="validate()">
</form>
How can I pass the value of txtid to the form action so that my new window URL would have http://myurl/3. Any idea how to trick this?
Thank you..
Try this
function validate()
{
//grabs the value of txtid
txtid = $('#txtid').val();
//uses var to redirect to the correct URL
window.open(http://myurl/"+txtid);
}

check filename before posting using jquery/ php

I need jquery to check if my posted filename (up_image) is empty or not.
if it's empty i need a div tag to be shown and come with some kind of alert message.
if not, just do the
$("#submit").submit();
<form action="/profile/" method="post" enctype="multipart/form-data" id="submit">
<p>
<label for="up_image">image:</label>
<input type="file" name="up_image" id="up_image" />
</p>
Upload
</form>
$(function() {
$("#post_submit").click(function() {
var fil = $("#up_image");
if($.trim(fil.val()).length == 0) {
alert("Choose a file!");
fil.focus();
return false;
}
$("#submit").submit();
});
});
1: use a standard submit button to submit your form rather than a javascript-dependent link, for accessibility reasons, and to prevent brokenness if someone tries to right-click-open-in-new-window or other similar action on the link. If you want it to look like a link, you can still use a button, just apply some CSS to make it no longer look like a button.
2: use the form.onsubmit event to do validation rather than relying on a submit button click (forms can also be submitted by pressing enter, which may not always generate a button click)
<form id="uploadform" method="post" action="/profile/" enctype="multipart/form-data">
<p>
<label for="up_image">image:</label>
<input id="up_image" type="file" name="up_image" />
</p>
<p>
<input type="submit" value="Upload" />
</p>
</form>
<script type="text/javascript">
$('#uploadform').submit(function(e) {
if ($('#up_image').val()=='') {
alert('Please choose a file to upload.');
e.preventDefault();
}
});
</script>

Categories