I'm using Laravel 5.6, and the following is my view (leads/show.blade.php):
<form method="post" id="student_form">
{{csrf_field()}}
<span id="form_output"></span>
<div class="form-group">
<label>Choose Group for Your Lead</label>
<select name="group_id" id="group_id" class="form-control">
#foreach($groups as $group)
<option value="{{$group->id}}"> {{$group->name}}</option>
#endforeach
</select>
<input type="hidden" name="customer_id" id="customer_id" value="{{$lead->id}}">
</div>
<div class="modal-footer">
<input type="hidden" name="student_id" id="student_id" value="" />
<input type="hidden" name="button_action" id="button_action" value="insert" />
<input type="submit" name="submit" id="action" value="Add" class="btn btn-info" />
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
and the route is :
Route::post('leads/savegroup', 'LeadsController#savegroup')->name('leads.savegroup');
Please help me to find the error in this route.
Add <form method="post" id="student_form" action="{{ url('/leads/savegroup') }}">
to your code.As you are posting data to empty route .You need to define some action.
Related
I tried to update a post using edit route but when I send the form and use the update function give me an error
my code is
<form action="/posts{{$posts->id}}" method="POST">
#method('PUT')
#csrf
<label for="">title</label>
<input type="text" name="title" class="form-control" >
<label for="">body</label>
<textarea type="text" name="body" class="form-control">{{$post->body}}</textarea>
<input type="submit" class="btn btn-primary" value="edit">
You have to use like this
<form action="{{url('')}}/posts/{{$post->id}}" method="POST">
#csrf
<label for="">title</label>
<input type="text" name="title" class="form-control" >
<label for="">body</label>
<textarea type="text" name="body" class="form-control">{{$post->body}}</textarea>
<input type="submit" class="btn btn-primary" value="edit">
And in your route use like this
Route::post('/posts/{id}', ...)
You are missing a / in your action
action="/posts/{{ $posts->id }}"
You could do the following :
<form action="{{ route('route.name', $post->id) }}" method="POST">
#csrf
<label for="">title</label>
<input type="text" name="title" class="form-control" >
<label for="">body</label>
<textarea type="text" name="body" class="form-control">{{$post->body}}</textarea>
<input type="submit" class="btn btn-primary" value="edit">
And for the route :
Route::post('/posts/{id}', 'Controller#function')->name('route.name');
I put a hidden method that I found on laravel documents and worked fine
<form action="/posts/{{$post->id}}" method="POST">
#csrf
<label for="">title</label>
<input type="text" name="title" class="form-control" >
<label for="">body</label>
<textarea type="text" name="body" class="form-control">{{$post->body}}.
</textarea>
<input type="submit" class="btn btn-primary" value="edit">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
I am a bit new to PHP and I'm having a bit of difficulties here and there. I am developing a form and wish to display an error box if any of the fields are empty when the 'Submit' Button is pressed. I've tried the following code but the echo is still not appearing. Any suggestions ?
Form Code:
<div style="padding-top:40px">
<div style="text-center; padding-right:25%; padding-left:25%">
<div class="form-area">
<form role="form" method="$_POST" action="searchEmployee.php">
<br style="clear:both">
<h3 style="margin-bottom:25px; text-align: center;">Visitor Form</h3>
<div class="form-group">
<label>Name:</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name" required>
</div>
<div class="form-group">
<label>Surname:</label>
<input type="text" class="form-control" id="surname" name="surname" placeholder="Surname" required>
</div>
<div class="form-group">
<label>ID Card:</label>
<input type="text" class="form-control" id="idCard" name="idCard" placeholder="ID Card No" required>
</div>
<div class="form-group">
<label>Visitor Card Number:</label>
<input type="text" class="form-control" id="cardNumber" name="cardNumber" placeholder="Card No" required>
</div>
<div class="form-group">
<intput type="button" id="submit" name="submit" class="btn btn-primary pull-right">Sign In Visitor</button>
</div>
</form>
</div>
</div>
</div>
PHP Code:
<?php
if (isset($_POST['submit'])) {
$required = array('name', 'surname', 'ID', 'visitorCard');
// Loop over field names, make sure each one exists and is not empty
$error = false;
foreach($required as $field) {
if (empty($_POST[$field])) {
$error = true;
}
}
if ($error) {
echo "All fields are required.";
}
}
?>
You are using method as $_POST in your form attribute,
It should be only POST.
So, replace your form line with,
<form role="form" method="POST" action="searchEmployee.php">
and also, change Submit button line to,
<input type="submit" name="submit" value="Sign In Visitor" class="btn btn-primary pull-right" />
Here are few mistakes:
You are using method as $_POST in your form attribute, It should be only POST.
Your form will not submit because your button is not a submit type. it should
<input type="submit" id="submit" name="submit" class="btn btn-primary pull-right" value="Sign In Visitor" />
Or
<button type="submit" id="submit" name="submit" class="btn btn-primary pull-right">Sign In Visitor</button>
You need to make 2 change as below
Change button type like this
<input type="submit" id="submit" name="submit" class="btn btn-primary pull-right" value="Sign In Visitor">
Change Form method
<form role="form" method="POST" action="searchEmployee.php">
Change this
<intput type="button" id="submit" name="submit" class="btn btn-primary pull-right">Sign In Visitor</button>
To
<input type="button" id="submit" name="submit" value="submit" class="btn btn-primary pull-right" />Sign In Visitor
and Also
this
<form role="form" method="$_POST" action="searchEmployee.php">
To
<form role="form" method="POST" action="searchEmployee.php">
How will you get POST['submit'] value when you have not even set, that means your if code won't execute it and so it won't echo or alert it.
For Best practice of debugging always try to do this whenever such instances occurs while coding.
print_r($_POST);
This will show you an array of POST variables
change $_POST to POST and put <input type="submit" instead of <input type = "button"
<div style="padding-top:40px">
<div style="text-center; padding-right:25%; padding-left:25%">
<div class="form-area">
<form role="form" method="post" action="searchEmployee.php"> <br style="clear:both"> <h3 style="margin-bottom:25px; text-align: center;">Visitor Form</h3> <div class="form-group"> <label>Name:</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name" required> </div>
<div class="form-group"> <label>Surname:</label>
<input type="text" class="form-control" id="surname" name="surname" placeholder="Surname" required> </div> <div class="form-group"> <label>ID Card:</label>
<input type="text" class="form-control" id="idCard" name="idCard" placeholder="ID Card No" required>
</div>
<div class="form-group">
<label>Visitor Card Number:</label> <input type="text" class="form-control" id="cardNumber" name="cardNumber" placeholder="Card No" required>
</div> <div class="form-group">
<input type="submit" id="submit" name="submit" class="btn btn-primary pull-right" value="Sign In Visitor">
</div> </form> </div>
</div> </div>
Php Code:::searchEmployee.php
<?php if (isset($_POST['submit'])) { $required = array('name', 'surname', 'idCard', 'cardNumber');
// Loop over field names, make sure each one exists and is not empty
$error = false;
foreach($required as $field) { if (!isset($_POST[$field])) {
$error = true;
} }
if ($error) {
echo "All fields are required."; } }
?>
First think change button type="submit".
Second think change PHP array
$required = array('name', 'surname', 'idCard', 'cardNumber');
I have two forms in my webpage, one with a field and a button and the other with two fields and a button.
I have a hard time checking which form's button is pressed, any advice is welcome on how to handle this.
<form class="form-inline" action="somewhere.php" method="post">
<div class="form-group">
<label for="date">Date:</label>
<input type="text" class="form-control" name="date" id="date" placeholder="abc">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<form class="form-inline" action="somewhere.php" method="post">
<div class="form-group">
<label for="date1">Date 1:</label>
<input type="text" class="form-control" name="date1" id="date1" placeholder="abc>
</div>
<div class="form-group">
<label for="date2">Date 2:</label>
<input type="text" class="form-control" name="date2" id="date2" placeholder="abc">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
And what is supposed to check what button is pressed.
$date = $_POST['date'];
$date1 = $_POST['date1'];
$date2 = $_POST['date2'];
if (!empty(date)) {
//do something
}
if (!empty($date1) && !empty($date2)) {
//do something else
}
First give name attribute in button.
<button type="submit" name="button1" class="btn btn-default">Submit</button>
<button type="submit" name="button2" class="btn btn-default">Submit</button>
now php side check which button is pressed:
if(isset($_POST['button1']){
//Do something.
}
else if(isset($_POST['button2'])
{
//Do something.
}
HTML
<button type="submit" name="btn1" class="btn btn-default">Submit</button>
<button type="submit" name="btn2" class="btn btn-default">Submit</button>
PHP
if(isset($_POST['btn1']){
//put code here.
}else{
//put code here.
}
I try to make a multi registration form in 2 steps.
And let work the buttons.
How do I hide step two until proceed step 1, than hide step 1.
<div class="user-register-field-1">
<form name="register" action="<?php echo osc_base_url(true); ?>" method="post">
<fieldset>
<input type="hidden" name="page" value="register" />
<input type="hidden" name="action" value="register_post" />
<button type="submit" class="small radius">
<?php _e("Continue Step 2", 'ctg_housing');?>
</button>
</fieldset>
</form>
</div>
<div class="user-register-field-2">
<form name="user-register-2" action="<?php echo osc_base_url(true); ?>" method="post">
<fieldset>
<input type="hidden" name="page" value="register" />
<input type="hidden" name="action" value="register_post" />
<button type="submit" class="small radius">
<?php _e("Create Account", 'ctg_housing');?>
</button>
</fieldset>
</form>
</div>
Thanks
Try this:
HTML:
<div class="user-register-field-1">
<form name="register" action="<?php echo osc_base_url(true); ?>" method="post">
<fieldset>
<input type="text" name="page" >
<input type="text" name="action" >
<button type="submit" class="small radius">
<?php _e("Continue Step 2", 'ctg_housing');?>
</button>
</fieldset>
</form>
</div>
<div class="user-register-field-2">
<form name="user-register-2" action="<?php echo osc_base_url(true); ?>" method="post">
<fieldset>
<input type="text" name="page">
<input type="text" name="action">
<button type="submit" class="small radius">
<?php _e("Create Account", 'ctg_housing');?>
</button>
</fieldset>
</form>
</div>
CSS:
.user-register-field-2{
display:none;
}
JS:
$(document).ready(function(){
$("div.user-register-field-1 form").on("submit", function(){
$("div.user-register-field-1").hide();
$("div.user-register-field-2").show();
});
});
Check also my Fiddle: https://jsfiddle.net/cz5kyaqL/
I hope I understood you right and could help
<form action="../includes/process_login.php" method="post" name="login_form">
<div class="form-group">
<label class="control-label">Username</label>
<input type="text" class="form-control" name="username" />
</div>
<div class="form-group">
<label class="control-label">Password</label>
<input type="password" class="form-control" name="password" />
</div>
<div class="text-center">
<input type="button"
value="Sign in"
class="btn btn-primary"
action="../includes/process_login.php"/>
</div>
</form>
Hello all, I have been following a tutorial and stumbled upon this error. Whenever I try to click the Sign-in button, it doesn't re-direct me. It is supposed to log me in.
Thank you in advance.
Remove the "action" from input and change its type to "submit".
<input type="submit" value="Sign in" class="btn btn-primary" />
This will submit the form to "../includes/process_login.php".
The correct syntax for button(submit) is as follows
<input type="submit" value="Submit">
Thus, your button should be changed as
<input type="submit" value="Sign in" class="btn btn-primary"/>
On clicking this submit button, the form is submitted to the page apecified in the attribute action of the <form>
Read more about it here