how to set and get checked or unchecked values in single checkbox using another form - laravel

i want to set value and retrieved value in the checkbox field when submitting a value from another form hidden filed.
<form action="store" method="post">
<div class="form-group">
<div class="row">
<label class="control-label col-lg-3"><b>Enable/Disable App</b>
</label>
<label class="Sg-switch">
<input type="checkbox" name="is_active" value="<?php $_POST['enable']; ?>"<?php if (isset($setting['is_active'])==1) { ?> checked="checked" <?php } ?>><span class="Sg-slider round"></span>
</label>
</div>
<div class="clearfix"></div>
<div class="form-group">
<button type="submit" class="sg-main-btn sg-primary-tn">Save</button>
My submit form is:-
<div class="modal-body">
<form class="form-horizontal" method="post" action="#" name="enable">
<div class="modal-footer" style="text-align:center;">
<input type="text" name="is_active" value="1" hidden>
<button type="submit" name="enable" class="sg-main-btn sg-success-btn dis_btn"><i class="fa fa-check"></i><i class="fa fa-spin fa-spinner" style="display: none;"></i>Yes</button>
<i class="fa fa-times"></i>No
</div>
</form>

you can use jquery.
Give your input id like id = "input".
<input type="text" name="is_active" value="1" hidden id = 'input'>
<input type="checkbox" id="input_new" name="is_active" value="<?php $_POST['enable']; ?>"<?php if (isset($setting['is_active'])==1) { ?> checked="checked" <?php } ?>>
<span class="Sg-slider round"></span>
<button id="button1">also add yourclass and type etc</button>
$('#button1').click( function() {
var active = $('#input').val();
if(active == 1){
$('#input_new').attr('checked');
}});

Related

in my laravel project some datas are not passed to controller from form submit.What could be the reasons?

in my laravel project i have made a form with input field name,size,price,etc. My problem is that when i type name in name field datas arenot passed to controller.This is happening only to some specific names.For some other names working fine.And this problem is raised in live in local working fine
below is form blade
<form class="form-horizontal form-label-left" method="post"
action="{{route('product')}}" enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-group col-lg-6" >
<label for="select-from">Select Catagory:<span class="required" style="color:red;">*</span></label>
<select class="form-control" id="category" name="category">
<option value="">Choose</option>
#foreach($allcategory as $cat)
<option value="{{$cat->id}}">{{$cat->name}}</option>
#endforeach
</select>
</div>
<script type="text/javascript">
$(document).ready(function(){
$(document).on('change','#category',function(){
var a = $(this).val();
$.ajax({
type:'get',
url: '{{URL::to('#dashboard#/childcategory-section/submenu-choose')}}',
data:{'id':a},
success:function(datas){
$("select#submenu").empty();
$.each(datas,function(i,data){
$("select#submenu").append('<option value="'+data.id+'"> '+data.name+'</option>');
});
}
});
});
});
</script>
<div class="form-group col-lg-6" >
<label for="select-from">Select SubCategory:<span class="required" style="color:red;">*</span></label>
<select name="submenu_id" id="submenu" class="form-control">
<option value="">Choose</option>
</select>
</div>
<div class="form-group col-lg-12">
<label for="category">Product Name <span class="required" style="color:red;">*</span> </label>
<div>
<input type="text" name="name" required class="form-control">
</div>
</div>
<div class="form-group col-lg-6">
<label for="category">Image <span class="required" style="color:red;">*</span> </label>
<div>
<input type="file" name="image" required class="form-control">
</div>
</div>
<div class="form-group col-lg-12">
<label for="category">Old Price <span class="required" style="color:red;">*</span> </label>
<div>
<input type="text" name="old_price" required class="form-control">
</div>
</div>
<div class="form-group col-lg-12">
<label for="category">New Price <span class="required" style="color:red;">*</span> </label>
<div>
<input type="text" name="new_price" required class="form-control">
</div>
</div>
<script src="{{URL::to('ckeditorfull/ckeditor/ckeditor.js')}}"></script>
<div class="form-group col-lg-12">
<label for="category">Detail <span class="required" style="color:red;">*</span> </label>
<div>
<textarea class="form-control" id="detail" name="detail" ></textarea>
</div>
</div>
<script>
CKEDITOR.replace( 'detail');
</script>
<div class="ln_solid"></div>
<div class="form-group ">
<div>
<button type="submit" class="btn btn-success pull-right" style="background: #1abb9c;">Submit</button>
</div>
</div>
below is controller
public function add_action(Request $request){
//dd($request->all());
$datas=new Product();
$this->validate($request,['name'=>'required|unique:products',
'image'=>'required',
'old_price'=>'required',
'new_price'=>'required',
'detail'=>'required',
'total_products'=>'required',
'size'=>'required',
'total_sizeproducts'=>'required']);
$datas->category_id=$request->category;
$datas->menu_id=$request->submenu_id;
$datas->name=$request->name;
$datas->slug=str_slug($request->name);
if($request->hasFile('image')){
$file=$request->file('image');
$filename=time().$file->getClientOriginalName();
$file->move(public_path().'/backend/images/products/',$filename);
$datas->image=$filename;
}
$datas->new_price=$request->new_price;
$datas->old_price=$request->old_price;
$datas->rating=$request->rating;
$datas->brand=$request->brand;
$datas->availability=$request->availability;
$datas->total_products=$request->total_products;
$datas->discount=$request->discount;
$datas->detail=$request->detail;
$datas->save();
}
return redirect()->back()->with('success','products added successfully!!!');
}
below is route
Route::group(['namespace'=>'product','prefix'=>'product','middleware'=>'auth'],function (){
Route::get('/','ProductController#add')->name('product');
Route::post('/','ProductController#add_action');
});
Post some code. But you can use dd($request) and you will be able to see the data thats being sent to the controller. Make sure you are using the correct route for that action.

Laravel Dynamic Form Submit not responding

I have a controller ( Laravel ) which will be dynamic create a form as below
<div class="row" style="margin-bottom:30px;margin-top:20px;">
<div class="col-2">
<form class="addform" id="newcheckform" role="form">
'.csrf_field().'
<label class="" for="cust_code">Cust Code</label>
<input type="text" class="form-control" id="cust_code" value="'.$row->cust_no.'">
</div>
<div class="col-2">
<label class="" for="cust_short">Cust Shortname</label>
<input type="text" class="form-control" id="cust_short">
</div>
<div class="col-4">
<label class="" for="cust_name">Cust Name</label>
<input type="text" class="form-control" id="cust_name" value="'.$row->cust.'">
</div>
<div class="col-2">
<label class="" for="region">Region</label>
<input type="text" class="form-control" id="region">
</div>
<div class="col-2">
<label class="" for="region">Add Cust Data</label>
<button class="btn btn-sm btn-info" id="createnewcust" type="submit">Create</button>
</form>
</div>
</div>
if will be loaded by below script in the blade file
$("#custcheck").load("{{ url('/sales/admin/custcheck') }}");
The form displayed as its should to be.
However I when I submit button. Nothing happened. code as below. Appreciate anyone can help. this script resides in the same blade file.
$(function() {
$(document).on('submit', '#newcheckform', function(e){
alert("Hi");
});
});
You have wrong closing tags for <form> change something like this:
<div class="row" style="margin-bottom:30px;margin-top:20px;">
<form class="addform" id="newcheckform" role="form">
{{csrf_field()}}
<div class="col-2">
<label class="" for="cust_code">Cust Code</label>
<input type="text" class="form-control" id="cust_code" value="{{$row->cust_no}}">
</div>
<div class="col-2">
<label class="" for="cust_short">Cust Shortname</label>
<input type="text" class="form-control" id="cust_short">
</div>
<div class="col-4">
<label class="" for="cust_name">Cust Name</label>
<input type="text" class="form-control" id="cust_name" value="{{$row->cust}}">
</div>
<div class="col-2">
<label class="" for="region">Region</label>
<input type="text" class="form-control" id="region">
</div>
<div class="col-2">
<label class="" for="region">Add Cust Data</label>
<button class="btn btn-sm btn-info" id="createnewcust" type="submit">Create</button>
</div>
</form>
</div>
This will work.

how to select and show data comment by id post in codeigniter

master peace of codeigniter. im new user for this framework.
i have problem to show comment data by id_diskusi in the single post of diskusi. i try to show data using 'where' in the lybrary code but its still not show the data. i hope the people at there can help me & solved this problem.
i use library to get data from database
public function setuju(){
$data=$this->CI->db->query("SELECT komentar.id AS id,
komentar.diskusi_id AS id_diskusi,
komentar.pilih AS pilih,
komentar.nama AS nama,
komentar.email AS email,
komentar.pesan AS pesan,
komentar.tanggal AS tanggal,
diskusi.diskusi_id as nomor_diskusi
FROM diskusi, komentar
WHERE diskusi.diskusi_status='publish' AND komentar.pilih='1' AND komentar.diskusi_id=diskusi.diskusi_id ORDER BY komentar.id DESC
");
return $data->result_array();
}
i use this code to filter data who data on komentar will be show by id of diskusi.
komentar.diskusi_id=diskusi.diskusi_id
but still not work
and its my controller
$data['setuju']=$this->diskusi->setuju();
code in the view
<div id="netral" class="tab-pane">
<?php
foreach ($netral AS $value) {
echo "<div class='box box-body no-border'>
<div class='row'>
<div class='col-md-2'>
<div class='box-profile'>"; ?>
<img alt='user image' style='margin-top:10px' class='profile-user-img img-responsive img-circle' src='<?php echo img_user_url('user.png'); ?>'>
<?php echo"
<h3><center>$value[nama]</center</h3>
</div>
</div>
<div class='col-md-10'>
<div class='callout callout-danger lead'><span class='pull-right'>".format_tanggal($value['tanggal'])."</span><br>
<p>$value[pesan]</p>
</div>
</div>
</div>
</div>";
}?>
</div><!-- /.tab-pane -->
<div class="box box-danger">
<div class="box-header with-border">
<div class="user-block">
<h3 class="no-margin">Tinggalkan Komentar</h3>
</div><!-- /.user-block -->
<div class="box-tools">
<button data-widget="collapse" class="btn btn-danger btn-sm"><i class="fa fa-minus"></i></button>
</div><!-- /.box-tools -->
</div>
<div class="box-body">
<form method='POST' id='komentar' action='<?php echo baseURL('form_visitors/komentar'); ?>' autocomplete='off' method="post" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="inputName">Name</label>
<div class="col-sm-10">
<input type="hidden" name="diskusi_id" value="<?php echo "$diskusi[id]";?>">
<input type="text" placeholder="Nama" data-original-title="Masukkan Nama" required='required' name="nama" id="inputName" class="form-control">
<input type='hidden' class='form-control' name='url' value='<?php echo current_url() ?>' />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="inputEmail">Email</label>
<div class="col-sm-10">
<input type="email" name="email" data-original-title="Masukkan Email" placeholder="Email" required='required' id="inputEmail" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-10">
<div class="checkbox">
<label>
<input type="radio" name="pilih" value="1"> <i class="fa fa-thumbs-o-up margin-r-5 text-green"> <b>Setuju</b></i>
</label>
<label>
<input type="radio" name="pilih" value="2"> <i class="fa fa-square margin-r-5 text-yellow"> <b>Netral</b></i>
</label>
<label>
<input type="radio" name="pilih" value="3"> <i class="fa fa-thumbs-o-down margin-r-5 text-red"> <b>Tidak Setuju</b></i>
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="inputExperience">Komentar</label>
<div class="col-sm-10">
<textarea placeholder="Komentar" name="pesan" id="inputExperience" required='required' class="form-control"></textarea>
</div>
</div>
<div class='form-group'>
<label class="col-sm-2 control-label" for="inputExperience"></label>
<div class="col-sm-10">
<div id='recaptcha1'></div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-danger" type="submit" id="submit">Submit</button>
<div class="cssload" style="display: none; width: 100px">
<div class="cssload-tube-tunnel"></div>
</div>
</div>
</div>
</form>
</div>
</div>
how can i show comment data according with single post of diskusi who have comment. Thank you very much in advance! sorry for my english.
I can see you are fetching the data from two different tables but you have not used 'JOIN'.
you can try the following query string :
public function setuju(){
$data=$this->CI->db->query("SELECT komentar.id AS id,
komentar.diskusi_id AS id_diskusi,
komentar.pilih AS pilih,
komentar.nama AS nama,
komentar.email AS email,
komentar.pesan AS pesan,
komentar.tanggal AS tanggal,
diskusi.diskusi_id as nomor_diskusi
FROM komentar, diskusi
JOIN diskusi
ON diskusi.diskusi_id=komentar.diskusi_id
WHERE diskusi.diskusi_status='publish' AND komentar.pilih='1' ORDER BY komentar.id DESC
");
return $data->result_array();
}

Page not getting refresh after form submission?

<form id="contact-form" action="<?=site_url()?>/main/add_contact" onsubmit="return Validate()" method="POST">
<div class="inline-inputs">
<div class="col-lg-6 col-md-6 col-sm-12">
<label>Name*</label>
<input type="text" name="username" id="username">
<?php if ($this->session->flashdata('username')) {?><b style="color: red"><?=$this->session->flashdata('username')?></b><?php }?>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<label>Phone*</label>
<input type="text" name="phone" id="phone">
<?php if ($this->session->flashdata('phone')) {?><b style="color: red"><?=$this->session->flashdata('phone')?></b><?php }?>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<label>Email Address*</label>
<input type="email" name="email" id="email">
<?php if ($this->session->flashdata('email')) {?><b style="color: red"><?=$this->session->flashdata('email')?></b><?php }?>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<label>Subject*</label>
<input type="text" name="subject" id="subject">
<?php if ($this->session->flashdata('subject')) {?><b style="color: red"><?=$this->session->flashdata('subject')?></b><?php }?>
</div>
<div class="col-lg-12 col-md-12 col-sm-12">
<label>Message*</label>
<textarea rows="10" cols="10" name="query" id="query"style = 'resize:none;'></textarea>
<?php if ($this->session->flashdata('query')) {?><b style="color: red"><?=$this->session->flashdata('query')?></b><?php }?>
</div>
</div>
<input type="submit" value="submit"/>
</form>
After this form submission the action goes to the method in the controller,there i have set with validation and kept
redirect(site_url().'/main/contact','refresh');
Even though the method exists in the controller why i dont no the page is not getting refresh after the form submission..
After the form submission the page should show the flash data,it is not getting refreshed,when i manually refresh the page after the submission then i can see the flashdata..

Stripe form not submitting

My stripe form is not submitting. When I press submit it goes to page cannot be displayed. I replaced the route code to resolve to an echo "test"; and the post request shows the echo. Any help would be appreciated. This code is from a tutorial http://www.sitepoint.com/selling-downloads-stripe-laravel/
Route
Route::get('/buy/{id}', function($id)
{
$download = Download::find($id);
return View::make('buy', array('download' => $download));
});
Route::post('/buy/{id}', function($id)
{
Stripe::setApiKey(Config::get('laravel-stripe::stripe.sk_test_aaaaaaaaaaaaaaaaaaaaaaaa'));
$download = Download::find($id);
$token = Input::get('stripeToken');
// Charge the card
try {
$charge = Stripe_Charge::create(array(
"amount" => $download->price,
"currency" => "gbp",
"card" => $token,
"description" => 'Order: ' . $download->name)
);
// If we get this far, we've charged the user successfully
Session::put('purchased_download_id', $download->id);
return Redirect::to('confirmed');
} catch(Stripe_CardError $e) {
// Payment failed
return Redirect::to('buy/'.$id)->with('message', 'Your payment has failed.');
}
});
View
#extends('layouts.default')
#section('content')
<h1>Your Order</h1>
<h2>{{ $download->name }}</h2>
<p>£{{ ($download->price/100) }}</p>
<form action="" method="POST" id="payment-form" role="form">
<input type="hidden" name="did" value="{{ $download->id }}" />
<div class="payment-errors alert alert-danger" style="display:none;"></div>
<div class="form-group">
<label>
<span>Card Number</span>
<input type="text" size="20" data-stripe="number" class="form-control input-lg" />
</label>
</div>
<div class="form-group">
<label>
<span>CVC</span>
<input type="text" size="4" data-stripe="cvc" class="form-control input-lg" />
</label>
</div>
<div class="form-group">
<label>
<span>Expires</span>
</label>
<div class="row">
<div class="col-lg-1 col-md-1 col-sm-2 col-xs-3">
<input type="text" size="2" data-stripe="exp-month" class="input-lg" placeholder="MM" />
</div>
<div class="col-lg-1 col-md-1 col-sm-2 col-xs-3">
<input type="text" size="4" data-stripe="exp-year" class="input-lg" placeholder="YYYY" />
</div>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg">Submit Payment</button>
</div>
</form>
#stop

Resources