Create a table together with nested objects (columns) - spring

In my Spring MVC application I am trying to build a complex form, where a table and the tables columns can be created at once.
When I submit my form, the table is created with all attributes, but it has not columns. Whats wrong with the nested objects?
This is my view:
<form id="form2" class="form-horizontal" action="/Weasy/virtualtable/insert" method="post">
<input type="hidden" id="isVirtual" name="isVirtual" value="true"/>
<input type="hidden" id="query" name="query" value="select * from aktie"/>
<input type="hidden" id="schema" name="schema" value="40"/>
<div class="form-group">
<div class="row">
<label class="col-sm-2 control-label" for="name"><i>Column No</i></label>
<label class="col-sm-2 control-label" for="name"><i>Column Name</i></label>
<label class="col-sm-2 control-label" for="name"><i>Database Type</i></label>
</div>
<div class="row">
<label class="col-sm-2 control-label" for="name"><i>0</i></label>
<label class="col-sm-2 control-label" for="name"><i>ID</i></label>
<div class="col-sm-5">
<input type="hidden" class="form-control" name="obj.columns[0].name" value="ID" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[0].datatype" value="INTEGER , Size: 11" placeholder="specify datatype">
</div>
</div>
<div class="row">
<label class="col-sm-2 control-label" for="name"><i>1</i></label>
<label class="col-sm-2 control-label" for="name"><i>BESCHREIBUNG</i></label>
<div class="col-sm-5">
<input type="hidden" class="form-control" name="obj.columns[1].name" value="BESCHREIBUNG" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[1].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</div>
</div>
<div class="row">
<label class="col-sm-2 control-label" for="name"><i>2</i></label>
<label class="col-sm-2 control-label" for="name"><i>ISIN</i></label>
<div class="col-sm-5">
<input type="hidden" class="form-control" name="obj.columns[2].name" value="ISIN" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[2].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</div>
</div>
<div class="row">
<label class="col-sm-2 control-label" for="name"><i>3</i></label>
<label class="col-sm-2 control-label" for="name"><i>WKN</i></label>
<div class="col-sm-5">
<input type="hidden" class="form-control" name="obj.columns[3].name" value="WKN" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[3].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</div>
</div>
<div class="row">
<label class="col-sm-2 control-label" for="name"><i>4</i></label>
<label class="col-sm-2 control-label" for="name"><i>NAME</i></label>
<div class="col-sm-5">
<input type="hidden" class="form-control" name="obj.columns[4].name" value="NAME" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[4].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="name"><i>Source Table</i></label>
<div class="col-sm-5">
<input type="text" class="form-control" id="name" name="name"
value="" placeholder="Virtual Table Name" required>
</div>
</div>
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-2">
<input id="execQry" class="btn btn-block btn-primary btn-default"
type="submit" value="Save"
>
</div>
</div>
</div>
</form>
And this is the corresponding method of my controller. When I debug it, I see the table, but it has no columns.
#RequestMapping("insert")
public ModelAndView insert(#ModelAttribute SrcTable obj) {
return update(obj);
}

In your HTML you are trying to simulate a table with bootstrap, if you take a look at http://getbootstrap.com/css/#forms in form-horizontal section it can give you a more table-like structure, but in this case i recommend a table structure inside your form.
Example:
<input type="hidden" id="isVirtual" name="isVirtual" value="true"/>
<input type="hidden" id="query" name="query" value="select * from aktie"/>
<input type="hidden" id="schema" name="schema" value="40"/>
<table class="table">
<thead>
<tr>
<th><i>Column No</i></th>
<th><i>Column Name</i></th>
<th><i>Database Type</i></th>
</tr>
</thead>
<tbody>
<tr>
<td><i>0</i></td>
<td><i>ID</i></td>
<td>
<input type="hidden" class="form-control" name="obj.columns[0].name" value="ID" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[0].datatype" value="INTEGER , Size: 11" placeholder="specify datatype">
</td>
</tr>
<tr>
<td><i>1</i></td>
<td><i>BESCHREIBUNG</i></td>
<td>
<input type="hidden" class="form-control" name="obj.columns[1].name" value="BESCHREIBUNG" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[1].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</td>
</tr>
<tr>
<td><i>2</i></td>
<td><i>ISIN</i></td>
<td>
<input type="hidden" class="form-control" name="obj.columns[2].name" value="ISIN" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[2].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</td>
</tr>
<tr>
<td><i>3</i></td>
<td><i>WKN</i></td>
<td>
<input type="hidden" class="form-control" name="obj.columns[3].name" value="WKN" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[3].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</td>
</tr>
<tr>
<td><i>4</i></td>
<td><i>NAME</i></td>
<td>
<input type="hidden" class="form-control" name="obj.columns[4].name" value="NAME" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[4].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</td>
</tr>
</tbody>
</table>
<input id="execQry" class="btn btn-block btn-primary btn-default"
type="submit" value="Save"
>
</form>

While looking this over after a day pause, I found my error.
instead of
<input type="hidden" class="form-control" name="obj.columns[4].name" value="NAME" placeholder="specify name">
I had to use
<input type="hidden" class="form-control" name="columns[4].name" value="NAME" placeholder="specify name">

Related

how to disable input when the value is empty laravel livewire

i am using livewire , laravel 7. Below is the code. How to make sure the input is readonly when the value is empty?
<div class="form-row">
#foreach($serviceOrder as $o)
<div class="col-md-5 mb-3">
<label class="form-control-label" >Service {{ $loop->iteration }} </label>
<input type="text" wire:model="serviceOrder.{{ $loop->index }}.serv.serviceName" class="form-control " readonly>
</div>
<input type="hidden" wire:model="serviceOrder.{{ $loop->index }}.serv.servicePrice" class="form-control col-sm-1 mb-3" readonly>
<div class="col-md-3 mb-3">
<label class="form-control-label" >Weight/Size</label>
<input type="text" name="" value="" wire:model="serviceOrder.{{ $loop->index }}.weightsize" class="form-control">
</div>
<div class="col-md-3 mb-3">
<label class="form-control-label" >Quantity*opt</label>
<input type="text" name="" value="" wire:model="serviceOrder.{{ $loop->index }}.quantity" class="form-control" #if(!$quantity) readonly #endif >
</div>
#endforeach
</div>
the one i am focusing is this part
<div class="col-md-3 mb-3">
<label class="form-control-label" >Quantity*opt</label>
<input type="text" name="" value="" wire:model="serviceOrder.{{ $loop->index }}.quantity" class="form-control" #if(!$quantity) readonly #endif >
</div>
for the input that has no value, should be " ", it is a nullable variable for quantity
try adding this check in the element:
<input type="text" wire:model="serviceOrder.{{ $loop->index }}.quantity" class="form-control" #if(!$serviceOrder[$loop->index]['quantity']) readonly #endif>

PHP Laravel Post action

I have a form page for users informations update but my post function isn't working.I have defined a post method in the blade page and I show the page as a formaction post.This is my code;
#extends('layouts.admin-master')
#section('content')
<form action="post">
<div class="form-row">
<div class="form-group">
<label for="inputAddress2">Ad Soyad</label>
<input type="text" class="form-control" id="inputAddress2" name="name" value="{{ Auth::user()->name }}">
</div>
<br><br>
<div class="form-group">
<label for="inputAddress2">Şirket</label>
<input type="text" class="form-control" id="inputAddress2" name="company">
</div>
</div>
<div class="form-group">
<label for="inputAddress">Email</label>
<input type="text" class="form-control" id="inputAddress" name="email" value="{{ Auth::user()->email }}">
</div>
<div class="form-group">
<label for="inputAddress2">Telefon</label>
<input type="text" class="form-control" id="inputAddress2" name="phone">
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputState">Üyelik Tipi</label>
<select id="inputState" class="form-control">
<option selected>Seçenekler</option>
<option>Bronz Üyelik</option>
<option>Silver Üyelik</option>
<option>Gold Üyelik</option>
</select>
</div>
<div class="form-group col-md-2">
<label class="radio-container m-r-55">Tedarikçi
<input type="radio" checked="checked" name="secim" value="tedarikci">
<span class="checkmark"></span>
</label>
`enter code here` <label class="radio-container">Alıcı
<input type="radio" name="secim" value="alici">
<span class="checkmark"></span>
</label>
</div>
</div>
<form action="{{route('form.add')}}" method="post" enctype="multipart/form-data">
<button type="submit" class="btn btn-primary">Kaydet</button>
</form>
</form>
#endsection
try this:
#extends('layouts.admin-master')
#section('content')
<form action="{{route('form.add')}}" method="post" enctype="multipart/form-data">
<div class="form-row">
<div class="form-group">
<label for="inputAddress2">Ad Soyad</label>
<input type="text" class="form-control" id="inputAddress2" name="name" value="{{ Auth::user()->name }}">
</div>
<br><br>
<div class="form-group">
<label for="inputAddress2">Şirket</label>
<input type="text" class="form-control" id="inputAddress2" name="company">
</div>
</div>
<div class="form-group">
<label for="inputAddress">Email</label>
<input type="text" class="form-control" id="inputAddress" name="email" value="{{ Auth::user()->email }}">
</div>
<div class="form-group">
<label for="inputAddress2">Telefon</label>
<input type="text" class="form-control" id="inputAddress2" name="phone">
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputState">Üyelik Tipi</label>
<select id="inputState" class="form-control">
<option selected>Seçenekler</option>
<option>Bronz Üyelik</option>
<option>Silver Üyelik</option>
<option>Gold Üyelik</option>
</select>
</div>
<div class="form-group col-md-2">
<label class="radio-container m-r-55">Tedarikçi
<input type="radio" checked="checked" name="secim" value="tedarikci">
<span class="checkmark"></span>
</label>
`enter code here` <label class="radio-container">Alıcı
<input type="radio" name="secim" value="alici">
<span class="checkmark"></span>
</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Kaydet</button>
</form>
put this line in your form and it should work :
{{csrf_field()}}
and make sure that your route address is correct too
u can add #csrf above the button

Laravel csrf_field() Is Blank

I am learning about Packages in Laravel 5.4 and ultimately I will upload them to github.
This is my directory structure :
laravel
-vendor
--student
---myPackage
----src
-----Views
------myView.blade.php
the myView.blade.php has a form in it, and a {{csrf_field()}} function call, but when I inspect the output in the browser, the value attribute of the hidden input <input name="_token" value="" type="hidden"> is empty.
How do I make this work ?
SOLUTION
Apparantly, I needed to make sure that the web middleware is in use
for my routes, so I changed Route::get('/Register/{group}',
'Student\myPackage\Http\User#create'); to
Route::get('/Register/{group}',
'Student\myPackage\Http\User#create')->middleware('web');
Route:
Route::get('/Register/{group}', 'Student\myPackage\Http\User#create');
Route::post('/Register/{group}', 'Student\myPackage\Http\User#store');
Controller:
public function create($group){
return view('StudentUser::app', ['group' => $group]);
}
public function store($group)
{
dd(request()->all());
}
Form:
<form class="form-horizontal" role="form" method="POST" action="/Register/{{$group}}">
<div class="tab-content">
<div id="ap-about" class="tab-pane active">
{!! csrf_token() !!}
<div class="form-group">
<label for="name" class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="" required autofocus>
</div>
</div>
<div class="form-group">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="" required>
</div>
</div>
<div class="form-group">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
</div>
</div>
<div class="form-group">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="button" class="btn btn-primary">
Next
</button>
</div>
</div>
</div>
<div id="ap-personal" class="tab-pane">
<div class="form-group">
<label for="address" class="col-md-4 control-label">Address</label>
<div class="col-md-6">
<input id="address" type="text" class="form-control" name="personal[]" value="" required autofocus>
</div>
</div>
<div class="form-group">
<label for="url" class="col-md-4 control-label">url</label>
<div class="col-md-6">
<input id="url" type="text" class="form-control" name="personal[]" value="" required autofocus>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Register
</button>
</div>
</div>
</div>
</div>
</form>

How to validate multiple value (Array of value ) in single Input (form) in codeigniter

this is the html part when i add more email id's only first email is being validated and rest of emails treat as normal even if they are not in proper
<form action="<?php echo base_url()?>index.php/EMail/show_email">
<div class="form-group">
<label for="exampleInputEmail1">To :</label>
<input type="email" name="toa[]" ng-model="to" placeholder="To" class=" tagsinput" value="ss" />
</div>
<div class="form-group">
<label for="exampleInputEmail1">Subject :</label>
<input type="text" class="form-control" ng-model="sub" name="suba" id="exampleInputEmail1" placeholder="Subject">
<div>{{sub}}</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">CC :</label>
<input type="text" class="form-control" ng-model="to" name="cca" id="exampleInputEmail1" placeholder="CC">
<div>{{to}}</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">BCC:</label>
<input type="text" class="form-control" name="bcca" id="exampleInputEmail1" placeholder="BCC">
</div>
<div class="form-group ">
<label for="ccomment" class="control-label">Message</label>
<textarea class="form-control " id="ccomment" name="msg" required></textarea>
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" id="exampleInputFile">
<p class="help-block">Example block-level help text here.</p>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Check me out
</label>
</div>
<input type="submit" onclick="mail()" class="btn btn-primary" value="Send"/>
<button type="submit" class="btn btn-Success">Draft</button>
</form>
this is my controller and "toa "is that field which i mentioned in the image
function show_email(){
$this->form_validation->set_rules("toa[]","To","valid_email");
$this->form_validation->set_rules("cca","CC ","valid_email");
$this->form_validation->set_rules("suba","Subject","required");
$this->form_validation->set_rules("bcca","bcc","valid_email");
$this->form_validation->set_rules("msg","Message","required");
if($this->form_validation->run()==FALSE){
$data["title"]="EMail";
$this->load->view('header',$data);
$this->load->view('sidebar');
$this->load->view('Mail/mail');
}else{
//finish
$ccdata=$this->input->post("cca");
$bccdata=$this->input->post("bcca");
$sub=$this->input->post("suba");
$ms=$this->input->post("msg");
$dataa["username"]="MyProject";
$dataa["msg"]=$ms;
$msg=$this->load->view('Email_Temp/mail',$dataa,TRUE);
$todata=explode(",",$data);
print_r($todata[0]);
//$this->SendEmail($todata,$ccdata,$bccdata,$msg,$sub);
}
}
[Image] this is the field (to) that i want to validate

how to save data/records from html form to DB2 database

this is my html form
<form class="form-horizontal" id="myCredantials" >
<div class="form-group">
<label class="col-sm-2 control-label">Username : </label>
<div class="col-sm-10 col-md-2">
<input type="text" class="form-control" id="tbUsername" placeholder="Username">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Email : </label>
<div class="col-sm-10 col-md-2">
<input type="text" class="form-control" id="tbEmail" placeholder="Email">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Gender : </label>
<div class="col-sm-10 col-md-2">
<select id="cbmGender">
<option value="-1">Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Date : </label>
<div class="col-sm-10 col-md-2">
<input type="text" class="form-control" id="tbDate">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Price : </label>
<div class="col-sm-10 col-md-2">
<input type="text" class="form-control" value="0" id="tbPrice" placeholder="Prices">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Perc % : </label>
<div class="col-sm-10 col-md-2">
<input type="text" class="form-control" value="0" id="tbPercentage" placeholder="%">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Password : </label>
<div class="col-sm-10 col-md-2">
<input type="password" class="form-control" id="tbPassword" placeholder="Password">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Confirm Password : </label>
<div class="col-sm-10 col-md-2">
<input type="password" class="form-control" id="tbConfirmpassword" placeholder="Confirm">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="button" class="btn btn-primary " id="btnSubmit" onclick="onSave()" value="Save" >
<input type="button" class="btn btn-primary " id="btnClear" onclick="onClearError()" value="Remove Error" >
<input type="button" class="btn btn-primary " id="btnGet" onclick="doGet()" value="Get" >
<input type="button" class="btn btn-primary " id="btnGet" onclick="doPost()" value="Post" >
</div>
</div>
<div style="width:700px;">
<table cellpadding="0" cellspacing="0" border="0" width="700" id="tbl_Credantials">
</table>
</div>
</form>

Resources