I have created a valuation table which contain
class CreateValuations < ActiveRecord::Migration
def change
create_table :valuations do |t|
t.text :location
t.integer :number_of_bedroom
t.integer :number_of_bath
t.integer :age_of_building
t.text :other_details
t.string :name
t.string :email
t.integer :contact_number
t.timestamps null: false
end
end
end
And later i added a column :building of type text in it using rails generate migration add_building_to_valuations building:text. I have created a form
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(#valuation) do |val| %>
<%= val.label :building, "Name of Building/Builder" %>
<%= val.text_field :building, class: 'form-control' %>
<%= val.label :location, "Location" %>
<%= val.text_field :location, class: 'form-control' %>
<%= val.label :number_of_bedroom, "Number of Bedroom" %>
<%= val.text_field :number_of_bedroom, class: 'form-control' %>
<%= val.label :number_of_washroom, "Number of Washroom" %>
<%= val.text_field :number_of_bath, class: 'form-control' %>
<%= val.label :age_of_building, "Age of Building" %>
<%= val.text_field :age_of_building, class: 'form-control' %>
<%= val.label :name, "Name" %>
<%= val.text_field :name, class: 'form-control' %>
<%= val.label :email, "Email" %>
<%= val.text_field :email, class: 'form-control' %>
<%= val.label :contact_number, "Contact Number" %>
<%= val.text_field :contact_number, class: 'form-control' %>
<%= val.submit "Evaluate my property", class: "btn btn-primary" %>
<% end %>
</div>
</div>
When i fill all the field and submit via Evaluate my property, Then no data is being saved in :building.
I checked this using following commands
$ rails console
$ Valuation.all
and received output are following output
#<Valuation id: 1, location: "Chandivali, Powai",
number_of_bedroom: 3, number_of_bath: 3,
age_of_building: 9, other_details: nil, name: "Shravan",
email: "shravan.xxx#gmail.com",
contact_number: "9876543210",created_at: "2015-11-14 09:47:26",
updated_at: "2015-11-14 09:47:26", building: nil>,
You should update your valuation_params Which is most likely a private function
private
def valuation_params
params.require(:valuation).permit(:building,
:location,
:number_of_bedroom,
:number_of_bath,
:age_of_building,
:name, :email, :contact_number)
end
end
Related
I'm trying to create nested attributes but I'm getting the following error "Unpermitted parameter: address_fields" the fields appear when I'm trying to generate and create a new nested address but doesn't get saved.
In controller :
def praject_params
params.require(:praject).permit(:name, :cpf, :phone, :email, :zip, :city, :state, :borough, :street, :number, :comp, :type, address_attributes: [ :id, :ziptwo, :citytwo, :statetwo, :boroughtwo, :streetwo, :numbertwo, :comptwo, :typetwo])
end
In address model :
class Address < ApplicationRecord
self.inheritance_column = :foo
belongs_to :praject, optional: true
end
In praject model :
class Praject < ApplicationRecord
self.inheritance_column = :foo
has_many :addresses, inverse_of: :praject, dependent: :destroy
accepts_nested_attributes_for :addresses, allow_destroy: true, reject_if: proc { |att| att['name'].blank?}
before_save do
self.type.gsub!(/[\[\]\"]/, "") if attribute_present?("type")
end
end
class CreateAddresses < ActiveRecord::Migration[5.0]
def change
create_table :addresses do |t|
t.string :ziptwo
t.string :citytwo
t.string :statetwo
t.string :boroughtwo
t.string :streetwo
t.string :numbertwo
t.string :comptwo
t.string :typetwo
t.belongs_to :praject, foreign_key: true
t.timestamps
end
end
end
In the _form.html.erb I just have a button to add a new nested address field.
The funny part is that this error appear in the console when the rails application is running and I'm trying to create a new project, I tried to change the controller to addresses_attributes[] and is not working too. Can anyone help me? I'm getting crazy with this, I tried almost everything and nothing works.
## _form.html.erb
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
<th>
<div class="form-inputs">
<%= f.input :name, label: 'Name' %>
<%= f.input :cpf, label: 'Cpf' %>
<%= f.input :phone, label: 'Phone' %>
<%= f.input :email, label: 'Email' %>
<%= f.input :zip, label: 'Zip' %>
<%= f.input :city, label: 'City' %>
<%= f.input :state, label: 'State' %>
<%= f.input :borough, label: 'Neighbourhood' %>
<%= f.input :street, label: 'Street' %>
<%= f.input :number, label: 'Number' %>
<%= f.input :comp, label: 'Comp' %>
<div class="field">
<h4>Type:</h4>
<%= label_tag 'type_comer', 'Comercial' %>
<%= check_box_tag 'praject[type][]', 'comercial', checked('comercial'), id: 'type_comer' %>
<%= label_tag 'type_res', 'Residential' %>
<%= check_box_tag 'praject[type][]', 'Residential', checked('Residencial'), id: 'type_res' %>
<%= label_tag 'type_farm', 'Rural' %>
<%= check_box_tag 'praject[type][]', 'Rural', checked('Rural'), id: 'type_farm' %>
<%= label_tag 'type_beach', 'Beach' %>
<%= check_box_tag 'praject[type][]', 'Beach', checked('Beach'), id: 'type_beach' %>
</div>
</div>
<h3>Secondary Addresses:</h3>
</th>
<div class="field"
<%= form_for(#praject) do |f| %>
# ...
<%= f.fields_for(:addresses) do |address| %>
<%= address.input :cpf, label: 'Cpf' %>
<%= address.input :phone, label: 'Phone' %>
<%= address.input :email, label: 'Email' %>
<%= address.input :zip, label: 'Zip' %>
<%= address.input :city, label: 'City' %>
<%= address.input :state, label: 'State' %>
<%= address.input :borough, label: 'Neighbourhood' %>
<%= address.input :street, label: 'Street' %>
<%= address.input :number, label: 'Number' %>
<%= address.input :comp, label: 'Comp' %>
<% end %>
# ...
<% end %>
If you are using simple_form use its wrapped simple_fields_for method instead.
I am using a PostgreSQL database and Rails 5.0.6.
I try to build a course allocation WebApp for the school where I am working. For each course the teachers are able to select which forms are allowed to visit the course.
Migration file:
def up
create_table :courses do |t|
t.integer :number, null: false
t.string :name, null: false
t.text :description, null: false
t.decimal :level, array: true, default: []
t.integer :max_visitor, null: false
t.integer :min_visitor
t.integer :pos_visit
t.timestamps
end
end
In my Controller:
params.require(:course).permit(:number, :name, :description, :level [], :max_visitor, :min_visitor, :pos_visits)
I already read this post: Rails 5 strong params with an Array within check boxes values. But the Syntax params.require(:product).permit(:id, **category_ids: []**) doesnt work for me even though I am using rails 5 as well. I am not sure if :level [] really works but it seems to be correct syntax.
This is my Form:
<%= form_for #course do |t| %>
<%= t.text_field :number, class: 'form-control' %>
<%= t.text_field :name, class: 'form-control' %>
<%= t.text_area :description, class: 'form-control' %>
<%= t.check_box :level[], 1%>
<%= t.check_box :level[], 2%>
<%= t.check_box :level[], 3%>
<%= t.check_box :level[], 4%>
<%= t.text_field :max_visitor, class: 'form-control' %>
<%= t.text_field :min_visitor, class: 'form-control' %>
<%= t.text_field :pos_visit, class: 'form-control' %><br/>
<%= t.submit "bestätigen", class: "btn btn-success"%>
<% end %>
This check_box syntax seems to be wrong.
May anyone help me with the right syntax of the check_boxes?
Thanks for help.
There's a collection_check_boxes helper method for this:
<%= form_for #course do |f| %>
<%= f.collection_check_boxes(:level, { 'One': 1, 'Two': 2, 'Three': 3 }, :last, :first) %>
<% end %>
The third argument is the method used to get the value from the "collection", and the fourth is the method used to get the label from the "collection". This helper method automatically converts the Hash into an array, that's why I'm using last and first here.
It's also possible to style it the way you want e.g. using Bootstrap:
<%= f.collection_check_boxes(:level, { 'One': 1, 'Two': 2, 'Three': 3 }, :last, :first) do |b| %>
<div class="form-check form-check-inline">
<%= b.check_box class: 'form-check-input' %>
<%= b.label class: 'form-check-label' %>
</div>
<% end %>
<%= check_box_tag 'level[]', 1%>
<%= check_box_tag 'level[]', 2%>
<%= check_box_tag 'level[]', 3%>
<%= check_box_tag 'level[]', 4%>
But when you use check_box_tags in form_for, then the parameters level[], will be outside off the strong parameters array you usually use in the controller#new function.
Parameters: {"course"=>{"number"=>"12", "name"=>"tanzen", "description"=>"efwefggw", "max_visitor"=>"12", "min_visitor"=>"5", "pos_visit"=>"2"}, "level"=>["1", "3", "4"], "commit"=>"bestätigen"}
So I added the level manually
#course = Course.new(course_params)
#course.level = params[:level]
So I have a form and corresponding classes. I got an error:
undefined method `start' for #<Klass id: nil, name: nil, teacher: nil, day: nil>
for line: <%= f.text_field :start, class: 'form-control' %>
and (when I'm trying to delete the above one) <%= f.text_field :duration, class: 'form-control' %>
removing both fields makes my website ok.
My whole form code:
<%= form_for #klass do | f | %>
<div class = “form-group”>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :teacher %>
<%= f.text_field :teacher, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :start %>
<%= f.text_field :start, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :duration %>
<%= f.text_field :duration, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :day %>
<%= f.select :day, ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'] %>
</div>
<%= f.submit 'Submit', class: 'btn btn-default' %>
</div>
<% end %>
model (changing integer to string doesn't make any difference, but that is the only difference betweenthese two fields and the rest of the form that I can see) :
class Klass < ActiveRecord::Base
validates :name, presence: true
validates :teacher, presence: true
validates :day, presence: true
validates :start, presence: true
validates :duration, presence: true, numericality: { only_integer: true }
end
database file:
class CreateKlasses < ActiveRecord::Migration[5.0]
def change
create_table :klasses do |t|
t.string :name
t.string :teacher
t.string :day
t.integer :start
t.integer :duration
end
end
end
and controller:
class KlassesController < ApplicationController
def new
#klass = Klass.new
end
end
Looks for me like I missed to declare these two form fields but where else I can look for it?
1- rake db:rollback
make sure you have these fields added in migration file
class CreateKlasses < ActiveRecord::Migration[5.0]
def change
create_table :klasses do |t|
t.string :name
t.string :teacher
t.string :day
t.integer :start
t.integer :duration
end
end
end
2- rake db:migrate
now reload rails console
reload!
or just close rails console and open rails console again.
check again Klass.new if it has all field that you added in migration. if those field exists then restart server and thats it.
I have created a table name tenants which have following column
class CreateTenants < ActiveRecord::Migration
def change
create_table :tenants do |t|
t.text :company_name
t.text :work_area
t.text :second_pref
t.text :third_pref
t.integer :who_are_you
t.integer :number_of_bedroom
t.text :other_specs
t.string :budget
t.string :name
t.string :email
t.string :contact_number
t.timestamps null: false
end
end
end
And i am entering the data into in table by following form
<%= form_for Tenant.new do |val| %>
<%= val.label :company_name, "Company Name" %>
<%= val.text_field :company_name, class: 'form-control' %>
<%= val.label :work_area, "Work Area" %>
<%= val.text_field :work_area, class: 'form-control' %>
<%= val.label :second_pref, "Second Preference" %>
<%= val.text_field :second_pref, class: 'form-control' %>
<%= val.label :third_pref, "Third Preference" %>
<%= val.text_field :third_pref, class: 'form-control' %>
<%= val.label :who_are_you, "Are you Family/Bachelor?" %>
<%= val.text_field :who_are_you, class: 'form-control' %>
<%= val.label :number_of_bedroom, "Number of Bedroom" %>
<%= val.text_field :number_of_bedroom, class: 'form-control' %>
<%= val.label :other_specs, "Other Requirments" %>
<%= val.text_field :other_specs, class: 'form-control' %>
<%= val.label :budget, "Your Budget" %>
<%= val.text_field :budget, class: 'form-control' %>
<%= val.label :name, "Name" %>
<%= val.text_field :name, class: 'form-control' %>
<%= val.label :email, "Email" %>
<%= val.text_field :email, class: 'form-control' %>
<%= val.label :contact_number, "Contact Number" %>
<%= val.text_field :contact_number, class: 'form-control' %>
<%= val.submit "Submit", class: "btn btn-primary" %>
<% end %>
When i fill all the required filled and click submit, i see the following output in rails server log.
Started POST "/tenants" for ::1 at 2015-11-15 11:41:27 +0530
Processing by TenantsController#create as HTML
Parameters: {
"utf8"=>"✓", "authenticity_token"=>"26KYMFmofF+A1UrF+eWu21nEGbVO3n2bUSPl8340k8hY1JQhYF2kfhOHLmlF+r1Tj5UB7h6H+IJ7MY+Rx+o4CA==",
"tenant"=>
{
"company_name"=>"Housing.com",
"work_area"=>"Hiranandani Business Park",
"second_pref"=>"Chandivali",
"third_pref"=>"Vikhroli",
"who_are_you"=>"Bachelor",
"number_of_bedroom"=>"3",
"other_specs"=>"Gym, Swimming Pool",
"budget"=>"55000",
"name"=>"Shravan Kumar Gond",
"email"=>"shravan.ma.iitkgp#gmail.com",
"contact_number"=>"9475593772"
},
"commit"=>"Submit"
}
Unpermitted parameter: budget
(0.1ms) begin transaction
(0.1ms) rollback transaction
Can anyone tell me, why this happening ?
It seems you are missing :budget in strong parameters of your tenants_controller.rb file. It should be something like this.
private
def tenant_params
params.require(:tenant).permit(:company_name,
:work_area,
:second_pref,
:third_pref,
:who_are_you,
:number_of_bedroom,
:other_specs,
:budget,
:name,
:email,
:contact_number)
end
Unpermitted parameter: budget
This is your error - it means you're passing parameters to your controller, but it cannot save them in your model.
The fix is to set the strong params method (as shravan40 suggested).
Since you're calling Tenant.new in your #new action, I would recommend using the following in your controller:
#app/controllers/tenants_controller.rb
class TenantsController < ApplicationController
def new
#tenant = Tenant.new
end
def create
#tenant = Tenant.new tenant_params
#tenant.save
end
private
def tenant_params
params.require(:tenant).permit(:company_name, :work_area, :second_pref, :third_pref, :who_are_you, :number_of_bedroom, :other_specs, :budget, :name, :email, :contact_number)
end
end
There's also something you can do to polish up your form...
<%= form_for #tenant do |val| %>
<% vals = [[:company_name],[:work_area],[:second_pref, "Second Preference"], [:third_pref, "Third Preference"],[:who_are_you, "Are you Family/Bachelor?"], [:number_of_bedroom], [:other_specs, "Other Requirements"],[:budget, "Your Budget"], [:name], [:email], [:contact_number]] %>
<% vals.each do |value| %>
<% value[1] ||= value[0].to_s.gsub("_", " ") %>
<%= val.label value[0], value[1] %>
<%= val.text_field value[0], class: 'form-control' %>
<% end %>
<%= val.submit "Submit", class: "btn btn-primary" %>
<% end %>
I am working on an app where people can go to edit their user and upon submission it redirects them to their show profile view.
This all seems to work according to plan but for some reason some when I go back to my edit view I see that some of my form fields get automatically pre-populated while others don't.
Why is this happening?
Specifically the all text fields are being remembered and pre-populated but my image file field and time weekly fields are not. They are definitely still in the database and are displayed in my show view but not pre-populated on the edit view?
Do certain types of fields not get pre-populated or what is this behavior? I would ideally like to have all of the fields pre-populated(image, dates, text, etc)
Here is my code:
Edit view:
<div class="editprofilebox">
<h1>Take a moment to fill out your profile:</h1>
<div class="container-fluid">
<div class="edit-profile-form">
<%= form_for #user, :html => { :role => 'form', :class => 'form-horizontal', :multipart => true } do |f| %>
<div class="form-inputs">
<div class="row">
<div class= "col-sm-4">
<div class: "form-group">
<%= f.text_field :first_name, class: "form-control", placeholder:"First Name" %>
</div>
<div class: "form-group">
<%= f.text_field :last_name, class: "form-control", placeholder:"Last Name" %>
</div>
<div class: "form-group">
<%= f.label :profile_image, class: "control-label" %>
<%= f.file_field :image, class: "profile-picture-upload" %>
</div>
</div>
<div class= "col-sm-4">
<div class: "form-group">
<%= f.label :twitter %>
<%= f.text_field :twitter, class: "form-control", placeholder:"Type your update title here" %>
</div>
<div class: "form-group">
<%= f.text_field :occupation, class: "form-control", placeholder:"Occupation" %>
</div>
<div class: "form-group">
<%= f.text_field :gender, class: "form-control", placeholder:"Gender" %>
</div>
<div class: "form-group">
<%= f.text_field :work_history, class: "form-control", placeholder:"Work History" %>
</div>
<div class: "form-group">
<%= f.number_field :years_of_experience, class: "form-control", placeholder:"years_of_experience" %>
</div>
</div>
<h3> time available </h3>
<div class="col-sm-2">
<%= f.label :Monday %>
<%= f.check_box :monday, class: "time-checkbox", placeholder:"Type your update title here" %>
<%= f.time_field :mondaytime1, class: "form-control time-box"%>
<%= f.time_field :mondaytime2, class: "form-control time-box" %>
<%= f.label :Tuesday %>
<%= f.check_box :tuesday, class: "time-checkbox", placeholder:"Type your update title here" %>
<%= f.time_field :tuesdaytime1, class: "form-control time-box" %>
<%= f.time_field :tuesdaytime2, class: "form-control time-box" %>
<%= f.label :Wednesday %>
<%= f.check_box :wednesday, class: "time-checkbox" %>
<%= f.time_field :wednesdaytime1, class: "form-control time-box" %>
<%= f.time_field :wednesdaytime2, class: "form-control time-box" %>
<%= f.label :Thursday %>
<%= f.check_box :thursday, class: "time-checkbox" %>
<%= f.time_field :thursdaytime1, class: "form-control time-box" %>
<%= f.time_field :thursdaytime2, class: "form-control time-box" %>
</div>
<div class:"col-sm-2">
<%= f.label :Friday %>
<%= f.check_box :friday, class: "time-checkbox" %>
<%= f.time_field :fridaytime1, class: "form-control time-box" %>
<%= f.time_field :fridaytime2, class: "form-control time-box" %>
<%= f.label :Saturday %>
<%= f.check_box :saturday, class: "time-checkbox" %>
<%= f.time_field :saturdaytime1, class: "form-control time-box" %>
<%= f.time_field :saturdaytime2, class: "form-control time-box" %>
<%= f.label :Sunday %>
<%= f.check_box :sunday, class: "time-checkbox" %>
<%= f.time_field :sundaytime1, class: "form-control time-box" %>
<%= f.time_field :sundaytime2, class: "form-control time-box" %>
</div>
</div>
</div>
<div class="form-actions">
<%= f.button :submit, class: "btn btn-default btn-lg" %>
</div>
<% end %>
</div>
</div>
</div>
show view:
<div class="profilebox">
<div class="profile-title-box" >
<%= #user.first_name %> <%= #user.last_name %> profile
</div>
<hr>
<div class="profile-container">
<div class="row ">
<div class="profile-image-box col-sm-4" >
<%= image_tag #user.image.thumb('150x185#').url if #user.image_stored? %>
</div>
<div class="profile-info-box col-sm-8">
<%= #user.email %>
</br>
<%= #user.first_name %>
</br>
<%= #user.last_name %>
</br>
<%= #user.occupation %>
</br>
<%= #user.gender %>
</br>
<%= #user.work_history %>
</br>
<%= #user.years_of_experience %>
</br>
</div>
</div>
</div>
<hr>
<div class="profile-extra-box">
<h3>Complete your profile here:</h3>
<%= link_to 'Edit', edit_user_path(#user) %>
</div>
</div>
users controller:
class UsersController < ApplicationController
def new
end
def show
#user = User.find(params[:id])
end
def index
end
def edit
#user = User.find(params[:id])
end
def update
#user = User.find_by_id(params[:id])
if #user.update_attributes(user_params)
flash[:success] = "User updated successfully!"
redirect_to user_path
else
flash[:danger] = "User could not be updated!"
end
end
def destroy
end
def user_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :image, :twitter, :monday, :mondaytime1, :mondaytime2, :tuesday, :tuesdaytime1, :tuesdaytime2, :wednesday, :wednesdaytime1, :wednesdaytime2, :thursday, :thursdaytime1, :thursdaytime2, :friday, :fridaytime1, :fridaytime2, :saturday, :saturdaytime1, :saturdaytime2, :sunday, :sundaytime1, :sundaytime2, :occupation, :gender, :years_of_experience, :work_history)
end
end
Scheema:
ActiveRecord::Schema.define(version: 20140906225655) do
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "first_name"
t.string "last_name"
t.string "image_uid"
t.string "image_name"
t.text "twitter"
t.boolean "monday"
t.text "mondaytime1"
t.text "mondaytime2"
t.boolean "tuesday"
t.text "tuesdaytime1"
t.text "tuesdaytime2"
t.boolean "wednesday"
t.text "wednesdaytime1"
t.text "wednesdaytime2"
t.boolean "thursday"
t.text "thursdaytime1"
t.text "thursdaytime2"
t.boolean "friday"
t.text "fridaytime1"
t.text "fridaytime2"
t.boolean "saturday"
t.text "saturdaytime1"
t.text "saturdaytime2"
t.boolean "sunday"
t.text "sundaytime1"
t.text "sundaytime2"
t.string "occupation"
t.string "gender"
t.string "work_history"
t.decimal "years_of_experience"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
"Pre-population" has two connotations, both of which you need to consider:
Browser-based data
Server-based data
Browser
The difference here is that browser based data is basically the "remember me" stuff you type into forms on e-commerce sites and the like.
The reason I mention this is because when you have a user form, modern browsers (exclusing IE) will generally populate it with the relevant data you have used before. This can be seen with this introduction to Autofill on Chrome's site:
In essence, it means that if you load standard "input names" on your pages, Chrome will endeavour to populate them with data you've either saved, or inputted into other websites.
Firstly, you need to make sure you are not having your details inputted by the browser. If this the is the case, it will mean you've got to get the server-side functionality working regardless.
Either way, you should look at using the server-based data as described below:
Server
Secondly, you'll have sever-based data. This is real Rails data, and what you need in your page:
#app/controllers/users_controller.rb
class UsersController < ApplicationController
def edit
#user = User.find params[:id]
end
end
#app/views/users/edit.html.erb
<%= form_for #user do |f| %>
<%= f.text_field :first_name %>
<%= f.text_field :last_name %>
<%= image_tag #user.image.url if #user.image.present? %>
<%= f.file_field :image %>
<%= f.submit %>
<% end %>
As per the form_for documentation, if you have the correct ActiveRecord object populated, and have the data in your database, calling the attribute-based input helpers should populate for you.
There are some caveats to this, however:
--
Image
Using file_field will not pre-populate your image.
The file upload element is distinctly different to the image element - simply that the upload element cannot show you an image. This means you have to explicitly show the image in your edit form, if indeed you want to show it:
# Edit View
<%= image_tag #user.image.thumb('150x185#').url if #user.image_stored? %>
<%= f.file_field :image %>
We've used this method here (just sign up for free and try to upload a profile image):
Although we used JQuery heavily here, we made it so that the image form shows the image, which then gives you the ability to upload a new one.
--
Time
Frankly, I'm not sure about your time field.
Like the explanation above, you'll want to ensure you're using the attributes from your database to populate your time fields. I see you're using a lot of different checkboxes, which although might help create a better system, will likely not populate the data you want