I want to pass a variable but for that I need to create a form. But I am using JavaScript to open the next page (that is a block page)
but I want to pass the method="post" directly in the button and not in the form, because it does not recognise the code.
Here is an example:
<form action="" method="post">
<button onclick="document.getElementById('id144').style.display='block'" class="btn btn-warning">
Editar nome grupo
</button>
</form>
What I want:
<button //pass method = post here onclick="document.getElementById('id144').style.display='block'" class="btn btn-warning">
Editar nome grupo
</button>
<form action="" id="formname" method="post">
</form>
<button onclick="document.getElementById('formname').submit();document.getElementById('id144').style.display='block';" class="btn btn-warning">Editar nome grupo</button>
Set form id.
Related
I'm a bit confuse on this form behaviour, I can get the second form but the first form is null. Here is my form codes:
<div class="modal-body">
<form action="{{ route('payroll',$data->id) }}" method="get" id="duadua">
</form>
<form action="{{ route('payroll',$data->id) }}" method="get" id="payrollForm">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button id="payrollSubmit" type="button" class="btn btn-primary">
{{ __('Process') }}
</button>
</div>
<script type="text/javascript">
$('document').ready(function(){
$("#payrollSubmit").click(function(){
var isi = document.getElementById('payrollForm');
console.log(isi);
});
});
</script>
I can get value of second form like this:
Meanwhile when I change to call first form (duadua) it returs null, like this:
I have no Idea why only second form can be called, while first form returns null.
I am using modal window to post the the values to the controller .
<form action="<?php echo base_url();?>Users/sms/" id="form" method="post" class="form-horizontal" enctype="multipart/form-data">
buttons
<button type="button" id="custom" class="btn btn-warning" disabled="disabled">
Custom Msg
</button>
<button type="button" id="initial" class="btn btn-primary">
Initial
</button>
no response in my screen. i cannot able find the error. in popup window showing nothing. when i click the button no response. suggestion please
Type should be submit instead of button to post the data.
I'm currently having an issue with posting method directly on submit buttons. What I need to do is to put two submit buttons in the same form. I've searched a little and found the html "formaction" method. The problem is that on one page, it is working just fine, but not on the other page.
So, this down here is my code that works:
<form action="" method="POST">
{{ csrf_field() }}
<input type="hidden" name="id" value="$id">
<button type="submit" formaction="{{route('remove')}}">
<i class="fa fa-check-circle" aria-hidden="true"></i>
</button>
</form>
And that one don't:
<form method="POST">
{{csrf_field()}}
<input type="hidden" name="id" value="{{$q->id}}">
<button type="button" formaction="{{route('remove')}}">
<i class="fa fa-trash" aria-hidden="true" style="font-size: 20px; color: red;"></i>
</button>
</form>
Someone has any idea why that is happening? I'm searching for this for a while now, but I just found dead ends.
suggestion
add a name="" for each button, and use $_POST["name_of_submit"] to process the form submission. example
//1st button
<button type="submit" name="submit1" formaction="{{route('remove')}}">
//2nd button
<button type="submit" name="submit2" formaction="{{route('remove')}}">
if (isset($_POST['submit1'])){
//do something
}
if (isset($_POST['submit2'])){
//do something else
}
Here is my form :
<form action="{{ route('invoice.destroy' , $invoice->id)}}" method="DELETE">
<div class="modal-footer no-border">
<button type="button" class="btn btn-info" data-dismiss="modal">No</button>
<button type="submit" class="btn btn-primary">Yes</button>
<input type="hidden" name="_method" value="DELETE" />
</div>
</form>
Here is my controller :
public function destroy($id)
{
$invoice = Invoice::find($id);
if(!$invoice){
return redirect()->route('invoice.index')->with(['fail' => 'Page not found !']);
}
$invoice->delete();
return redirect()->route('invoice.index')->with(['success' => 'Invoice Deleted.']);
}
But it can not delete where is the problem ? How solve this ?
You need to use POST method for the form and add input element with name _method and value DELETE. Also, add token:
<form action="{{ route('invoice.destroy' , $invoice->id)}}" method="POST">
<input name="_method" type="hidden" value="DELETE">
{{ csrf_field() }}
<div class="modal-footer no-border">
<button type="button" class="btn btn-info" data-dismiss="modal">No</button>
<button type="submit" class="btn btn-primary">Yes</button>
</div>
</form>
I think you must add a hidden input to the form which will contain the method used:
<form action="{{ route('invoice.destroy' , $invoice->id)}}" method="POST">
<input type="hidden" name="_method" value="DELETE" />
</form>
Read more on Laravel documentation about Form method spoofing
In order to get PUT and DELETE methods to work, you need an additional field, since only POST and GET are possible within HTML (out-of-the-box).
The additional field will be made with the code:
{!! method_field('DELETE') !!}
So your form will look like this:
<form action="{{ route('invoice.destroy' , $invoice->id)}}" method="DELETE">
{!! method_field('DELETE') !!}
<div class="modal-footer no-border">
<button type="button" class="btn btn-info" data-dismiss="modal">No</button>
<button type="submit" class="btn btn-primary">Yes</button>
</div>
</form>
Also, if you are using blade templates, you can add the method field like so:
#method('DELETE')
More Laravel way you can do this
<form action="{{ route('invoice.destroy',$invoice->id)}}" method="POST">
#method('DELETE')
<button type="submit" class="btn btn-primary">Yes</button>
</form>
I have next html form:
<form class="form-horizontal" action="frames1.php" method="post">
<div class="form-group">
<label for="uri1" class="control-label">URL:</label>
<div class="controls">
<input type="text" id="uri1" placeholder="www.ejemplo.com">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
<input type="submit" class="btn btn-primary" id="submit" value="Visualizar" />
</div>
</form>
I want to pass the value from textbox "uri1" to a php variable.
Thats my frames1.php:
<?php
$uriValue = $_GET["uri1"];
?>
<script>
var uri = '<?php echo $uriValue;?>';
alert(uri);
</script>
But the system shows me "", not the value I put on the textbox in the form just before.
How can pass the value from the textbox to read on the php file?
Thanks!
You are using method as post in form co change this to
<?php
$uriValue = $_POST["uri1"];
?>
<script>
var uri = '<?php echo $uriValue;?>';
alert(uri);
</script>
and also add name attribute to your field. name="uri1"
that is,
<form class="form-horizontal" action="frames1.php" method="post">
<div class="form-group">
<label for="uri1" class="control-label">URL:</label>
<div class="controls">
<input type="text" id="uri1" name="uri1" placeholder="www.ejemplo.com">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
<input type="submit" class="btn btn-primary" id="submit" value="Visualizar" />
</div>
</form>
Here is the working link.
You send a form by POST but in your frames1.php file, you try to get the content with $_GET. So what you have to do is just change GETto POST, so it looks like
<?php
$uriValue = $_POST["uri1"];
?>
Also a bigger problem is, that your input doesn't have a name, the parameter can only be referenced by the name, not by the ID. So your input should look like that:
<input type="text" id="uri1" name="uri1" placeholder="www.ejemplo.com">
There are one mistake in HTML as well as PHP code, You have to give name to the input field's. When form is submitted to the server then It will recognize fetch values using HTML Input Field names, and If your posted form in HTML, then you have to use same method to get the values.
Try to replace bellow code with your code:
<form class="form-horizontal" action="frames1.php" method="post">
<div class="form-group">
<label for="uri1" class="control-label">URL:</label>
<div class="controls">
<input type="text" name="uri1" id="uri1" placeholder="www.ejemplo.com">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
<input type="submit" class="btn btn-primary" id="submit" value="Visualizar" />
</div>
</form>
Coming to your frames1.php:
<?php
$uriValue = $_POST["uri1"];
?>
<script>
var uri = '<?php echo $uriValue;?>';
alert(uri);
</script>
Let me know still not resolved.
Diff in HTML file is:
<input type="text" name="uri1" id="uri1" placeholder="www.ejemplo.com">
you didn't mention the name, then server will not recognize the element.
In PHP:
Your using POST method but your getting the values using _GET[], both are incompatible methods. So you will not get the values which are submitted by the form
<?php
$uriValue = $_POST["uri1"];
?>
You have set form method="post".
Therefore, after your form gets submitted, the value should be:
$uriValue = $_POST["uri1"];
Not
$uriValue = $_GET["uri1"];
Solutions:
1) Either change your form method method="post" to get your existing code working.
2) Change $uriValue = $_GET["uri1"]; to $uriValue = $_POST["uri1"];