I'm trying to achieve updating Image I tried finding for the answer but it seems that they don't work on mine maybe because I am using Yajra DataTables, I already inserted or added the image seems to be working fine but whenever I click the button it doesn't popup the modal Thank you in Advance.
This is my Controller:
public function edit($id)
{
if (request()->ajax()) {
$shippings = Shipping_data::findOrFail($id);
return response()->json(['result' => $shippings]);
}
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, Shipping_data $shippings_data)
{
$rules = array(
'name' ,
'mobile',
'items',
'shippingAddress',
'amount',
'facebookLink',
'facebookName',
"modePayment",
"shipVia"=> 'required',
"trackingNumber"=> 'required',
"shippingReceipt"=> 'required',
"shippingCharged"=> 'required',
"shippingWeight"=> 'required'
);
$error = Validator::make($request->all(), $rules);
if ($error->fails()) {
return response()->json(['errors' => $error->errors()->all()]);
}
// Handle File Upload
if ($request->hasFile('shippingReceipt')) {
// Get filename with the extension
$filenameWithExt = $request->file('shippingReceipt')->getClientOriginalName();
// Get just filename
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
// Get just ext
$extension = $request->file('shippingReceipt')->getClientOriginalExtension();
// Filename to store
$fileNameToStore= $filename.'_'.time().'.'.$extension;
// Upload Image
$path = $request->file('shippingReceipt')->storeAs('public/shippingReceipts', $fileNameToStore);
}else {
$fileNameToStore = '';
}
$form_data = array(
'name' => $request->name,
'mobile'=> $request->mobile,
'items'=> $request->items,
'shippingAddress'=> $request->shippingAddress,
'amount'=> $request->amount,
'facebookLink'=> $request->facebookLink,
'facebookName'=> $request->facebookName,
"modePayment"=> $request->modePayment,
"shipVia"=> $request->shipVia,
"trackingNumber"=> $request->trackingNumber,
"shippingReceipt"=> $request->fileNameToStore,
"shippingWeight"=> $request->shippingWeight,
"shippingCharged"=> $request->shippingCharged,
);
Shipping_data::whereId($request->hidden_id)->update($form_data);
return response()->json(['success' => 'Shipping Data is successfully updated']);
}
This is my blade.php:
#extends('layouts.navbar')
#section('content')
<br />
<br />
<br />
Add Order Data
<br>
<br>
<!-- Table -->
<div style="margin: 10px 15px;">
<table id="shipping_table" class="table table-bordered table-striped ">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Mobile Number</th>
<th scope="col">Item Orders</th>
<th scope="col">Shipping Address</th>
<th scope="col">Amount</th>
<th scope="col">Facebook Link</th>
<th scope="col">Facebook Name</th>
<th scope="col">Mode of Payment</th>
<th scope="col">Ship Via</th>
<th scope="col">Tracking Number</th>
<th scope="col">Shipping Receipt</th>
<th scope="col">Shipping Charged</th>
<th scope="col">Shipping Weight</th>
<th>Action</th>
</tr>
</thead>
</table>
</div>
<br />
<br />
<!-- End Table -->
</body>
</html>
<!-- Modal -->
<div id="formModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title text-center">Add Shipping Data</h4>
</div>
<div class="modal-body">
<span id="form_result"></span>
<form method="post" id="shipping_form" class="form-horizontal">
#csrf
#if(Auth::check() && Auth::user()->role == "admin")
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" placeholder="Please Enter Client Name"
id="name">
</select>
</div>
<div class="form-group">
<label>Mobile</label>
<input type="text" class="form-control" name="mobile" placeholder="Please Enter Mobile Number"
id="mobile">
</div>
<div class="form-group">
<label>Items Order</label>
<input type="text" class="form-control" name="items" placeholder="Please Enter Items Order"
id="items">
</div>
<div class="form-group">
<label>Shipping Address</label>
<input type="text" class="form-control" name="shippingAddress" id="shippingAddress"
placeholder="Please Enter Shipping Address">
</div>
<div class="form-group">
<label>Amount</label>
<input type="text" class="form-control" name="amount" placeholder="Please Enter Amount"
id="amount">
</div>
<div class="form-group">
<label>Facebook Link</label>
<input type="text" class="form-control" name="facebookLink" id="facebookLink"
placeholder="Please Enter Facebook Link">
</div>
<div class="form-group">
<label>Facebook Name</label>
<input type="text" class="form-control" name="facebookName" id="facebookName"
placeholder="Please Enter Facebook Name">
</div>
<div class="form-group">
<label>Mode of Payment</label>
<input type="text" class="form-control" name="modePayment" id="modePayment"
placeholder="Please Enter Mode of Payment">
</div>
#endif
#if(Auth::check() && Auth::user()->role == "employee")
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" placeholder="Please Enter Name" id="name"
READONLY>
</div>
<div class="form-group">
<label>Mobile</label>
<input type="text" class="form-control" name="mobile" placeholder="Please Enter Mobile Number"
id="mobile" READONLY>
</div>
<div class="form-group">
<label>Items Order</label>
<input type="text" class="form-control" name="items" placeholder="Please Enter Items Order"
id="items" READONLY>
</div>
<div class="form-group">
<label>Shipping Address</label>
<input type="text" class="form-control" name="shippingAddress" id="shippingAddress" READONLY
placeholder="Please Enter Shipping Address">
</div>
<div class="form-group">
<label>Amount</label>
<input type="text" class="form-control" name="amount" placeholder="Please Enter Amount"
id="amount" READONLY>
</div>
<div class="form-group">
<label>Facebook Link</label>
<input type="text" class="form-control" name="facebookLink" id="facebookLink" READONLY
placeholder="Please Enter Facebook Link">
</div>
<div class="form-group">
<label>Facebook Name</label>
<input type="text" class="form-control" name="facebookName" id="facebookName" READONLY
placeholder="Please Enter Facebook Name">
</div>
<div class="form-group">
<label>Mode of Payment</label>
<input type="text" class="form-control" name="modePayment" id="modePayment" READONLY
placeholder="Please Enter Mode of Payment">
</div>
#endif
<div class="form-group">
<label>Shipping Via</label>
<input type="text" class="form-control" name="shipVia" placeholder="Please Enter Shipping Via"
id="shipVia">
</div>
<div class="form-group">
<label>Tracking Number</label>
<input type="text" class="form-control" name="trackingNumber" id="trackingNumber"
placeholder="Please Enter Tracking Number">
</div>
<div class="form-group">
<label>Shipping Receipt</label>
<br>
<input type="file" class="form-control file-form" name="shippingReceipt" id="shippingReceipt">
</div>
<div class="form-group">
<label>Shipping Charged</label>
<input type="text" class="form-control" name="shippingCharged" id="shippingCharged"
placeholder="Please Enter Shipping Charged">
</div>
<div class="form-group">
<label>Shipping Weight</label>
<input type="text" class="form-control" name="shippingWeight" id="shippingWeight"
placeholder="Please Enter Shipping Weight">
</div>
<br />
<div class="form-group" align="center">
<input type="hidden" name="action" id="action" value="Add" />
<input type="hidden" name="hidden_id" id="hidden_id" />
<input type="submit" name="action_button" id="action_button" class="btn btn-success"
value="Add" />
</div>
</form>
</div>
</div>
</div>
</div>
<div id="confirmModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="modal-title">Confirmation</h2>
</div>
<div class="modal-body">
<h4 align="center" style="margin:0;">Are you sure you want to remove this data?</h4>
</div>
<div class="modal-footer">
<button type="button" name="ok_button" id="ok_button" class="btn btn-danger">OK</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
<!-- End Modal -->
<script>
$(document).ready(function () {
$('#shipping_table').DataTable({
processing: true,
serverSide: true,
ajax: {
url: "{{ route('shipping.index') }}",
},
columns: [
{
data: 'name',
name: 'name'
},
{
data: 'mobile',
name: 'mobile'
},
{
data: 'items',
name: 'items'
},
{
data: 'shippingAddress',
name: 'shippingAddress'
},
{
data: 'amount',
name: 'amount'
},
{
data: 'facebookLink',
name: 'facebookLink'
},
{
data: 'facebookName',
name: 'facebookName'
},
{
data: 'modePayment',
name: 'modePayment'
},
{
data: 'shipVia',
name: 'shipVia'
},
{
data: 'trackingNumber',
name: 'trackingNumber'
},
{
data: 'shippingReceipt',
name: 'shippingReceipt',
"render": function (data, type, full, meta) {
return "<img src=\"storage/shippingReceipts/" + data + "\" height=\"50\"/>";
},
},
{
data: 'shippingCharged',
name: 'shippingCharged'
},
{
data: 'shippingWeight',
name: 'shippingWeight'
},
{
data: 'action',
name: 'action',
orderable: false
}
]
});
$('#create_record').click(function () {
$('.modal-title').text('Add Client Data');
$('#action_button').val('Add Client Data');
$('#action').val('Add');
$('#form_result').html('');
$('#formModal').modal('show');
});
$('#shipping_form').on('submit', function (event) {
event.preventDefault();
var action_url = '';
if ($('#action').val() == 'Add') {
action_url = "{{ route('shipping.store') }}";
}
if ($('#action').val() == 'Edit') {
action_url = "{{ route('shipping.update') }}";
}
$.ajax({
url: action_url,
method: "POST",
data: $(this).serialize(),
dataType: "json",
success: function (data) {
var html = '';
if (data.errors) {
html = '<div class="alert alert-danger">';
for (var count = 0; count < data.errors.length; count++) {
html += '<p>' + data.errors[count] + '</p>';
}
html += '</div>';
}
if (data.success) {
html = '<div class="alert alert-success">' + data.success + '</div>';
$('#shipping_form')[0].reset();
$('#shipping_table').DataTable().ajax.reload();
}
$('#form_result').html(html);
}
});
});
$(document).on('click', '.edit', function () {
var id = $(this).attr('id');
$('#form_result').html('');
$.ajax({
url: "/shipping/" + id + "/edit",
dataType: "json",
success: function (data) {
$('#name').val(data.result.name);
$('#mobile').val(data.result.mobile);
$('#items').val(data.result.items);
$('#shippingAddress').val(data.result.shippingAddress);
$('#amount').val(data.result.amount);
$('#facebookLink').val(data.result.facebookLink);
$('#facebookName').val(data.result.facebookName);
$('#modePayment').val(data.result.modePayment);
$('#shipVia').val(data.result.shipVia);
$('#trackingNumber').val(data.result.trackingNumber);
$('#shippingReceipt').val(data.result.shippingReceipt);
$('#shippingCharged').val(data.result.shippingCharged);
$('#shippingWeight').val(data.result.shippingWeight);
$('#hidden_id').val(id);
$('.modal-title').text('Edit Record');
$('#action_button').val('Save');
$('#action').val('Edit');
$('#formModal').modal('show');
}
})
});
var shipping_id;
$(document).on('click', '.delete', function () {
shipping_id = $(this).attr('id');
$('#confirmModal').modal('show');
});
$('#ok_button').click(function () {
$.ajax({
url: "shipping/destroy/" + shipping_id,
beforeSend: function () {
$('#ok_button').text('Deleting...');
},
success: function (data) {
setTimeout(function () {
$('#confirmModal').modal('hide');
$('#shipping_table').DataTable().ajax.reload();
}, 2000);
}
})
});
});
</script>
#endsection
You can't view an image on input field, but you can do it with img tag :
<img class="img-circle" id="view_photo">
Change this line :
$('#shippingReceipt').val(data.result.shippingReceipt);
To,
$("#view_photo").attr("src", data.result.shippingReceipt);
i'm new with angular 5.
I'm trying to populate a form with data from a database.
So far this it hid my form and from the ts side it only shows null.
PHP code:
include ('conexion.php');
$id = $_GET['id'];
$sql = "SELECT * FROM tbl_usuario WHERE id=".$id;
if($con){
if(!$result = mysqli_query($con,$sql)) die();
while($data = mysqli_fetch_assoc($result)){
$arreglo[] = $data;
}
echo json_encode($arreglo);
}else{
die ("error");
}
form.html:(the ngModel i used with or without brackets)
<div class="forms">
<form method="post" *ngFor="let x of datos">
<div class="form-row">
<div class="form-group col-md-4">
<label>Nombre</label>
<input type="text" class="form-control col-10" (ngModel)="x.nombre" name="nombre" value="x.nombre" />
</div>
<div class="form-group col-md-4">
<label>Apellido Paterno</label>
<input type="text" class="form-control col-10" (ngModel)="x.a_paterno" name="a_paterno" value="x.a_paterno" required/>
</div>
<div class="form-group col-md-4">
<label>Apellido Materno</label>
<input type="text" class="form-control col-10" (ngModel)="x.a_materno" name="a_materno" value="x.a_materno" required/>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Edad</label>
<input type="text" class="form-control col-10" (ngModel)="x.edad" name="edad" value="x.edad" required/>
</div>
<div class="form-group col-md-6">
<label>Carrera</label>
<input type="text" class="form-control col-10" (ngModel)="x.carrera" name="carrera" value="x.carrera" required />
</div>
<div class="col-md-10">
<label>Direccion</label>
<input type="text" class="form-control col-12" (ngModel)="x.direccion" name="direccion" value="x.direccion" required/>
</div>
<div class="col-md-10">
<br>
<label>Telefono</label>
<input type="text" class="form-control col-12" (ngModel)="x.telefono" name="telefono" value="x.telefono" required/>
</div>
</div>
<br>
<button type="submit" class="btn btn-primary">Enviar Datos</button>
<br>
<br>
</form>
</div>
form.ts:
constructor(private http: HttpClient, private router: Router, private route: ActivatedRoute) {
this.mostrarDatos();
}
ngOnInit() {
this.route.params.subscribe(params => {
this.id = params['id']; // (+) converts string 'id' to a number
console.log('Mi id' + this.id);
});
}
mostrarDatos() {
console.log(this.id);
this.http.get('http://localhost/crudu/mostrarID.php?id=' + this.id).subscribe((data) => {
this.datos = data;
console.log(this.datos);
});
}
I've been trying with many solutions but nothing at the end.
Also in my route or url it shows as eUsuario/1
Try to replace (ngModel) with [(ngModel)]. Currently you have a binding from the input into model but not vice versa.
Remove the call of mostrarDatos from the constructor and call it after you get the id.
this.route.params.subscribe(params => {
this.id = params['id']; // (+) converts string 'id' to a number
console.log('Mi id' + this.id);
this.mostrarDatos();
});
I was trying to send a form data to php code some how when I have condition of if the button was submit do the following code it doesn't work :
$("button#send").click(function() {
var error = '';
var send = $("#send").val() = true;
if ($('#username').val().length == 0) { error += 'user name<br />'; }
if ($('#password').val().length == 0) { error += 'password<br />'; }
if ($('#repassword').val().length == 0) { error += 'repassword<br />'; }
if ($('#password').val() != $('#repassword').val()) { error += 'pass match<br />'; }
var phonenum = $('#phonenum').val() + $('#select').val();
if (phonenum.length == 0) { error += 'phone num <br />'; } else if ($.isNumeric(phonenum) == false || phonenum.length != 10) { error += 'phoneworng<br />'; }
if (error != '') {
$('#result').html(error);
} else {
$.ajax({
url: $("#form_reg").attr('action'),
data: $("#form_reg input").serializeArray(),
type: 'POST',
success: function(result) {
$("#result").html(result);
},
error: function(error) {
alert(error);
}
});
}
$("#form_reg").submit(function(e) {
e.preventdefault;
return false;
});
});
here the html code
<form id="form_reg" action="AddUser.php" method="post">
<div class="head_div"> <span> reg </span> </div>
<div id="main_reg">
<div class="login_line">
<label for="username">username</label>
<input type="text" name="username" id="username" placeholder="username" />
</div>
<div class="login_line">
<label for="password"> passs </label>
<input type="password" name="password" id="password" placeholder="pass" />
</div>
<div class="login_line">
<label for="repassword"> repass </label>
<input type="password" name="repassword" id="repassword" placeholder="repass" />
</div>
<div class="login_line">
<label for="email"> email </label>
<input type="email" name="email" id="email" placeholder="email" />
</div>
<div class="login_line">
<label for="phonenum"> phone num</label>
</div>
<div class="login_line">
<input type="text" id="phonenum" name="phonenum" placeholder="phone num" />
<select id="select">
<option value="050"> 050</option>
<option value="054"> 054</option>
<option value="052"> 052</option>
<option value="053"> 053</option>
<option value="058"> 058</option>
</select>
</div>
</div>
<div class="login_line">
<div id="result"> </div>
</div>
<div class="send_line">
<button type="submit" name="send" id="send"> reg</button>
</div>
</form>
here the php
include_once 'login_db.php';
$error_msg="";
if(isset($_POST['send']))
{
And the rest there include the echo somehow without the if isset($_POST['send'])
the code is echo the result
I have a contact form that is working fine, it sends the email except that it doesn't post the email address of the person that sends it. I have no idea why, I tried changing the $from variable and nothing changes. Is there something obvious I am missing?
It is the input with the id c_email which is put into the $from variable that I do not receive in the emails sent by this form.
My contactform.php:
<?php
// Contact
$to = 'myemail#gmail.com';
$subject = 'Portfolio ContactForm';
if(isset($_POST['c_name']) && isset($_POST['c_email']) && isset($_POST['c_message'])){
$name = $_POST['c_name'];
$from = $_POST['c_email'];
$message = $_POST['c_message'];
if (mail($to, $subject, $from, $name, $message)) {
$result = array(
'message' => 'Sent, thanks!',
'sendstatus' => 1
);
echo json_encode($result);
} else {
$result = array(
'message' => 'Ooops, problem..',
'sendstatus' => 1
);
echo json_encode($result);
}
}?>
On my html page:
<form id="contact-form" role="form">
<div class="form-group">
<label class="sr-only" for="c_name">Name</label>
<input type="text" id="c_name" class="form-control" name="c_name" placeholder="Nom">
</div>
<div class="form-group">
<label class="sr-only" for="c_email">Email address</label>
<input type="email" id="c_email" class="form-control" name="c_email" placeholder="E-mail">
</div>
<div class="form-group">
<textarea class="form-control" id="c_message" name="c_message" rows="7" placeholder="Votre message"></textarea>
</div>
<button type="submit" class="btn btn-custom-1">
<i class="fa fa-bullhorn icon-before"></i> Envoyer
</button>
</form>
Your values is not posting because in your form you not mention method="POST".Just try like this.it should work
<form id="contact-form" role="form" action="" method="POST">
<div class="form-group">
<label class="sr-only" for="c_name">Name</label>
<input type="text" id="c_name" class="form-control" name="c_name" placeholder="Nom">
</div>
<div class="form-group">
<label class="sr-only" for="c_email">Email address</label>
<input type="email" id="c_email" class="form-control" name="c_email" placeholder="E-mail">
</div>
<div class="form-group">
<textarea class="form-control" id="c_message" name="c_message" rows="7" placeholder="Votre message"></textarea>
</div>
<button type="submit" class="btn btn-custom-1">
<i class="fa fa-bullhorn icon-before"></i> Envoyer
</button>
</form>
<script>
$('button').click(function() {
var c_name = $("#c_name").val();
var c_email = $("#c_email").val();
var c_message = $("#c_message").val();
$.ajax({//create an ajax request to load_page.php
type: "POST",
url: "assets/php/contactForm.php",
data:{"c_name":c_name,"c_email":c_email,"c_message":c_message},
success: function(data) {
if (data) {
alert(data);
}
else {
alert('Successfully not posted.');
}
}
});
});
</script>
I have a registration form for my website, and it is showing username, password and password confirmation required although i am providing all of these. This is the controller code:
{
$this->load->library('form_validation');
$this->form_validation->set_rules('username','Username','trim|required|min_length[4]|xss_clean');
$this->form_validation->set_rules('email','Email','trim|required|valid_email');
$this->form_validation->set_rules('pass1','Password','trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('pass2','Password Confirmation','trim|required|matches[pass1]');
if ($this->form_validation->run() === FALSE)
{
$password = $this->input->post('pass1');
echo json_encode(array('error' => '1', 'message' => validation_errors('<div class="alert alert-error"><strong>Error!</strong> ', '</div>')));
}
else
{
$username = $this->input->post('username');
$password = $this->input->post('pass1');
$email = $this->input->post('email');
$date = date('Y/m/d H:i:s');
$this->load->model('ui_model');
$this->ui_model->register_user($username,$password,$email,$date);
echo json_encode(array('error' => '0', 'message' => '<div class="alert alert-success"><strong>Success!</strong> You have been registered!</div>'));
}
and this is the view code:
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Registration</h3>
</div>
<div class="modal-body">
<div id="registerModalerror" style="display: none;"></div>
<?php
$attributes = array('class' => 'form-horizontal','id' => 'registerModalform');
echo form_open('',$attributes);
?>
<div class="control-group">
<label class="control-label" for="Username">Username</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input type="text" id="inputUser" placeholder="Username" name="username" value ="" >
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-envelope"></i></span>
<input type="text" id="inputEmail" placeholder="email" name="email" value = "">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-lock"></i></span>
<input type="password" id="inputPassword" placeholder="Password" name="pass1" value = "">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword2">Retype Password</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-lock"></i></span>
<input type="password" id="inputPassword2" placeholder="Retype Password" name="pass2" value = "">
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Register</button>
</div>
</div>
</div>
<?php echo form_close(); ?>
<div class="modal-footer">
</div>
</div>
<script>
$(document).ready(function() {
$('#myModalReg').removeData('modal');
$('#myModalReg').hide();
$('#registerModalform').submit(registerUser);
});
function registerUser(event)
{
//Stop the form from submitting
event.preventDefault();
//Collect our form data.
var form_data = {
username : $("[name='username']").val(),
password1 : $("[name='pass1']").val(),
password2 : $("[name='pass2']").val(),
email : $("[name='email']").val()
};
//Begin the ajax call
$.ajax({
url: "http://localhost/fys/index.php/ui/do_register",
type: "POST",
data: form_data,
dataType: "json",
cache: false,
async : false,
success: function (json) {
// alert(json.pass);
if (json.error==1)
{
$('#registerModalerror').html(json.message).show();
}
else {
//Hide our form
$('#registerModalform').slideUp();
//Show the success message
$('#registerModalerror').html(json.message).show();
}
},
error: function(json)
{
alert(json.message);
}
});
}
</script>
I am not sure where it went wrong, and it is bugging me for almost 24 hours. Can anyone provide some help?
Thanks!
Your POST object is
{
username : $("[name='username']").val(),
password1 : $("[name='pass1']").val(),
password2 : $("[name='pass2']").val(),
email : $("[name='email']").val()
}
But your Controller's POST name is pass1 and pass2. You're passing up password1 and password2
:P