I am developing a multi choice questionaire. I want to get the answered question of the student. How do I go about it?
My Code
<div class="car card-body" style="border: #d3d3d3 1px solid; padding: 2rem">
1. Don't do tath <br />
<div style="padding-top: 1rem;">
<input type="hidden" name="question_id" value=2TpZL1kJjUj7XNysyqSk">
<input type="radio" name="option[1]" id="" style="display:inline"
value="a">
1. Computer is an electronic device
<br />
<input type="hidden" name="question_id" value="2TpZL1kJjUj7XNysyqSk">
<input type="radio" name="option[1]" id="" style="display:inline"
value="b">Computer is human
<br />
<input type="hidden" name="question_id" value="2TpZL1kJjUj7XNysyqSk">
<input type="radio" name="option[1]" id="" style="display:inline"
value="c">in hime i came
<br />
</div>
</div>
<br />
<div class="car card-body" style="border: #d3d3d3 1px solid; padding: 2rem">
2. What is Web Development <br />
<div style="padding-top: 1rem;">
<input type="hidden" name="question_id" value="8qbpQJ2ob4RvlcEJzszY">
<input type="radio" name="option[2]" id="" style="display:inline" value="a">development involved database management
<br />
<input type="hidden" name="question_id" value="8qbpQJ2ob4RvlcEJzszY">
<input type="radio" name="option[2]" id="" style="display:inline"
value="b">
web development involves the design of the law
<br />
<input type="hidden" name="question_id" value="8qbpQJ2ob4RvlcEJzszY">
<input type="radio" name="option[2]" id="" style="display:inline"
value="c">Web store is the absolute beginer
<br />
</div>
</div>
<div class="form-group mt-3">
<button type="submit" class="btn btn-primary btn-block">Submit</button>
</div>
Controller
public function submitExam(Request $request){
$myOption = $request->get('option');
$optioncount = count($myOption);
for($i=1; $i<$optioncount + 1; $i++){
echo $request->get("question_id");
echo $myOption[$i]. "<br />";
$option = Options::where('question_id', $question)->value('answer');
if($myOption[$i] == $option){
echo "Good";
}
}
}
I want to select from option where question id is the same and compare it the value of the selected radio button but I only get the question id of the first question. Can anyone help me? Thanks
I have finally solved it.
<div class="car card-body" style="border: #d3d3d3 1px solid; padding: 2rem">
<div style="padding-top: 1rem;">
<input type="hidden" name="question_id" value=2TpZL1kJjUj7XNysyqSk">
<input type="radio" name="option[1]" id="" style="display:inline" value="a">
1. Computer is an electronic device
<br />
<input type="hidden" name="question_id" value="2TpZL1kJjUj7XNysyqSk">
a. <input type="radio" name="option[1]" id="" style="display:inline" value="b">Computer is human
<br />
<input type="hidden" name="question_id" value="2TpZL1kJjUj7XNysyqSk">
<br />
b. <input type="radio" name="option[1]" id="" style="display:inline" value="c">computer is
</div>
</div>
Controller
$score = 0;
foreach ($request->input('question_id', []) as $key => $question) {
$answer = $request->input('option.'.$question);
$correctAnswer = Questions::where('question_id', $question)->value('answer');
if ($correctAnswer == $answer) {
$score++;
}
}
source
https://github.com/imran1234567/Online-Examination-System/blob/master/resources/views/tests/create.blade.php
https://github.com/imran1234567/Online-Examination-System/blob/master/app/Http/Controllers/TestsController.php
Related
am creating a rental house management web app whereby a tenant can only review and rate the house in which they are living in only. so in the view, I want to only show the form for the house when the user is logged in, whereby the user can only review that rental house and they can be able to see the form on any other rental house details page except for the rental house they occupies.
i just want only the user to reviewand rate the house they lives in and on the other house descriptions page they won't be able to see a review form.also a user should only have one review for their house house.I have tried this but it shows the for for other rental houses alsoinstead of hiding them.
this is the function that shows the rental house details
public function singlehsedetails ($rental_slug,$id){
$rentalhouse=Rental_house::with
('housetags','rentalalternateimages','houselocation','hsesusers')->find($id);
if (Auth::check())
{
$userrating=Houseratingreview::where(['user_id'=>Auth::user()->id,'hse_id'=>$rentalhouse->id])->first();
}
return view('Front.Rentalslisting.rentalhsedetails',compact('userrating','rentalhouse'));
this is is my blade file.
#if ($userrating ==null)
#else
<div class="card padding-card">
#auth
<div class="card-body" id="ratingdiv">
<h3 class="card-title mb-4">Rate and Review The House</h3>
<span class="font-weight-bold font-italic text-danger">Note:You Can Only Review and Rate Your The House Once</span>
<form id="rateandreviewhseform" method="POST" class="form-horizontal" action="javascript:void(0);">
#csrf
<input type="hidden" name="houseid" value="{{ $rentalhouse->id }}">
<input type="hidden" name="userid" value="{{ Auth::user()->id }}">
<div class="form-group" style="margin-top: 5px;">
<div class="row">
<div class="col-lg-8 col-md-8">
<label style="font-size: 15px;">Give a Star Rating for the House<span class="text-danger">*</span></label>
</div>
</div>
<div class="row">
<div class="col-lg-8 col-md-8">
<div class="rate">
<input type="radio" id="star5" name="rate" value="5" />
<label for="star5" title="text">5 stars</label>
<input type="radio" id="star4" name="rate" value="4" />
<label for="star4" title="text">4 stars</label>
<input type="radio" id="star3" name="rate" value="3" />
<label for="star3" title="text">3 stars</label>
<input type="radio" id="star2" name="rate" value="2" />
<label for="star2" title="text">2 stars</label>
<input type="radio" id="star1" name="rate" value="1" />
<label for="star1" title="text">1 star</label>
</div>
</div>
</div>
</div>
<p id="msg" style="font-size: 17px;"></p>
<br>
<div class="control-group form-group" style="margin-top: 2px;">
<div class="controls">
<label style="font-size: 15px;">Write A Review For The House <span class="text-danger">*</span></label>
<textarea style="border:2px solid black;" name="textreview" rows="10" cols="100" class="form-control" required></textarea>
</div>
</div>
<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>
#else
<p>To Review and Rate the House Create or Log In to your Account...</p>
<span href="#" data-toggle="modal" data-target="#signupmodal" class="btn btn-success btn-block">Create/Login an Account<i class="fa fa-angle-right"></i></span>
#endauth
</div>
#endif
in my users table i have a column "house_id" that store the house id for the user
this is my ratings and reviews table
public function singlehsedetails ($rental_slug,$id){
$rentalhouse=Rental_house::with
('housetags','rentalalternateimages','houselocation','hsesusers')->find($id);
$userrating=null;
$allowreview=false;
$currentuserlivinginhouse=false;
////check if user is living in the house
if(isset(Auth::user()->house_id) && Auth::user()->house_id==$id){
$currentuserlivinginhouse=true;
}
if (Auth::check())
{
$userrating=Houseratingreview::where(['user_id'=>Auth::user()->id,'hse_id'=>$rentalhouse->id])->first();
//if user is living in the house and rating not given then allow review
if($currentuserlivinginhouse && !isset($userrating->id)){
$allowreview=true;
}
}
return view('Front.Rentalslisting.rentalhsedetails',compact('userrating','rentalhouse','allowreview'));
}
Blade
#if ($allowreview)
<div class="card padding-card">
#auth
<div class="card-body" id="ratingdiv">
<h3 class="card-title mb-4">Rate and Review The House</h3>
<span class="font-weight-bold font-italic text-danger">Note:You Can Only Review and Rate Your The House Once</span>
<form id="rateandreviewhseform" method="POST" class="form-horizontal" action="javascript:void(0);">
#csrf
<input type="hidden" name="houseid" value="{{ $rentalhouse->id }}">
<input type="hidden" name="userid" value="{{ Auth::user()->id }}">
<div class="form-group" style="margin-top: 5px;">
<div class="row">
<div class="col-lg-8 col-md-8">
<label style="font-size: 15px;">Give a Star Rating for the House<span class="text-danger">*</span></label>
</div>
</div>
<div class="row">
<div class="col-lg-8 col-md-8">
<div class="rate">
<input type="radio" id="star5" name="rate" value="5" />
<label for="star5" title="text">5 stars</label>
<input type="radio" id="star4" name="rate" value="4" />
<label for="star4" title="text">4 stars</label>
<input type="radio" id="star3" name="rate" value="3" />
<label for="star3" title="text">3 stars</label>
<input type="radio" id="star2" name="rate" value="2" />
<label for="star2" title="text">2 stars</label>
<input type="radio" id="star1" name="rate" value="1" />
<label for="star1" title="text">1 star</label>
</div>
</div>
</div>
</div>
<p id="msg" style="font-size: 17px;"></p>
<br>
<div class="control-group form-group" style="margin-top: 2px;">
<div class="controls">
<label style="font-size: 15px;">Write A Review For The House <span class="text-danger">*</span></label>
<textarea style="border:2px solid black;" name="textreview" rows="10" cols="100" class="form-control" required></textarea>
</div>
</div>
<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>
#else
<p>To Review and Rate the House Create or Log In to your Account...</p>
<span href="#" data-toggle="modal" data-target="#signupmodal" class="btn btn-success btn-block">Create/Login an Account<i class="fa fa-angle-right"></i></span>
#endauth
</div>
#endif
In a foreach loop, I have more than one item and each item has a button called "save". However, when I click on the first "save" button, it saves only the last item in my database.
#foreach($product_dr as $product)
<tr>
<td style="font-size: 20px;color: #101010">
<div class="form-group">
<input type="hidden" name="title" value="{{$product->title}}">
<label for="inputText3" class="col-form-label"></label>
{{$product->title}}
</div>
</td>
<td style="font-size: 20px;color: #2ec551">
<div class="form-group">
<input id="inputText4" VALUE="{{$product->price}}" type="text" name="price" class="form-control" placeholder="Amount" style="width: 100px">
</div>
</td>
<td style="font-size: 20px;color: #2ec551">
<div class="form-group">
<input id="inputText4" VALUE="1" type="number" name="amount" class="form-control" placeholder="Amount" style="width: 100px">
</div>
</td>
<td style="font-size: 20px;color: #2ec551">
<div class="form-group">
<input type="hidden" name="table" value="{{$table[0]->number}}">
<input type="hidden" name="table_number" value="{{$table[0]->number}}">
<label for="inputText3" class="col-form-label"></label>
{{$table[0]->number}}
</div>
</td>
<td>
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 ">
<button class="btn btn-success" type="submit">Save</button>
</div>
</td>
</tr>
#endforeach
The name of the variables must be an array as such:
<input type="hidden" name="title[]" value="{{$product->title}}">
This way you will have an array on your backed that you can iterate. If not, you will only get one value for "title"
I have read somewhere that when an image is uploaded & there is a problem with it the page will refresh and abort the upload, but when I upload the image, I can see the image being displayed on my page and then the page gets refreshed, any ideas on what is causing that?
The AJAX code that sends the image to the server :
function uploadAuth() {
var formdata = new FormData($('#formt')[0]);
if ($("#file").val() !== "") {
$.ajax({
type: "POST",
url: '/Actions/UploadImage',
data: formdata,
processData: false,
contentType: false,
success: function (data) {
var d = data;
$('.userPicturesAuth').append('<div class="singleImage"><img class= "img" src=" ' + data + ' "/><button class="dropdowncust butt fas fa-ellipsis-v"><div class="dropdown-contentcust"><div class="singleElement"><p>Change picture</p></div><div class="singleElement"><p>Delete picture</p></div><div class="singleElement"><p>Make private</p></div></div></button></div>');
},
error: function (e) {
console.log(e.responseText);
}
});
}
}
server code:
[HttpPost]
public string UploadImage(Service service, IFormFile photo)
{
if (photo != null)
{
using var image = Image.Load(photo.OpenReadStream());
string uploadsFolder = Path.Combine(Hosting.WebRootPath, "images");
image.Mutate(x => x.Resize(180, 180));
var uniqueFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(photo.FileName);
string filePath = Path.Combine(uploadsFolder, uniqueFileName);
image.Save(filePath);
//photo.CopyTo(new FileStream(filePath, FileMode.Create));
var newPath = filePath.Replace(Hosting.WebRootPath, "");
return newPath;
}
return null;
}
the Path that is returned to the ajax as a response is :
\images\ab89e973-d434-4053-8efa-d2a17847b06e_6682_DancingCoffin4.png
-------EDIT-------
the whole HTML page:
#using Models
#using AutoMatcherProject.ViewModels
#model Models.GenericUser
#using Utils
#using Interfaces
#using Microsoft.AspNetCore.Identity;
#using DbServices
#inject ICredentialDb DataAccess
#inject UserManager<ApplicationUser> signIn
#{
ViewData["Title"] = "Dashboard";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script src="~/lib/jquery-validate/jquery.validate.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
<script src="~/jQuery-Autocomplete-master/"></script>
<link rel="stylesheet" type="text/css" href="~/css/css/myCss.css">
<link rel="stylesheet" type="text/css" href="~/css/css/AuthUserCss.css">
<link href='https://fonts.googleapis.com/css?family=Arya' rel='stylesheet'>
<script src="~/js/scripts.js"></script>
<script src="~/js/AuthenticatedUserScripts.js"></script>
<script src="~/jquery-ui.js"></script>
<link href="~/jquery-ui.css" rel="stylesheet" />
<link href="https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel="stylesheet">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="https://cdn.metroui.org.ua/v4/css/metro-all.min.css">
<script src="https://cdn.metroui.org.ua/v4/js/metro.min.js"></script>
</head>
#{
var user = DataAccess.GetById(signIn.GetUserId(User));
var username = user.Username;
var password = user.Password;
var allServices = Enum.GetValues(typeof(Service)).Cast<Service>().ToList();
List<Service>? services = null;
List<Service>? unsubscribedServices = new List<Service>();
try
{
services = DataAccess.GetUserServicesById(signIn.GetUserId(User));
for (int i = 0; i < allServices.Count - 1; i++)
{
if (!services.Contains(allServices[i]))
{
unsubscribedServices.Add(allServices[i]);
}
}
}
catch (Exception)
{
}
if (services.Count != 0)
{
<div id="mainCont">
<div id="cont1">
<label class="aryaFont">Welcome Back #username!</label>
<div id="userServices">
<label class="aryaFont">Select a service</label>
<br />
#*<form method="post" asp-action="ChangeDescriptions" asp-controller="Actions">
#for (int i = 0; i < services.Count; i++)
{
<input name="services" type="checkbox" value="#services[i]" />
#Html.Hidden("id", #signIn.GetUserId(User));
<label id="serviceName">#services[i]</label>
<br />
}
<input type="text" name="description" value="" />
<button>Change description!</button>
</form>*#
<form id="schedulerFormAuth">
<div id="dropDownAuthenticated">
#*<select id="userServicesDropDownAuth" class="browser-default custom-select" asp-for="Service" onchange="getImages(this, '#username', '#password')">
#{
<option style="display:none"></option>
foreach (var item in services)
{
<option>#item.ToString()</option>
}
}
</select>*#
</div>
<br />
<div id="likesAuth">
<label class="aryaFont">Select number of likes</label>
<br />
<input id="likesInputAuth" class="likeInput" asp-for="Likes" onchange="flipLikesAuth()">
<br />
<div id="checkboxAuth">
<label class="aryaFont">Start liking in the future?</label>
<div class="custom-control custom-checkbox">
<br />
<div class="onOffAuth">
<div class="onoffswitchAuth">
<input type="checkbox" name="onoffswitchAuth" class="onoffswitch-checkboxAuth" id="myonoffswitchAuth" checked>
<label class="onoffswitch-labelAuth" for="myonoffswitchAuth">
<span class="onoffswitch-innerAuth"></span>
<span class="onoffswitch-switchAuth"></span>
</label>
</div>
</div>
<div id="dateAuth">
<label class="aryaFont"> When would you like us to start?</label>
<div class="container">
<input id="datetimepicker1Auth" asp-for="Time" type="datetime-local" asp-format="{4:MM/dd/yyyy}" class="form-control" />
<button id="dateAuth" type="submit" class="btn btn-primary">Continue</button>
</div>
</div>
<input id="submitAuth" onclick="submitValidatedFormAuth('#username','#password')" type="button" class="btn btn-primary" value="Continue 1">
<i id="pleaseWait" class="text-danger"></i>
</div>
</div>
</div>
</form>
</div>
<div class="checkOutAuth">
<input id="StartLikingAuth" onclick="scheduleAuth()" type="button" class="btn btn-primary" value="Check out and start likiing!">
</div>
<div id="descriptionAuth">
<form id="aboutMeAuth">
<h5>Change About Me</h5>
<i>About Me</i>
<input id="aboutMeInput" type="text" asp-for="input" />
<br />
<a id="aboutMe"></a>
<br />
<input onclick="aboutMeAuth()" asp-for="input" type="button" class="btn btn-primary" value="Change About Me">
</form>
<br />
<form id="autoCompleteForm">
<i>Change location</i>
<input id="autocomplete2" asp-for="input" type="text">
<br />
<a id="currentLocation"> </a>
<br />
<input onclick="getCityAuth()" asp-for="input" type="button" value="Set Location" class="btn btn-primary">
</form>
<i>I am looking for:</i>
<br />
<form name="genders">
<div>
<input type="radio" name="gender" value="Male" id="Male">
<label for="Male">Male</label>
</div>
<div>
<input type="radio" name="gender" value="Both" id="Both">
<label for="Both">Both</label>
</div>
<div>
<input type="radio" name="gender" value="Female" id="Female">
<label for="Female">Female</label>
</div>
</form>
<br />
<label for="customRange1">Change searching distance</label>
<input type="range" class="custom-range" id="distanceInput" min="0" max="160" value="" oninput="distanceoutput.value = value "><output id="distanceoutput"></output>
<br />
<input data-role="doubleslider"
data-min="18" data-max="80"
onchange="$('#slider-return-value').val(this.value)">
<input type="text" id="slider-return-value">
<input onclick="changeSearchSettings()" asp-for="input" type="button" value="Update Settings" class="btn btn-primary">
<br />
<div class="userPicturesAuth">
<div class="addPicture">
<div class="pictureSquare">
<div class="camIcon">
<i class="fas fa-camera fa-3x ">
</i><div class="addAPicture">
<form id="formt" enctype="multipart/form-data">
<input onchange="uploadAuth()" id="file" asp-for="Photo" type="file" />
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#if (unsubscribedServices.Count > 0)
{
<div id="cont2">
<div class="botImage">
#*<img src="~/images/unnamed.png" alt="Alternate Text" />*#
</div>
<div id="cn1">
<form id="schedulerForm">
<div id="service">
<label class="aryaFont">Select a service</label>
<br />
<select id="service" class="browser-default custom-select" asp-for="Service" onchange="flipService()">
#{
<option style="display:none"></option>
foreach (var singleService in unsubscribedServices)
{
<option>#singleService.ToString()</option>
};
}
</select>
</div>
<br />
<div id="likes">
<label class="aryaFont">Select number of likes</label>
<br />
<input id="likesInput" class="likeInput" asp-for="Likes" onchange="flipLikes()">
<br />
<div id="checkbox">
<label class="aryaFont">Start liking in the future?</label>
<div class="custom-control custom-checkbox">
<br />
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
<div id="date">
<label class="aryaFont"> When would you like us to start?</label>
<div class="container">
<input id="datetimepicker1" asp-for="Time" type="datetime-local" asp-format="{4:MM/dd/yyyy}" class="form-control" />
<button id="date" type="submit" class="btn btn-primary">Continue</button>
</div>
</div>
<input id="submit" onclick="submitForm()" type="button" class="btn btn-primary" value="Continue">
</div>
</div>
</div>
</form>
</div>
<div>
<form id="serviceLogIn">
<div>
<i id="error" class="text-danger"></i>
</div>
<div>
<input id="username1" type="text" asp-for="Username" value="Username" />
<br />
<input id="password1" type="password" asp-for="Password" value="Password" />
<br />
</div>
<input id="submitService" onclick="validateUser()" type="button" class="btn btn-primary" value="Validate">
<br />
<i id="pleaseWait" class="text-danger"></i>
<div class="spinner-border"></div>
</form>
</div>
<br />
<div class="checkOut">
<h5>Checkout form</h5>
<input id="StartLiking" onclick="schedule()" type="button" class="btn btn-primary" value="Check out and start likiing!">
</div>
<div id="description">
<form id="ChangeDesc">
<h5>Change Description</h5>
<input type="text" asp-for="Proffesion" /> <i>Proffesion</i>
<br />
<input type="text" asp-for="CompanyName" /><i>Company name</i>
<br />
<input type="text" asp-for="School" /><i>School or university</i>
<br />
<input onclick="changeDesc()" type="button" class="btn btn-primary" value="Change Description">
</form>
<br />
<form id="autoCompleteForm">
<input id="autocomplete2" asp-for="input" type="text"><i>Change location</i>
<br />
<input onclick="getCity()" asp-for="input" type="button" value="Set Location" class="btn btn-primary">
</form>
<br />
</div>
<div class="userPictures">
<div class="addPicture">
<div class="pictureSquare">
<div class="camIcon">
<i class="fas fa-camera fa-3x "></i>
<div class="addAPicture">
#*<form id="formt" enctype="multipart/form-data">
<input onchange="upload()" id="file" asp-for="Photo" type="file" /><input id="service2" asp-for="Service" />
<i>
Add a
</i>
</form>*#
</div>
</div>
</div>
</div>
</div>
</div>
}
</div>
}
else
{
<div id="cont2">
<div id="cn1">
<form id="schedulerForm">
<div id="service">
<label class="aryaFont">Select a service</label>
<br />
<select id="service" class="browser-default custom-select" asp-for="Service" asp-items="Html.GetEnumSelectList<Service>()" onchange="flipService()">
<option style="display:none" />
</select>
</div>
<br />
<div id="likes">
<label class="aryaFont">Select number of likes</label>
<br />
<input id="likesInput" class="likeInput" asp-for="Likes" onchange="flipLikes()">
<br />
<div id="checkbox">
<label class="aryaFont">Start liking in the future?</label>
<div class="custom-control custom-checkbox">
<br />
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox switchunauth" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
<div id="date">
<label class="aryaFont"> When would you like us to start?</label>
<div class="container">
<input id="datetimepicker1" asp-for="Time" type="datetime-local" asp-format="{4:MM/dd/yyyy}" class="form-control" />
<button id="date" type="submit" class="btn btn-primary">Continue</button>
</div>
</div>
<input id="submit" onclick="submitForm()" type="button" class="btn btn-primary" value="Continue">
</div>
</div>
</div>
</form>
</div>
<div>
<form id="serviceLogIn">
<div>
<i id="error" class="text-danger"></i>
</div>
<div>
<input id="username1" type="text" asp-for="Username" value="Username" />
<br />
<input id="password1" type="password" asp-for="Password" value="Password" />
<br />
</div>
<input id="submitService" onclick="validateUser()" type="button" class="btn btn-primary" value="Validate">
<br />
<i id="pleaseWait" class="text-danger"></i>
<div class="spinner-border"></div>
</form>
</div>
<div class="checkOut">
<h5>Checkout form</h5>
<input id="StartLiking" onclick="schedule()" type="button" class="btn btn-primary" value="Check out and start likiing!">
</div>
<div id="description">
<form id="ChangeDesc">
<h5>Change Description</h5>
<input type="text" asp-for="Proffesion" /> <i>Proffesion</i>
<br />
<input type="text" asp-for="CompanyName" /><i>Company name</i>
<br />
<input type="text" asp-for="School" /><i>School or university</i>
<br />
<input onclick="changeDesc()" type="button" class="btn btn-primary" value="Change Description">
</form>
<br />
<form id="autoCompleteForm">
<input id="autocomplete2" asp-for="input" type="text"><i>Change location</i>
<br />
<input onclick="getCity()" asp-for="input" type="button" value="Set Location" class="btn btn-primary">
</form>
<br />
<div class="userPictures">
<div class="addPicture"><div class="pictureSquare"><div class="camIcon"><i class="fas fa-camera fa-3x "></i><div class="addAPicture"><form id="formt" enctype="multipart/form-data"><input onchange="upload()" id="file" asp-for="Photo" type="file" /><input id="service2" asp-for="Service" /><i>Add a picture</i></form></div></div></div></div>
</div>
</div>
</div>
}
}
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">
I want to fill this form, but i dont know how to do it since it only have a classname.
All the examples i saw have an id or a name, to fill the form and submit it, please help.
<form class="header_form" method="post" action="">
<div class="lgn-items">
<div class="login_item">
<label>Email</label>
<input type="text" name="email" tabindex="1" class="inputtext" id="email" />
</div>
<div class="login_item" >
<label>Password</label>
<input type="password" name="password" tabindex="2" class="inputtext" id="pass" />
</div>
<div class="lgn-add">
Registration <span>|</span>
Forgot your password ?
<div class="rembo">
<input type="checkbox" name="remember" value="1" /> Remember me
</div>
</div>
</div>
<div class="login_item lgn-btn" >
<input type="submit" name="login_button" value="Login" tabindex="3" class="login" />
</div>
</form>
You can access to your form using any selector. In your case you to it like this.
casper.then(function () {
casper.fill('form.header_form', {
/** Your parameters here **/
}, true);
});