Laravel get method doesnt work like i wanted - php

i am trying to add data from form with get method but when i submit it, datas doesnt show up in the url like this
addcustomers_token=vkmH0qnA6g2mfVcQzYUU3ZE0ZQvkQYs4DuCtKteX&company_name=Hebert+Frank+Inc&customer_name=Beau+Nixon&customer_surname=Schneider&customer_phone1=19655489736&customer_phone2=16612429699&customer_phone3=14871428281&customer_email1=qycuhuva%40mailinator.com&customer_score=2&customer_job=Doloribus+facilis+no&customer_gender=Woman&customer_source=Tawk+Canlı+Destek&user_id=1&user_company_id=1&tag_id=1&company_id=1
but its shows like that
/addcustomers
my controller
public function store(Request $req)
{
//
// Form validation (Zorunlu Alanlar)
$this->validate(request(), [
'customer_phone1' => 'required',
]);
$customers = new Customers;
$customers->customer_name = $req->input('customer_name');
$customers->customer_surname = $req->input('customer_surname');
$customers->customer_phone1 = $req->input('customer_phone1');
$customers->customer_phone2 = $req->input('customer_phone2');
$customers->customer_phone3 = $req->input('customer_phone3');
$customers->customer_email1 = $req->input('customer_email1');
$customers->customer_score = $req->input('customer_score');
$customers->customer_job = $req->input('customer_job');
$customers->customer_gender = $req->input('customer_gender');
$customers->customer_source = $req->input('customer_source');
$customers->customer_ref = "";
$customers->company_id = $req->input('company_id');
$customers->user_company_id = $req->input('user_company_id');
$customers->user_id = $req->input('user_id');
$customers->tag_id = $req->input('tag_id');
if(!empty($req->company_name)){
$companies = new Companies;
$companies->company_name = $req->input('company_name');
$companies->company_type = "";
$companies->company_address = "";
$companies->company_country = "";
$companies->company_city = "";
$companies->company_phone = "";
$companies->company_email = "";
$companies->company_tax_office = "";
$companies->company_tax_no = "";
$companies->company_website = "";
$companies->company_score = "";
$companies->company_status = "";
$companies->user_company_id = "1";
$companies->user_id = $req->input('user_id');
$companies->tag_id = "1";
$companies->updateTimestamps();
$companies->save();}
$customers->updateTimestamps();
$customers->save();
return redirect()->back()->with('success', true);
}
related routes
Route::get('/addcustomers', function () {
$companies = App\Models\Companies::all();
return view('addcustomers' , compact('companies'));
});
Route::get('/addcustomers2', [App\Http\Controllers\CustomersController::class, 'store']);
my form
<form action="/add-customers2" method="GET">
#csrf
<div class="row">
<div class="col-md-12 mb-4">
<label> <strong> Company Name </strong></label>
<input type="text" name="company_name" class="form-control" placeholder="Company Name">
</div>
<div class="col-md-6 mb-4">
<label> <strong> Customer Name </strong></label>
<input type="text" name="customer_name" class="form-control" placeholder="Customer Name">
</div>
<div class="col-md-6 mb-4">
<label> <strong> Customer Surname </strong></label>
<input type="text" name="customer_surname" class="form-control"
placeholder="Customer Surname">
</div>
<div class="col-md-4 mb-4">
<label> <strong>Phone 1</strong> *</label>
<input type="text" maxlength="11"
oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');"
name="customer_phone1" class="form-control" placeholder="Phone" reqiured>
</div>
<div class="col-md-4 mb-4">
<label> <strong> Phone 2 </strong></label>
<input type="text" maxlength="11"
oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');"
name="customer_phone2" class="form-control" placeholder="Phone">
</div>
<div class="col-md-4 mb-4">
<label> <strong> Phone 3 </strong></label>
<input type="text" maxlength="11"
oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');"
name="customer_phone3" class="form-control" placeholder="Phone">
</div>
<div class="col-md-6 mb-4">
<label> <strong> Customer Email </strong></label>
<input type="text" name="customer_email1" class="form-control" placeholder="Email">
</div>
<div class="form-group col-md-6 mb-4 ">
<label class="control-label" for="customer_score"> <strong> Customer Score
</strong></label>
<select class="form-control " name="customer_score">
<option selected="true" disabled="disabled" hidden>Choose..</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
<div class="col-md-6 mb-4">
<label> <strong> Customer Job </strong></label>
<input type="text" name="customer_job" class="form-control" placeholder="Customer Job">
</div>
<!--
<div class="col-md-6 mb-4">
<label> <strong> Call Later </strong></label>
<input type="text" name="call_later" class="form-control" placeholder="Call Later">
</div>
-->
<div class="form-group col-md-6 mb-4 ">
<label class="control-label" for="customer_gender"> <strong> Customer Gender
</strong></label>
<select class="form-control select2" name="customer_gender">
<option value="Man" selected="selected">Man</option>
<option value="Woman">Woman</option>
</select>
</div>
<div class="form-group col-md-12 mb-4 ">
<label class="control-label" for="customer_source"> <strong> Customer Source
</strong></label>
<select class="form-control " name="customer_source">
<option selected="true" disabled="disabled" hidden >Choose..</option>
<option value="Gelen Arama">Gelen Arama</option>
<option value="Tawk Canlı Destek">Tawk Canlı Destek</option>
<option value="WhatsApp">WhatsApp</option>
<option value="Formlar">Formlar</option>
<option value="E-Posta">E-Posta</option>
<option value="Referans">Referans</option>
</select>
</div>
<!--
<div class="col-md-6 mb-4">
<label> <strong> Customer Ref </strong></label>
<input type="text" name="customer_ref" class="form-control" placeholder="City">
</div>
-->
<?php $userId = Auth::id(); ?>
<input type="hidden" name="user_id" class="form-control" value="<?php echo $userId; ?>">
<input type="hidden" name="user_company_id" class="form-control" value="1">
<input type="hidden" name="tag_id" class="form-control" value="1">
<input type="hidden" name="company_id" class="form-control" value="1">
<button type="submit" class="btn btn-dark mb-3 ">Kaydet</button>
</div>
</form>
and i want to add records to database and redirect back to /addcustomers url
what am i doing wrong ?

Most likely why you see /addcustomers in the url is because after the submission you have:
return redirect()->back()->with('success', true);
I suppose your blade/html form submission page is on /addcustomers, and after you submit it to /addcustomers2 it redirects back to /addcustomers due to the above code. You can confirm this by opening the inspector on your browser and checking the networking tab (you might need to click an option to keep the history). There you will probably see the /addcustomers2 with all the parameters.
As others said you should use POST and rename your routes:
GET /addcustomers -> GET /customers
GET /addcustomers2 -> POST /customer

Related

Undefined variable Laravel using ajax function

I am using ajax for submitting data in the database but when I hit submit button in the return response "undefined " value I got, and the problem lies in the controller. I am not sure why I got this error. I am getting this error on fname variable and obv other variables too as they all are similar.
Here is the Controller
public function save(Request $request)
{
$validator = \Validator::make($request->all(), [
'cnic' => 'required|unique:patients',
]);
if ($validator->fails()) {
return response()->json(['success' => false, 'errors' => $validator->errors()->all()]);
}
$temppatientId = IdGenerator::generate(['table' => 'patients', 'length' => 5, 'prefix' => '22']);
$patientid = $temppatientId + 1;
$query = new patient;
$query->patientid = $patientid;
$query->fname =$fname;
$query->lname = $lname;
$query->cnic = $cnic;
$query->contactno = $contactno;
$query->gender = $gender;
$query->age = $age;
$query->dob = $dob;
$query->city = $city;
$query->address = $address;
$query->husbandname = $husbandname;
$query->fathername = $fathername;
$query->bloodgroup = $bloodgroup;
$query->maritalstatus = $maritalstatus;
$query->save();
return response()->json(['success' => true, 'patients' => $query]);
}
Here is the Ajax function
$(document).ready(function() {
$("#save1").on('click', function(e) {
var cnic = $("#cnic").val();
if (cnic == '') {
alert("Kindly Enter CNIC");
return false;
}
var gender = $("#gender").val();
if (gender == '') {
alert("Kindly Enter Gender");
return false;
}
var contactno = $("#contactno").val();
if (contactno == '') {
alert("Kindly Enter Contact No");
return false;
}
var fname = $("#fname").val();
if (fname == '') {
alert("Kindly Enter Name");
return false;
}
else{
$.ajax({
url: "/save",
type: "post",
data: $('#registrationform').serialize(),
dataType: 'json',
success: function(data) {
if (data.success === false) {
alert('CNIC already Exists !');
} else {
$("#patientid").val(data.patient.patientid);
// console.log(data.patient);
}
}
})
}
});
});
this is my blade file
<form class="form" data-parsley-validate id="registrationform" autocomplete="off">
#csrf
<div class="row">
<div class="col-md-4 col-4">
<div class="form-group mandatory">
<label for="first-name-column" class="form-label">First Name</label>
<input type="text" autofocus tabIndex="1" name="fname" id="fname" class="form-control" placeholder="First Name" name="fname" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group">
<label for="last-name-column" class="form-label">Last Name</label>
<input type="text" id="lname" tabIndex="2" class="form-control" placeholder="Last Name" name="lname">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group">
<label for="city-column" class="form-label">Age</label>
<input type="number" id="age" tabIndex="3" class="form-control" placeholder="Age" name="age" >
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group">
<label for="country-floating" class="form-label">DOB</label>
<input type="date" id="dob" tabIndex="4" class="form-control" name="dob" placeholder="Date of Birth">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group choices" mandatory>
<label for="company-column" class="form-label choices">Gender:</label>
<div class="form-group">
<select class="choices form-select" tabIndex="5" id="gender" name="gender">
<option value="">SELECT</option>
<option value="MALE">MALE</option>
<option value="FEMALE">FEMALE</option>
<option value="NEUTER">NEUTER</option>
</select>
</div>
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group mandatory">
<label for="email-id-column" class="form-label">Contact No</label>
<input type="number" id="contactno" tabIndex="6" class="form-control" name="contactno" placeholder="Contact No" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group ">
<label for="email-id-column" class="form-label">Father Name</label>
<input type="text" id="fathername" tabIndex="7" class="form-control" name="fathername" placeholder="Father Name" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group ">
<label for="email-id-column" class="form-label">Husband Name</label>
<input type="text" id="husbandname" tabIndex="8" class="form-control" name="husbandname" placeholder="Husband Name" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group mandatory">
<label for="email-id-column" class="form-label">CNIC</label>
<input type="number" id="cnic" class="form-control" tabIndex="9" name="cnic" placeholder="CNIC" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group ">
<label for="email-id-column" class="form-label">City</label>
<input type="text" id="city" tabIndex="10" class="form-control" name="city" placeholder="City" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group choices">
<label for="company-column" class="form-label choices">Marital Status</label>
<div class="form-group">
<select class="choices form-select" tabIndex="11" id="maritalstatus" name="maritalstatus">
<option value="">SELECT</option>
<option value="NOT SPECIFIED">NOT SPECIFIED</option>
<option value="SINGLE">SINGLE</option>
<option value="MARRIED">MARRIED</option>
<option value="WIDOW">WIDOW</option>
<option value="WIDOWER">WIDOWER</option>
<option value="DIVORCED">DIVORCED</option>
<option value="SEPARATED">SEPARATED</option>
<option value="UNKNOWN">UNKNOWN</option>
</select>
</div>
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group choices">
<label for="company-column" class="form-label choices">Blood Group</label>
<div class="form-group">
<select class="choices form-select" tabIndex="12" id="bloodgroup" name="bloodgroup">
<option value="">SELECT</option>
<option value="NOT SPECIFIED">NOT SPECIFIED</option>
<option value="A POSITIVE">A POSITIVE</option>
<option value="A NEGATIVE">A NEGATIVE</option>
<option value="B POSITIVE">B POSITIVE</option>
<option value="B NEGATIVE">B NEGATIVE</option>
<option value="O POSITIVE">O POSITIVE</option>
<option value="O NEGATIVE">O NEGATIVE</option>
<option value="AB POSITIVE">AB POSITIVE</option>
<option value="AB NEGATIVE">AB NEGATIVE</option>
</select>
</div>
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group mandatory">
<label for="email-id-column" class="form-label">Address</label>
<input type="text" id="address" class="form-control" tabIndex="13" name="address" placeholder="Address" data-parsley-required="true">
</div>
</div>
<div class="col-6 col-lg-3 col-md-6">
<div class="card-body px-2 py-3-4">
<div class="row">
<div class="col-md-4 col-lg-4 col-xl-8 col-xxl-5 d-flex justify-content-start ">
<div class="stats-icon purple mb-2">
<i class="iconly-boldShow"></i>
</div>
</div>
<div class="col-md-8 col-lg-12 col-xl-12 col-xxl-7">
<h6 class="text-muted font-semibold">Patient ID</h6>
<input class="font-extrabold mb-0" style="align-content: center; color:red; " type="number" name="patientid" id="patientid" disabled>
</div>
</div>
</div>
</div>
{{-- <label>Search Patient:</label>
<div class="col-lg-2">
<label>Patient ID:</label>
<input placeholder="Enter Patient ID" type="number" name="patientid"
id="selectpatientid" class="form-control form-control-sm d2">
</div>
<div class="col-lg-2">
<label>Patient CNIC:</label>
<input placeholder="Enter Patient CNIC" type="number" name="cnic"
id="selectpatientcnic" class="form-control form-control-sm d2">
</div>
</div> --}}
<div class="row">
<div class="col-12 d-flex justify-content-end">
<a id="save1" tabIndex="14" class="btn btn-primary me-1 mb-1">Register</a>
{{-- <button type="submit" class="btn btn-light-secondary me-1 mb-1">Register</button> --}}
<button type="reset" class="btn btn-light-secondary me-1 mb-1">Reset</button>
</div>
</div>
</form>
Try opening the F12 tools and heading over to the networking tab, under the networking tab you can double check the CSR under is getting pass along to the app under the 'headers' or 'request' once you've clicked on your jQuery request
You should also be able to see that larval responded with if you click 'response'
It might also be worth checking out the laravel.log under storage provider any more insight to the problem, this normally contains some help hints

How to show uploaded files as selected during update/edit the form?

I have a form which contain multiple file upload field ,I have success to upload multiple files in /upload folder.
But now when I edit the form that time I want to show the previously upload files as selected files where I can change the files,add new files or delete the files.
echo form_open_multipart(site_url()."lead/update/$lead->id");
?>
<div class="box-body">
<div class="form-group">
<label for="InputFirstName">First name</label>
<input type="text" class="form-control" id="InputFirstName" name="InputFirstName" placeholder="Enter first name" value="<?php echo $lead->fname; ?>">
</div>
<div class="form-group">
<label for="InputLastName">Last name</label>
<input type="text" class="form-control" id="InputLastName" name="InputLastName" placeholder="Enter last name" value="<?php echo $lead->lname; ?>">
</div>
<div class="form-group">
<label for="InputEmail1">Email address</label>
<input type="email" class="form-control" id="InputEmail1" name="InputEmail1" placeholder="Enter email" value="<?php echo $lead->email; ?>">
<?php echo form_error('InputEmail1', '<span class="help-block">', '</span>'); ?>
</div>
<div class="form-group">
<label for="InputContact">Contact number</label>
<input type="text" class="form-control" id="InputContact" name="InputContact" placeholder="Enter contact number" value="<?php echo $lead->phone; ?>">
</div>
<div class="form-group">
<label for="InputSource">Source</lable>
<select name="source" id="InputSource" class="form-control">
<option value="Email"<?php if($lead->source=='Email') echo 'selected="selected"';?>>Email</option>
<option value="Phone"<?php if($lead->source=='Phone') echo 'selected="selected"';?>>Phone</option>
<option value="Website"<?php if($lead->source=='Website') echo 'selected="selected"';?>>Website</option>
</select>
</div>
<div class="form-group">
<label for="InputStatus">Status</label>
<select name="status" id="InputStatus" class="form-control">
<option value="Draft"<?php if($lead->status=='Draft') echo 'selected="selected"';?>>Draft</option>
<option value="In Progress" <?php if($lead->status=='In Progress') echo 'selected="selected"';?>>In Progress</option>
<option value="Responsible Assigned" <?php if($lead->status=='Responsible Assigned') echo 'selected="selected"';?>>Responsible Assigned</option>
</select>
</div>
<div class="form-group">
<label for="exampleInputFile">Add Attachments</label>
<input type="file" id="files" name="files[]">
<div class="contents"></div>
<div>
Add more
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<?php echo form_submit(array('value'=>'Submit', 'class'=>'btn btn-primary btn_add', 'name'=>'SAVE')); ?>
</div>
<?php echo form_close(); ?>
This is my code

php ajax returns some html content instead of numeric value

I'm getting the nominee_role value from add_employee file.
In nominee_role im getting 7000 as a result, but when I'm trying to get the data value in alert it returns some html contents.
<?php
include('database.php');
include("header.php");
include("left_side_bar.php");
?>
<div class="row">
<!-- left column -->
<div class="col-xs-12">
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">
Add employee
</h3>
<?php
extract($_POST);
//echo $name;
$current_date=date("Y-m-d");
if(isset($_POST['submit']))
{
//echo "hi";
$select = "SELECT * FROM `emp_details` WHERE `branch_name` = '".$branch_code."' AND `emp_role` = '".$emp_role."' ORDER BY id DESC LIMIT 1";
//echo $select;
$exe_select=mysql_query($select);
$fetch=mysql_fetch_array($exe_select);
$rows = mysql_num_rows($exe_select);
$emp_id ='0001';
if($rows == 0)
{
$emp_id ='0001';
$emp_code=$branch_code.$emp_role.$emp_id;
//echo "employee code: ".$emp_code;
}
else
{
$emp_id=$fetch['emp_code'];
echo $emp_id;
//exit();
$emp_id= $emp_id +1;
$emp_code=$emp_id;
//echo "employee code: ".$emp_code;
}
//exit();
$sql="INSERT INTO `emp_details`
(`emp_name`, `emp_code`, `emp_role`, `dob`, `age`, `address`, `contact_number`, `gender`, `pan`, `bank_acc`, `ifsc_code`, `branch_name`,`intro_code`, `nom_name`, `nom_address`, `nom_age`, `nom_gender`, `relationship_status`, `created_date`)
VALUES
('".$name."', '".$emp_code."', '".$emp_role."', '".$dob."', '".$age."', '".$address."', '".$contact_num."', '".$gender."', '".$pan."', '".$acc_num."', '".$ifsccode."', '".$branch_code."', '".$intro_code."', '".$nom_name."', '".$nom_add."', '".$nom_age."', '".$nom_gender."', '".$rel_status."', '".$current_date."' )";
//print_r($sql);
//exit();
$exe_query=mysql_query($sql);
if($exe_query)
{
echo '<h3 class="msyqlsuccess">Employee Details Added Successfully</h3>';
}
else
{
echo '<h3 class="msyqlerror">Employee Details Not Added</h3>'; }
}
?>
</div>
</div>
<!-- form start -->
<form role="form" method="post" class="agentdetails" id="add_agent_details" enctype="multipart/form-data">
<div class="box-body clearfix">
<div class="form-group">
<label>Name</label>
<input type="text" placeholder="Enter Employee Name" id="name" required="required" name="name" class="form-control" />
</div>
<div class="form-group">
<label>DOB</label>
<input type="text" placeholder="Enter DOB" id="date_of_birth" required="required" name="dob" class="form-control" />
</div>
<div class="form-group">
<label>Age</label>
<input type="text" placeholder="Enter Employee Age" id="age" required="required" name="age" class="form-control" />
</div>
<div class="form-group">
<label>Address</label>
<input type="text" placeholder="Enter Employee Address" id="address" required="required" name="address" class="form-control" />
</div>
<div class="form-group">
<label>Contact Number</label>
<input type="text" placeholder="Enter Contact Number" id="contact_num" required="address" name="contact_num" class="form-control" />
</div>
<div class="form-group">
<label>Gender</label>
<select name="gender" id="gender" class="select">
<option value="Female">Female</option>
<option value="Male">Male</option>
</select>
</div>
<div class="form-group">
<label>Employee Role</label>
<select name="emp_role" id="" class="select">
<option value="">---Select User Role---</option>
<option value="1000">Adviser</option>
<option value="2000">Agency Manager</option>
<option value="3000">Sales Manager</option>
<option value="4000">Business Development Manager</option>
<option value="5000">Executive Manager</option>
<option value="6000">Senior Executive Manager</option>
<option value="7000">Director</option>
</select>
</div>
<div class="form-group">
<label>Branch Name</label>
<select name="branch_code" id="" class="select">
<option value="">--Select Branch--</option>
<option value="130">Chennai</option>
<option value="150">Pondicherry</option>
</select>
</div>
<div class="form-group">
<label>PAN Number</label>
<input type="text" placeholder="Enter PAN" id="pan" required="required" name="pan" class="form-control" />
</div>
<div class="form-group">
<label>Bank Account</label>
<input type="text" placeholder="Enter Bankacc" id="acc_num" required="required" name="acc_num" class="form-control" />
</div>
<div class="form-group">
<label>IFSC Code</label>
<input type="text" placeholder="Enter IFSC Code" id="ifsccode" required="required" name="ifsccode" class="form-control" />
</div>
<div class="form-group">
<label>Introducer Code</label>
<input type="text" placeholder="Enter Introducer Code" id="intro_code" required="required" name="intro_code" class="form-control" />
</div>
<div class="form-group">
<label>Nominee Role</label>
<select name="nominee_role" class="select nominee">
<option value="">---Select Nominee Role---</option>
<option value="1000">Adviser</option>
<option value="2000">Agency Manager</option>
<option value="3000">Sales Manager</option>
<option value="4000">Business Development Manager</option>
<option value="5000">Executive Manager</option>
<option value="6000">Senior Executive Manager</option>
<option value="7000">Director</option>
</select>
</div>
<div class="form-group">
<label>Nominee Name</label>
<select name="nom_name" id="" class="select nominee_name">
<option value="">---Select Nominee Role---</option>
<?php
echo $nominee_role = $_POST['nominee_role'];
//echo "hi";
//load nominee name
$get_nominee="SELECT * FROM `emp_details` WHERE `nom_role` = '".$nominee_role."'";
echo $get_nominee;
$exe_nominee=mysql_query($get_nominee);
$is_nominee=mysql_fetch_array($exe_nominee);
$nominee_row=mysql_num_rows($exe_nominee);
if($is_nominee)
{
echo '<option value="'.$is_nominee['emp_code'].'">'.$is_nominee['nom_name'].'</option>';
}
else
{
echo '<option value="">No names are found</option>';
}
?>
</select>
</div>
<div class="form-group">
<label>Nominee Age</label>
<input type="text" placeholder="Enter Nominee Age" id="nom_age" required="required" name="nom_age" class="form-control" />
</div>
<div class="form-group">
<label>Nominee Address</label>
<input type="text" placeholder="Enter Nominee Address" id="nom_add" required="required" name="nom_add" class="form-control" />
</div>
<div class="form-group">
<label>Nominee Gender</label>
<select name="nom_gender" id="" class="select">
<option value="female">Female</option>
<option value="male">Male</option>
</select>
</div>
<div class="form-group">
<label>Relationship Status</label>
<input type="text" placeholder="Enter Relationship Status" id="rel_status" required="required" name="rel_status" class="form-control" />
</div>
<div class="box-footer">
<?php //if($num){ ?>
<!-- <button class="btn btn-primary" id="next" value="Update" type="submit" name="submit" style="margin-top: 6%;">Update</button>
--> <?php //} else { ?>
<button class="btn btn-primary submit" id="add_agent_details" value="Submit" type="submit" name="submit">Submit</button>
<?php //} ?>
</div>
</div>
</form>
</div>
</div>
<?php
include("footer.php");
die;
?>
<script>
$('.nominee').change(function () {
var nominee_role = $('.nominee').val();
alert(nominee_role); // '7000'
//send nominee role
$.ajax({
type: "POST",
url: "add_employee.php",
data: {nomi_role: nominee_role},
success: function (data) {
alert(data);
}
});
return false;
});
</script>
Kindly help me to solve this! I really don't know where I leave a mistake!
Add die; at the end of add_employee.php file;
while you didnt include your add_employee file then lets say you have this in that file.
$your_var = 7000 ;
$other_value = 8000 ;
echo json_encode(array("val"=>$your_var , "val2"=>$other_value ));
then in your ajax you should have this :
$.ajax({
type: "POST",
url: "add_employee.php",
data: {nomi_role: nominee_role},
success: function (data) {
alert(data.val); //will give you 7000.
alert(data.val2); //will give you 8000.
}
});
Hope that helps .

Add A File Attachment to A PHP Email Form Send

Currently I have created a form on a PHP form that posts to the send PHP code. All of the textareas/fields ETC work fine. The issue I have is that I have 3 file fields. The aim is to add 3 file attachments to the email. I just cant work out how to do it.
(Attachment areas at the bottom of the form)
<form method="post" action="quote_send.php">
<form class="form-light mt-20" role="form">
<div class="form-group">
<label>Title</label><br />
<select name="Title">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Miss">Miss</option>
<option value="Ms">Ms</option>
</select>
</div> <div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Forename</label>
<input type="text" class="form-control" name="forename" placeholder="Your Forename">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Surname</label>
<input type="text" class="form-control" name="surname" placeholder="Your Surname">
</div>
</div>
</div>
<!----CONTACT DETAILS------>
<h3>Your Contact Details</h3>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Email Address</label>
<input type="text" class="form-control" name="visitormail" placeholder="Your Email Address">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Contact Number</label>
<input type="text" class="form-control" name="number" placeholder="Your Contact Number">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Address Line 1</label>
<input type="text" class="form-control" name="address1" placeholder="Address Line 1">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Address Line 2</label>
<input type="text" class="form-control" name="address2" placeholder="Address Line 2">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>City</label>
<input type="text" class="form-control" name="city" placeholder="City">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label>Post Code</label>
<input type="text" class="form-control" name="pcode" placeholder="Post Code">
</div>
</div>
</div>
<!----SITE DETAILS----->
<h3>Site Contact Details</h3>
<div class="form-group">
<label>Title</label><br />
<select name="siteTitle">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Miss">Miss</option>
<option value="Ms">Ms</option>
</select>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Site Contact Forename</label>
<input type="text" class="form-control" name="scforename" placeholder="Site Contact Forename">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Site Contact Surname</label>
<input type="text" class="form-control" name="scsurname" placeholder="Site Contact Surname">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Email Address</label>
<input type="text" class="form-control" name="scvisitormail" placeholder="Site Email Address">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Contact Number</label>
<input type="text" class="form-control" name="scnumber" placeholder="Site Contact Number">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Address Line 1</label>
<input type="text" class="form-control" name="scaddress1" placeholder="Site Address Line 1">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Address Line 2</label>
<input type="text" class="form-control" name="scaddress2" placeholder="Site Address Line 2">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>City</label>
<input type="text" class="form-control" name="sccity" placeholder="City">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label>Post Code</label>
<input type="text" class="form-control" name="scpcode" placeholder="Post Code">
</div>
</div>
</div>
<!----SITE DETAILS----->
<h3>Site Details</h3>
<div class="row">
<div class="col-md-2">
<div class="form-group">
<label>Number of Domestic Plots</label><br />
<select name="numdp">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5+">5+</option>
</select></div></div>
<div class="col-md-2">
<div class="form-group">
<label>Number of Commercial Plots</label><br />
<select name="numcp">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5+">5+</option>
</select>
</div></div>
<div class="col-md-2">
<div class="form-group">
<label>Is The Site Visit Required?</label><br />
<select name="sitevisitr">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div></div>
<div class="col-md-3">
<div class="form-group">
<label>Is The Site a Brownfield/Regeneration?</label><br />
<select name="brownregen">
<option value="Brownfield">Brownfield</option>
<option value="Regeneration">Regeneration</option>
</select>
</div></div>
<div class="col-md-3">
<div class="form-group">
<label>Is The Site Contaminated?</label><br />
<select name="contam">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div></div>
<div class="col-md-2">
<div class="form-group">
<label>Property Type</label><br />
<select name="proptype">
<option value="Commercial">Commercial</option>
<option value="Flat">Flat</option>
<option value="Detached">Detached</option>
<option value="Semi-Detached">Semi-Detached</option>
<option value="Terraced">Terraced</option>
</select>
</div></div>
<div class="col-md-2">
<div class="form-group">
<label>Rooms In The Property</label><br />
<select name="nrooms">
<option value="N/A">N/A</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10+">10+</option>
</select>
</div></div>
<div class="col-md-2">
<div class="form-group">
<label>Do You Have A Gas Supplier? *</label><br />
<select name="gsupplier">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div></div>
<div class="col-md-3">
<div class="form-group">
<label>If Yes. Who Is Your Gas Supplier?</label>
<input type="text" class="form-control" name="gsuppliername" placeholder="Gas Supplier">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Who Will Be Carrying Out The Excavation?</label><br />
<select name="erxcav">
<option value="MDL">MDL</option>
<option value="Customer">Customer</option>
</select>
</div></div>
<br /><p> * NOTE: If you do not have a gas supplier in place, you will need to obtain one before any works can be carried out. You can find a gas supplier here.</p>
<div class="col-md-2">
<div class="form-group">
<label>What Service Do You Require?</label><br />
<select name="servicer">
<option value="Gas Connection(s)">Gas Connection(s)</option>
<option value="Gas Disconnection(s)">Gas Disconnection(s)</option>
<option value="Meter Fitting / Exchange">Meter Fitting / Exchange</option>
<option value="Directional Drilling">Directional Drilling</option>
<option value="Outlet Pipework">Outlet Pipework</option>
</select>
</div></div>
<div class="col-md-3">
<div class="form-group">
<label>What Is Your Hourly Load? (KWh)</label>
<input type="text" class="form-control" name="hourl" placeholder="Hourly Load (KWh)">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>What Is Your Annual Load? (KWh)</label>
<input type="text" class="form-control" name="annl" placeholder="Annual Load? (KWh)">
</div>
</div> <br /><br /><br /><br />
<p> * NOTE: We require specific documents so we can proceed with your quote. These documents can be seen in the upload section below</p>
<div class="col-md-4">
<div class="form-group">
<label>Scaled Site Location Plan</label>
<input name="sslp" type="file">
</div></div>
<div class="col-md-4">
<div class="form-group">
<label>Domestic Property Schedule</label>
<input name="dps" type="file">
</div></div>
<div class="col-md-4">
<div class="form-group">
<label>Site Boundary Drawing</label>
<input name="sbd" type="file">
</div></div>
<p> * NOTE: We require specific documents so we can proceed with your quote. These documents can be seen in the upload section below</p>
<div class="col-md-6">
<div class="form-group">
<label>Is There Any Other Information You Think Would Help Us?</label><br />
<textarea class="form-control" name="notes" placeholder="Write you message here..." style="height:100px;"></textarea>
</div></div>
</div>
<br / >
<button type="submit" class="btn btn-two">SUBMIT</button>
</form>
THE PHP send code.-----------------------
<?php
$Title = $_POST['Title'];
$forename = $_POST['forename'];
$surname = $_POST['surname'];
$visitormail = $_POST['visitormail'];
$number = $_POST['number'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$pcode = $_POST['pcode'];
$siteTitle = $_POST['siteTitle'];
$scforename = $_POST['scforename'];
$scsurname = $_POST['scsurname'];
$scvisitormail = $_POST['scvisitormail'];
$scnumber = $_POST['scnumber'];
$scaddress1 = $_POST['scaddress1'];
$scaddress2 = $_POST['scaddress2'];
$sccity = $_POST['sccity'];
$scpcode = $_POST['scpcode'];
$numdp = $_POST['numdp'];
$numcp = $_POST['numcp'];
$sitevisitr = $_POST['sitevisitr'];
$brownregen = $_POST['brownregen'];
$contam = $_POST['contam'];
$proptype = $_POST['proptype'];
$nrooms = $_POST['nrooms'];
$gsupplier = $_POST['gsupplier'];
$gsuppliername = $_POST['gsuppliername'];
$erxcav = $_POST['erxcav'];
$servicer = $_POST['servicer'];
$hourl = $_POST['hourl'];
$annl = $_POST['annl'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];
$sslp = $_POST['sslp'];
$dps = $_POST['dps'];
$sbd = $_FILES['sbd'];
if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"#") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}
if(empty($forename) || empty($visitormail) || empty($notes )) {
echo "<h2>You have missed out required fields, please go back to them and fill them in</h2>\n";
die ("Use back! ! ");
}
$todayis = date("l, F j, Y, g:i a") ;
$attn = $attn ;
$subject = "New $servicer Quote Request";
$notes = stripcslashes($notes);
$message = "Section 1 - Customer Details \n
Customer Title: $Title
Customer Forname: $forename
Customer Surname: $surname
Customer Email: $visitormail
Customer Contact Number: $number
Contact Postal Address:\n $address1 \n $address2 \n $city \n $pcode \n
Section 2 - Site Contact Details \n
Site Contact Title: $siteTitle
Site Contact Forname: $scforename
Site Contact Surname: $scsurname
Site Contact Email Address: $scvisitormail
Site Contact Number: $scnumber
Site Current Postal Address:\n $scaddress1 \n $scaddress2 \n $sccity \n $scpcode \n
Section 3 - Site Work Details \n
Number of Domestic Plots: $numdp
Number of Commercial Plots: $numcp
Site Visit Required: $sitevisitr
Site a Brownfield/Regeneration: $brownregen
Site Contaminated: $contam
Property Type: $proptype
Number of Rooms in The Property: $nrooms
Gas Supplier Organised: $gsupplier
Gas Supplier Name: $gsuppliername
Who Will Be Carrying Out The Excavation: $erxcav
Service Rquired: $servicer
Hourly Load: $hourl
Annual Load: $annl
Extra Information: $notes
Attached Files: $sslp \n $dps \n $sbd
Please reply to this email within 24 hours to maximise our chances of turning enquiries in to sales.
";
$_FILES ="$sbd";
$from = "From: $visitormail\r\n";
mail("ash.manterfield#btinternet.com", $subject, $message, $from, $_FILES);
?>
</span>Thank you <?php echo $visitor ?> for contacting us regarding <?php echo $attn ?>.
Any help would be appreciated I've tried a few approaches and cant work out how to do it.

Having an issue with PHP $_POST

I am trying to tie my html form to a PHP mailer and for some reason the form inputs are not storing in my variables. I have tried searching all over and I cannot see what I am doing wrong. Any help would be greatly appreciated.
Form handler:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$date = trim($_POST["date"]);
$guests = trim($_POST["guests"]);
$description = trim($_POST["description"]);
}
Form:
<form role="form" class="text-center" method="POST" enctype="text/plain" action="index.php">
<div class="form-group">
<label for="name">Nombre</label>
<input type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group">
<label for="email">Correo Electrónico</label>
<input type="email" class="form-control" id="email" name="email">
</div>
<div class="form-group">
<label for="date">Fecha del Evento</label>
<input type="date" id="date" class="form-control" name="date">
</div>
<div class="form-group">
<label for="guests">Número de Huéspedes</label>
<select class="form-control" id="guests" name="guests">
<option>1 - 2</option>
<option>3 - 4</option>
<option>5 - 6</option>
<option>7 - 8</option>
</select>
</div>
<div class="form-group">
<label for="description">Descripción de Evento</label>
<textarea class="form-control" id="description" rows="3" name="description"></textarea>
</div>
<div style="display: none;">
<label for="address">Address</label>
<input type="text" class="form-control" id="address" name="address">
</div>
<input type="submit" class="btn btn-default" value="Enviar">
</form>
For PHP text/plain is not a valid value for enctype in <form>
Take a look here

Categories