So i'm trying to save date from this form to my database using laravel but when I test it using print-r
it shows that the form doesn't send anything and I couldn't figure where the problem is ?
View
<form action="{{ route('auctioneer.save') }}" method="POST">
#csrf
<fieldset>
<div class="form-group" style="width: 35%; position: absolute; margin-left: 4%">
<fieldset>
<label class="control-label" for="readOnlyInput">Name</label>
<input class="form-control" id="readOnlyInput" type="text" value="{{ Auth::user()->name }}" readonly="" style="width: 100%">
</fieldset>
</div>
<div class="form-group" style="width: 35%;margin-left: 60%">
<fieldset>
<label class="control-label" for="readOnlyInput">email</label>
<input class="form-control" id="readOnlyInput" type="text" value="{{ Auth::user()->email }}" readonly="" style="width: 100%">
</fieldset>
</div>
<div class="form-group" style="width: 35%; position: absolute; margin-left: 4%">
<label for="entreprisepos">Position dans l'entreprise</label>
<input type="text" class="form-control" required id="entreprisePos" aria-describedby="aucti" placeholder="Commercial ...">
</div>
<div class="form-group" style="width: 35%;margin-left: 60%">
<label for="entrepriseNom">Nom du l'entreprise</label>
<input type="text" class="form-control" required id="entrepriseNom" aria-describedby="aucti" placeholder="Make it Happen ...">
</div>
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" id="termsChkbx " type="checkbox" value="" checked="" onchange="isChecked(this, 'sub1')">
I Agree on Terms and Conditions
</label>
</div>
<div class="form-group text-center">
<button type="submit" class="ps-btn" id="sub1" style="width: 20%;" value="Submit">
Submit Form
</button>
</div>
</fieldset>
</form>
Route
Route::post('/submitauct','AuctioneerController#save')->name('auctioneer.save');
Controller
public function save( Request $req){
print_r($req->input());
}
Display
Array ( [_token] => xNY3q1BvlxuT3zylwhtONx0Xv13qVPUhrrga8omo )
you miss the name attribute in tag your data is pass in request but doesnot get any name so you didint see the data
always remamber id is usefull when you work with frontend like js/jquery/css but when you want to work in backend you have to passs name attribute.
next mistake is always use not button when you want to submit form in laravel.
use button when you want to submit form using ajax or axios its good.
hint:in dd() token is print becuase when you use #csrf you get this.
it has by default name property so it shows
pleas if this is helpful vote up..................................................
If you want to send data from HTML form, you need use input attribute name.
<input name="foo" value="bar">
Then you can get the value in Laravel :
request()->input('foo');
Related
I have a basic HTML/PHP web form. Everything works fine when I fill out all fields, except I want to make the file upload optional, not required. I have taken "required" off of the form html for the upload. I checked my handler.php and it does not say that field is required. I checked the formhandler.php and it says that attachments are null. I have looked through similar questions, but any of the more complex solutions I am probably implementing incorrectly. I've expended my knowledge of php looking for a solution. What am I missing?
Here is the html of the form:
<div class="row pb6">
<div class="col-md-6 offset-md-3">
<form role="form" method="post" id="reused_form" enctype="multipart/form-data" >
<div class="form-group">
<label for="name"> Name:</label>
<input type="text" class="form-control" id="name" name="name" required maxlength="50">
</div>
<div class="form-group">
<label for="email"> Email:</label>
<input type="email" class="form-control" id="email" name="email" required maxlength="50">
</div>
<div class="form-group">
<label for="tel"> Phone: </label>
<input type="tel" class="form-control" id="tel" name="tel" maxlength="50">
</div>
<div class="form-group">
<label for="name"> Message:</label>
<textarea class="form-control" type="textarea" name="message" id="message" placeholder="We want to hear all about your performance! Also, please include the date you need the music." maxlength="6000" rows="7"></textarea>
</div>
<div class="form-group">
<label for="file">File Upload (optional)</label>
<input type="file" class="form-control" id="image" name="image">
</div>
<button type="submit" class="btn btn-lg btn-success pull-right" id="btnContactUs">Post It! →</button>
</form>
<div id="success_message" style="width:100%; height:100%; display:none; "> <h3>Sent your message successfully!</h3> </div>
<div id="error_message" style="width:100%; height:100%; display:none; "><h3>Error</h3>We are very sorry. There was an error sending your form. Email us and we will send you a free demo.</div>
</div>
</div>
</div>
And here is the handler.php:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
Tested working with PHP5.4 and above (including PHP 7 )
*/
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
$validator = $pp->getValidator();
$validator->fields(['name','email','tel'])->areRequired()->maxLength(50);
$validator->field('email')->isEmail();
$validator->field('message')->maxLength(6000);
if($_FILES['image']){ $pp->attachFiles(['image']); }
$pp->sendEmailTo('email'); //
echo $pp->process($_POST);
after code edit:
1)Chrome and Firefox will send form, Safari will not.
2)All browsers show a perpetual "Sending" message, and do not show a success or failure message for the form.
3) Forms send WITH attachments will not send the form with attachment to email, only the form alone.
You are trying to attach the image whether it exists or not with $pp->attachFiles(['image']);. You should first check if it does indeed exists and only attach it if it does like so:
if($_FILES['image']){
$pp->attachFiles(['image']);
}
When the checkbox "Fill with auth user info" is clicked I want to populate the fields with the auth user info (name and surname) but it's not working. When the checkboxes are clicked is not working the fields are not populated with the auth user info.
What I have for now is in, https://jsfiddle.net/LahL166o/2/ the auth user info appears in this span
<span id="userData" data-name="John"
data-surname="Keane"></span>
The issue should be how to get the ticket type name in the jquery with laravel because as it is ther is no id with "name" or "surname" the result ids are: "namegeneral_1" and "surnamegeneral_1".
laravel form:
<form method="post" id="step1" action="">
{{csrf_field()}}
#if (!empty($allParticipants))
#if($allParticipants == 1)
<p>Fill all fields.</p>
#foreach($selectedRtypes as $k => $selectedRtype)
#foreach(range(1,$selectedRtype['quantity']) as $val)
<h6 class="text-heading-blue mb-3 pb-2 font-weight-bold">Participant - {{$val}} - {{$k}} </h6>
#if ($loop->first)
<div class="form-check">
<input class="form-check-input" id="fill_auth_info" type="checkbox">
<label class="form-check-label d-flex align-items-center" for="exampleRadios1">
<span class="mr-auto">Fill with auth user info.</span>
</label>
</div>
#endif
<span id="userData" data-name="{{ auth()->user()->name }}"
data-surname="{{ auth()->user()->surname }}"></span>
<div class="form-group font-size-sm">
<label for="participant_name" class="text-gray">Name</label>
<input type="text" id="name" name="participant_name[]" required class="form-control" value="">
</div>
<div class="form-group font-size-sm">
<label for="participant_surname" class="text-gray">Surname</label>
<input type="text" id="surname" required class="form-control" name="participant_surname[]" value="">
</div>
#endforeach
#endforeach
#endif
#else
<p>Is not necessary additional info.</p>
#endif
<input type="submit" href="#step2free"
id="goToStep2Free" class="btn btn-primary btn float-right next-step" value="Go to step 2"/>
</form>
Html result:
<form method="post" id="step1form" action="">
<input type="hidden" name="_token" value="">
<h6 class="text-heading-blue mb-3 pb-2 font-weight-bold">Participant - 1 - general </h6>
<div class="form-check">
<input class="form-check-input" name="fill_with_auth_info" id="fill_auth_infogeneral_1"
data-id="general_1" type="checkbox">
<label class="form-check-label d-flex align-items-center"
for="fill_auth_info1">
<span class="mr-auto">Fill with auth user info.</span>
</label>
</div>
<span id="userData" data-name="John"
data-surname="Keane"></span>
<div class="form-group font-size-sm">
<label for="namegeral_1" class="text-gray">Name</label>
<input type="text" id="namegeral_1" name="participant_name[]" required class="form-control" value="">
</div>
<div class="form-group font-size-sm">
<label for="surnamegeneral_1" class="text-gray">Surname</label>
<input type="text" id="surnamegeneral_1" required class="form-control" name="participant_surname[]" value="">
</div>
<input type="hidden" name="all_participants" value="1" />
<input type="hidden" name="rtypes[]" value="1"/>
<h6 class="text-heading-blue mb-3 pb-2 font-weight-bold">Participant - 1 - re </h6>
<div class="form-check">
<input class="form-check-input" name="fill_with_auth_info" id="fill_auth_infore_1"
data-id="re_1" type="checkbox">
<label class="form-check-label d-flex align-items-center"
for="fill_auth_info1">
<span class="mr-auto">Fill with auth user info.</span>
</label>
</div>
<span id="userData" data-name="John"
data-surname="Keane"></span>
<div class="form-group font-size-sm">
<label for="namere_1" class="text-gray">Name</label>
<input type="text" id="namere_1" name="participant_name[]" required class="form-control" value="">
</div>
<div class="form-group font-size-sm">
<label for="surnamere_1" class="text-gray">Surname</label>
<input type="text" id="surnamere_1" required class="form-control" name="participant_surname[]" value="">
</div>
<input type="hidden" name="all_participants" value="1" />
<input type="hidden" name="rtypes[]" value="2"/>
<input type="submit" href="#step2free"
id="goToStep2Free" class="btn btn-primary btn float-right next-step" value="Go to step 2"/>
</form>
jQuery:
let userData = $('#userData');
$("input[name = 'fill_with_auth_info']").on('click', function(e) {
let checked = $(this).is(':checked');
if (checked) {
$('#name').val(userData.data('name'));
$('#surname').val(userData.data('surname'));
} else {
$('#name').val(userData.data(''));
$('#surname').val(userData.data(''));
}
});
I think you may have a number of issues that are preventing this from working. I think most are stemming from your looping and accidentally assigning the same id to many items.
However, the code displayed above is a bit confusing as well - the blade file should produce something different from the HTML you show. I assume this was a later iteration? I will speak to the blade file, as it is easier to see, since its smaller.
To help get this working, I suggest the following: First, you have only one user, so move this:
<span id="userData" data-name="{{ auth()->user()->name }}"
data-surname="{{ auth()->user()->surname }}"></span>
outside of the loop (or put it inside the $loop->first block), so that the #userData id is only assigned once in the DOM.
Next remove the singular id #name from the input. Same for the #surname. The way you have it, it keeps assigning multiple id fields with the same id. The name="participant_name[]" is fine, and will work on POST.
It's not clear if you want the user name & surname to populate ALL the input fields, or just one near the place he checks the box. If you want to populate them all, add a class to the two inputs in the loop like 'firstName' and 'surname'. Then its easy to populate everything with your jquery:
$('.firstName').val(userData.data('name'));
$('.surname').val(userData.data('surname'));
If, however, you wish to populate only the one that is checked, it is a little more complex (but not hard). You will need to have a check box within each loop next to the set of inputs. Easiest way to track the right checkbox against the input fields is to add an iterator into the loop (assign it and then iterate: $x ++) and then use this on the checkbox in a data field (eg data-count={{$x}} ) and now add an id onto the inputs like so:
id = 'name{{$x}}'
id = 'surname{{$x}}'
From here, add to your jquery code to check which box was checked by getting the count from the data-count field on the checkbox. Then, you can identify the right inputs to add the User's name into by id:
var count = $(this).data('count');
$('#name'+count).val(userData.data('name'));
$('#surname'+count).val(userData.data('surname'));
Hope this helps
So, I have my SPA at about 98% functional. The app pulls data from a MySQL database and allows the user to edit/delete records. For the page in question, it will edit/delete data of the specified student ID but it will not properly display the data in the text fields.
If you do not input a value it will display the first item in the JSON array but not the one you specify in the search field.
I did not do a very good job at explaining that but here is the HTML page that uses a function to pass data to the controller which then selects the corresponding student by ID and assigns it to the variable $scope.student. I then try to display the student data on the HTML page by using student.first_name (or any property) but it does not work correctly.
<h3>Edit/Delete Student with ID: {{student.student_id}}</h3>
<div class="form-group">
<label for="sid">Student ID:</label>
<input type="text" class="form-control" id="sid" ng-model="sid">
</div>
<p><button type="button" class="btn btn-primary" ng-click="getRecord(sid)">
Get Student Info </button> </p>
<div class='row'>
<div class="col-md-6">
<div class="form-group">
<label for="first_name">First Name:</label>
<input type="text" class="form-control" id="first_name" ng-model="student.first_name">
</div>
<div class="form-group">
<label for="last_name">Last Name:</label>
<input type="text" class="form-control" id="last_name" ng-model="student.last_name">
</div>
<div class="form-group">
<label for="hrs_completed">Hrs Completed:</label>
<input type="text" class="form-control" id="hrs_completed" ng-model= "student.hrs_completed">
</div>
<div class="form-group">
<label for="hrs_attempted">Hrs Attempted:</label>
<input type="text" class="form-control" id="hrs_attempted" ng-model= "student.hrs_attempted">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="gpa_points">GPA Points:</label>
<input type="text" class="form-control" id="gpa_points" ng-model= "student.gpa_points">
</div>
<div class="form-group">
<label for="major">Major:</label>
<input type="text" class="form-control" id="major" ng-model="student.major">
</div>
<div class="form-group">
<label for="advisor_id">Advisor ID:</label>
<input type="text" class="form-control" id="advisor_id" ng-model="student.advisor_id">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="text" class="form-control" id="email" ng-model="student.email">
</div>
</div>
<button type="button" class="btn btn-primary" ng-click="updateRecord()">Update</button>
<button type="button" class="btn btn-primary" ng-click="deleteRecord()">Delete</button>
And here is my controller on my Javascript page:
app.controller('editCtrl', function($scope, $http) {
$http.get("getStudentData.php")
.then(function (response) {
$scope.students = response.data;
});
$scope.getRecord = function(sid) {
id = sid;
$scope.student = $scope.students.find(s=>s.id == sid);
};
Do I need to make a seperate GET request to the server for this to work properly or do I just need to reference the student object differently?
I think there is mismatch in what you are getting as response.data and what you are trying to .find() and then what you are binding on html.
Check this plunkr.
You are trying to render by searching id property.
$scope.students.find(s=>s.id == sid);
where as you are rendering on UI using student_id property.
{{student.student_id}}
So, surely there is mismatch in what you are getting as response.data and what you are rendering using $scope.student properties. I think my plunkr will show that your function is correct.
In case this answer doesn't work, share your response.data.
Hello I work with WordPress , and I create a custom Modal with form to add a Group called 'abonnement' I added the table in Database and this is my issue:
Form
<form name="abonnementCreate" action="create.php" method="POST">
<div class="form-group">
<label>Nom de l'abonnemnt</label>
<input type="text" class="form-control" id="nomA" name="nomA">
</div>
<div class="form-group">
<label>Durée</label>
<input type="number" class="form-control" id="dureeA">
<small id="dureeHelp" class="form-text text-muted">En jours</small>
</div>
<div class="form-group">
<label>Nombre de produit autorisé</label>
<input type="number" class="form-control" id="nbProdA">
</div>
<div class="form-group">
<label>Frais d'abonnement (€)</label>
<input type="number" class="form-control" id="fraisA">
</div>
<button type="submit" name="create" class="btn btn-primary">Valider</button>
</form>
and this is the action of the creation :
create.php
<?php
include'admin.php';
global $wpdb;
if(isset( $_POST["create"]))
{
$wpdb->insert('abonnement', array(
'nom' => '.$_POST["nomA"].',
'duree' => '.$_POST["dureeA"].',
'nbProd' => '.$_POST["nbProdA"].',
'frais' => '.$_POST["fraisA"].'
));
}
?>
I have $_POST["create"] and the condition is true but $_POST[" any field"] is always null,
Someone please can help me ?
you can never catch the post value from id of the form input field.only way that you can get value using $_POST[] is using the "name" attribute of the input field.
<input type="text" class="form-control" id="nomA" name="name1">
this input field value can be accessed from form action php file using $_POST["name1"]
I'm a newbie programmer trying to utilize Twitter Bootstrap to build out a concept. I'm using PHP and assigning actions within HTML tags to POST data and essentially take a user through the navigation. This has been pretty straightforward when using forms: i.e. here is a snippet that does work. For example, for this snippet of HTML:
<form action="?viewnotes" method="post">
<input type="hidden" name="id" value="<?php htmlout($note['id']); ?>">
</form>
It successfully triggers the following if statement in my index.php:
if (isset($_GET['viewnotes']))
However, I'm trying to do the same thing in my registration page, using a Twitter Bootstrap class for buttons. Here is the HTML:
<a class="btn btn-primary btn-large" action="?register">Sign Up Free!»</a></p>
The PHP code is:
if (isset($_GET['register']))
{
include 'register.html.php';
}
Clicking on the Sign Up button is not invoking the PHP code. If I hard code the URL it works, but then I have a similar issue on the register.html.php page. HTML on the register page has:
<form class="form-horizontal" action="?storeuser" method="post">
<fieldset>
<legend>It's quick and easy...</legend>
<div class="control-group">
<label class="control-label">First Name</label>
<div class="controls">
<input type="text" name="fname" class="input-xlarge" id="fname">
</div>
</div>
<div class="control-group">
<label class="control-label" name="lname">Last Name</label>
<div class="controls">
<input type="text" name="lname" class="input-xlarge" id="lname">
</div>
</div>
<div class="control-group">
<label class="control-label" name="email">Email Address</label>
<div class="controls">
<input type="text" name="email" class="input-xlarge" id="email">
</div>
</div>
<div class="control-group">
<label class="control-label" name="password">Password</label>
<div class="controls">
<input type="password" name="password" class="input-xlarge" id="password">
</div>
</div>
</fieldset>
<button type="submit" name="action" class="btn btn-primary btn-large">Complete Registration</button>
</form>
However, when clicking on the button, the index file does not trigger the following, which would store the fields into the DB.
if (isset($_GET['storeuser']))
If I hardcode the URL to register.html.php, then the resulting URL looks like localhost/register.html.php?storeuser instead of localhost/?storeuser. I'm not sure if that's affecting the behavior here.
Thank you for the help!
I think you're approaching this the wrong way, and it's not Twitter Bootstrap's fault.
Usually, you'd use POST, not GET, to handle user registrations. Your form would look like this:
<form action="register.php" method="post">
<!-- your form -->
<fieldset>
<input type="submit" name="register" value="Register" class="btn btn-primary" />
</fieldset>
</form>
You can then build register.php as follows:
<?php
if (isset($_POST['register'])) {
// handle user registration
}
// display form
?>
This will display the form when the user visits register.php, but will try and process the user registration first if the form's been POSTed.
try passing a value with your GET variable
<form action="?viewnotes=1" method="post">