Unexpected token "else" while compiling ejs - conditional-statements

<% if (p.type === "boolean") { %>
<label class="form-label"><%= p.name%></label>
<input type="radio" class="radio-inline" name="<%= p.name%>[value]=" true " [(ngModel)]="model.<%=p .name%>"> True
<input type="radio" class="radio-inline" name="<%= p.name%>" [value]="false" [(ngModel)]="model.<%= p.name%>"> False
<% } else if (p.type === "date"){ %>
<label class="form-label"><%= p.name%></label>
<input type="date" class="text-input" name="<%= p.name%>" [ngModel]="model.<%= p.name%> | date:'yyyy-MM-dd hh:ii'" (ngModelChange)="model.<%= p.name%> = $event">
<% } else { %>
<label class="form-label"><%= p.name%></label>
<input type="date" class="text-input" name="<%= p.name%>" [ngModel]="model.<%= p.name%> | date:'yyyy-MM-dd hh:ii'" (ngModelChange)="model.<%= p.name%> = $event">
<% } %>
Can anyone help me out here with this code here returning me an error
Unexpected token else while compiling ejs

Related

How to upload image file on codeigniter 3?

I've tried everything to code upload the image file but I still stuck and it keeps an error. It can't detect the data of the image file so it can't store to the database when I submitted the form. I saw every tutorial I've been searched and look into my code seems everything right but why it still keeps an error.
Controller
public function create()
{
if (!$this->session->userdata('user_logged')) {
redirect('Auth');
}
$data["title"] = "Form Create Blog";
$data["landingpage"] = false;
$data['content'] = 'component/admin/blog/blog_create';
$this->form_validation->set_rules('blogTitle', 'Title tidak boleh kosong', 'required|max_length[50]');
$this->form_validation->set_rules('blogHeaderImg', 'Header Image tidak boleh kosong', 'required');
$this->form_validation->set_rules('blogKeyword', 'Keyword tidak boleh kosong', 'required|max_length[50]');
$this->form_validation->set_rules('blogContent', 'Content tidak boleh kosong', 'required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('index', $data);
} else {
$config['upload_path'] = realpath(APPPATH . '../assets/img/upload/blog/header_image');
$config['allowed_types'] = 'jpg|png|PNG';
$nmfile = time() . "_" . $_FILES['blogHeaderImg']['name'];
$config['file_name'] = $nmfile;
$this->load->library('upload', $config);
if (!$this->upload->do_upload("blogHeaderImg")) {
$error = array('error' => $this->upload->display_errors());
echo '<div class="alert alert-danger">' . $error['error'] . '</div>';
} else {
$data = array('upload_data' => $this->upload->data());
$header_image = $data['upload_data']['file_name'];
$this->M_Blog->storeBlogData($header_image);
print_r($_FILES['blogHeaderImg']);
$this->session->set_flashdata('flashAddBlog', 'Data berhasil <strong>ditambahkan</strong>');
redirect('blog');
}
}
}
Model
public function storeBlogData($header_image)
{
$data = [
'title' => $this->input->post('blogTitle', TRUE),
'header_image' => $header_image,
'content' => $this->input->post('blogContent', TRUE),
'blog_keyword' => $this->input->post('blogKeyword', TRUE),
'created_by' => $this->session->userdata('user_logged')->id,
'last_modified_by' => $this->session->userdata('user_logged')->id,
'is_deleted' => 'n'
];
$this->db->insert('blog', $data);
}
View
<form method="POST" action="create" enctype="multipart/form-data">
<div class="form-group">
<label for="blogTitle">Title</label>
<input class="form-control" type="text" name="blogTitle" id="blogTitle" placeholder="Title">
<small class="form-text text-danger"><?= form_error('blogTitle') ?></small>
</div>
<div class="form-group">
<label for="blogHeaderImg">Header Image</label>
<input class="form-control-file" type="file" id="blogHeaderImg" name="blogHeaderImg">
<small class="form-text text-danger"><?= form_error('blogHeaderImg') ?></small>
</div>
<div class="form-group">
<label for="blogKeyword">Keyword</label>
<input class="form-control" type="text" id="blogKeyword" name="blogKeyword" placeholder="Keyword">
<small class="form-text text-danger"><?= form_error('blogKeyword') ?></small>
</div>
<div class="form-group">
<label for="blogContent">Content</label>
<textarea class="form-control" type="text" id="blogContent" name="blogContent" placeholder="Content" rows="10"></textarea>
<small class="form-text text-danger"><?= form_error('blogContent') ?></small>
</div>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
already solved. I just have to add this code to blog controller
if (empty($_FILES['blogHeaderImg']['name'])) {
$this->form_validation->set_rules('blogHeaderImg', 'Document', 'required');
}
instead of using this code
$this->form_validation->set_rules('blogHeaderImg', 'Header Image tidak boleh kosong', 'required');
thank you

Node Express fail load css and js

this is my folders:
/app
└── models
└── ...
└── node_module
└── ...
└── routes
└── ...
└── public
└── css
└── js
└── views
└── unites
└── new.js
└── show.js
└── edit.js
So, when I go on //mysiteweb/new my logs look like this:
GET /maitre-unites-new 304 4ms
GET /css/bootstrap.css 304 3ms
GET /js/bootstrap.js 304 2ms
But when I go on //mysiteweb/show my logs look like this:
GET /maitre-unites-show/52b46d81ddd1086615000001 304 2ms
GET /maitre-unites-show/css/bootstrap.css 404 2ms
GET /maitre-unites-show/js/bootstrap.js 404 1ms
GET /maitre-unites-show/images/unites/batiment1.jpeg 404 2ms
I don't understand why, my syntax is the same:
/*
* GET New unit.
*/
app.get('/maitre-unites-new', ensureAuthenticated, function (req, res){
Unites.find({}, function (err, unites) {
res.render('unites/new', {
unites: unites,
user : req.user,
title : ' Que voulez vous créer Maitre Du Jeu'
});
});
});
/*
* GET show unit.
*/
app.get('/maitre-unites-show/:id', ensureAuthenticated, function (req, res){
Unites.findById(req.params.id, function (err, unites) {
res.render('unites/show', {
unites: unites,
user : req.user,
title : ' Que voulez vous créer Maitre Du Jeu'
});
});
});
my views news.js:
<% layout('layout') -%>
<% script('js/bootstrap.js') -%>
<% stylesheet('css/bootstrap.css') -%>
<!-- Jumbotron -->
<div class="jumbotron">
<h1><%= title + ' ' %><code><%= user.username %></code></h1>
<p style="text-align:center;">Ho Créateur ! Inventez-nous comme toutes choses en cet univers.</p>
<p>
aide »
retour »
</p>
</div>
<div class="row">
<div class="col-md-12">
<h3>Créez une Unité:</h3>
<form method='post' action='/maitre-unites-new'>
<div>
<label>Nom:</label>
<input type="text" name="name"/><br/>
</div>
<div>
<label>Avatar:</label>
<input type="text" name="avatar"/><br/>
</div>
<div>
<label>Description:</label>
<textarea name="description" row="5" cols="50"></textarea>
</div>
<hr>
<%= unites.name %>
<h2>Inclure d'autres unités dans celle-ci:</h2>
<% if (unites && unites.length !=0) { %>
<div>
<% for (var index in unites) { %>
<input type="checkbox" name="<%= unites[index].unit %>" value="<%= unites[index]._id %>"> <%= unites[index].name %> |
<% } %>
</div>
<% } else { %>
<div>
no document exist
</div>
<% } %>
<hr>
<h2>Inclure cette unité dans d'autres unités:</h2>
<% if (unites && unites.length !=0) { %>
<div>
<% for (var index in unites) { %>
<input type="checkbox" name="<%= unites[index].unit %>" value="<%= unites[index]._id %>"> <%= unites[index].unit %> |
<% } %>
</div>
<% } else { %>
<div>
no document exist
</div>
<% } %>
<input type="submit" value="Save">
</form>
</div>
</div>
<!-- Site footer -->
<div class="footer">
<p>© Company 2013</p>
</div>
</div> <!-- /container -->
my views show.js:
<% layout('layout') -%>
<% script('js/bootstrap.js') -%>
<% stylesheet('css/bootstrap.css') -%>
<!-- Jumbotron -->
<div class="jumbotron">
<h1><%= title + ' ' %><code><%= user.username %></code></h1>
<p style="text-align:center;">Ho Créateur ! Inventez-nous comme toutes choses en cet univers.</p>
<p>
aide »
retour »
</p>
</div>
<div class="row">
<div class="col-md-12">
<%= unites.name %>
<img src="images/unites/<%= unites.avatar %>.jpeg">
<%= unites.description %>
</div>
</div>
<!-- Site footer -->
<div class="footer">
<p>© Company 2013</p>
</div>
</div> <!-- /container -->
This is my repo.git
Why I get this /maitre-unites-show/images.... and not /images... ?
Alright. The error is caused by the fact that your show route has extra path component /:id, and your routes in the views are relative, so they are searched from the current URL, which is different:
new -> /
show -> /maitre-unites-show/
All you need to do is to make your paths absolute in the view:
<% layout('layout') -%>
<% script('/js/bootstrap.js') -%>
<% stylesheet('/css/bootstrap.css') -%>

How to update a record using SQL in ASP

So I'm trying to update a record within a table I created. The form processes but for some reason I don't see the table columns updated. The HTML form is
<form action="divProgramProcess.asp?div=<% =divrec %>" id="countInput" class="contact_form">
<input type="text" name="Shipment_Current" id="Shipment_Current" value="<% =Shipment_Current %>" />
<input type="text" name="Couch_Current" id="Couch_Current" value="<%= Couch_Current %>" />
<input type="text" name="Person_Available_Current" id="Person_Available_Current" value="<%= Person_Available_Current %>" />
</form>
The code within divProgramProcess.asp is
<%
divrec = request.QueryString("div")
Set rstest = Server.CreateObject("ADODB.Recordset")
rstest.locktype = adLockOptimistic
sql = "SELECT top 1 * FROM CensusFacility_Records_Last WHERE Count = '1239' "
rstest.Open sql, db
%>
<body>
<%
Shipment_Current = request.form("Shipment")
Couch_Current = request.form("Couch")
Person_Available_Current = request.form("Person_Available")
rstest("Shipment") = Shipment_Current
rstest("Couch") = Couch_Current
rstest("Person_Available") = Person_Available_Current
rstest.update
Response.Redirect("chooseScreen.asp")
%>
If you have some information you know you're going to pass, you may find it easier to just set it as a hidden input.
For example, instead of what you're doing above, do this with your form:
<form action="divProgramProcess.asp" id="countInput" class="contact_form">
<input type="text" name="Shipment_Current" id="Shipment_Current" value="<% =Shipment_Current %>" />
<input type="text" name="Couch_Current" id="Couch_Current" value="<%= Couch_Current %>" />
<input type="text" name="Person_Available_Current" id="Person_Available_Current" value="<%= Person_Available_Current %>" />
<input type="hidden" name="div" value="<% =divrec %>" />
</form>
And pull the value of div from the Request.Form collection.

I get an empty page with capybara visit method, but response object has content

Ok, so I'm working with capybara + rails 3 + rspect
I'm trying to login to my site, but even though I don't get an error when I use the fill_in method, I get an error with the click_on method, since it can't find the element I'm trying to click.
Here is my HTML code:
<form accept-charset="UTF-8" action="/" class="filter_form" id="login" method="post">
<fieldset>
<div class="modal-body">
<div class="clearfix login-fields">
<label for="user_email">Email</label>
<div class="input login-inputs">
<input class="input-text" id="user_email" name="user[email]" placeholder="email" size="30" type="email" value="">
</div>
</div>
<div class="clearfix login-fields">
<label for="user_password">Password</label>
<div class="input login-inputs">
<input class="input-text" id="user_password" name="user[password]" placeholder="password" size="30" type="password">
</div>
</div>
</div>
<div class="modal-footer">
<input class="btn btn-primary login_btn" id="btn_login" name="commit" type="submit" value="Sign in">
Forgot password...
Cancel
</div>
</fieldset>
</form>
And here is the test:
describe "Login ", js: true, type: :request do
it "should login correctly if the right credentials are given" do
Capybara.default_wait_time = 15
Capybara.ignore_hidden_elements = false
visit new_user_session_path
fill_in 'user_email', :with => 'example#test.com'
fill_in 'user_password', :with => 'pwd123'
p page.body
click_on 'Sign in'
visit '/'
save_and_open_page
response.should have_content('Welcome')
end
end
The worst part is that when I do p page.body right before click_on I see the following code:
<html xmlns=\\\"http://www.w3.org/1999/xhtml\\\"><head></head><body></body></html>\
But if I change that for p response.body.inspect then I get the full html code of the page..., shouldn't the visit method load the content of the response on the page?
Any help will be appreciated, this is driving me crazy :)
Add that line:
config.include Capybara::DSL
to spec/spec_helper.rb:
RSpec.configure do |config|
.....
config.include Capybara::DSL
.....
end

Controller doesn't receive all parameters within the form

In my MVC Web App I am running an ActionResult with the following signature:
Public Function Create(ByVal article As Article_Ad) As ActionResult
And in my ASPX page I have declared the following form which fields correspond to the model, which is strongly typed:
<% Using Html.BeginForm(ViewData("action").toString, "Article", FormMethod.Post, New With { .class = "basic"}) %>
<div class="inner-form">
<%= Html.MyValidationSummary("Por favor corrija os erros e tente novamente.")%>
<dl>
<dt><label for="name">Descrição:</label></dt>
<dd><%= Html.TextBox("description", Model.description, New With {.class = "txt"})%></dd>
<dt><label for="type">Tipo:</label></dt>
<dd><%= Html.DropDownList("type", New SelectList(ViewData("typeList"), "value", "text", Model.type), New With {.class = ""})%></dd>
<dt id="image_dt"></dt>
<dd id="image_dd">
<fieldset id="img_fieldset">
<legend style="font-weight: bold;">Imagem</legend>
<label for="portrait_image_url">Url da Imagem:</label>
<%= Html.TextBox("image_url", Model.image_url, New With {.class = "txt"})%>
<label for="portrait_bigimage_url">Url da Imagem Portrait:</label>
<%= Html.TextBox("portrait_bigimage_url", Model.portrait_bigimage_url, New With {.class = "txt"})%>
<label for="landscape_bigimage_url">Url da Imagem Landscape:</label>
<%= Html.TextBox("landscape_bigimage_url", Model.landscape_bigimage_url, New With {.class = "txt"})%>
</fieldset>
</dd>
<dt id="video_dt"></dt>
<dd id="video_dd">
<fieldset id="video_fieldset">
<legend style="font-weight: bold;">Video</legend>
<label for="video_url">Url do Video:</label>
<%= Html.TextBox("video_url", Model.video_url, New With {.class = "txt"})%>
<label for="video_fullscreen">Url do Video Fullscreen:</label>
<%= Html.TextBox("video_fullscreen", Model.portrait_bigimage_url, New With {.class = "txt"})%>
</fieldset>
</dd>
<dt></dt>
<dd><input class="button" type="submit" name="submitButton" value="Gravar" /> <input class="button" type="submit" name="submitButton" value="Cancelar" /></dd>
</dl>
</div>
<% End Using%>
What is happening right now is that when I submit this form, only the description property is assigned to my object.
I'd like to know why the other properties aren't being filled in my class (I checked with fiddler and everything is being sent correctly).
Make sure your properties are in your Model.
Also you can make sure you View inherits your Model to get intellisense for it.
Inherits="System.Web.Mvc.ViewPage(Of Your Model)" %>