I am new to liferay, and want to create a custom web form portlet having multiple jsp.
like on one jsp i have to display the all details for the user i.e first name last name etc with next button (it will redirect the user to another jsp) that contains a message box with submit button.
after click on submit button the data from both jsp will be save in database!
i have created a register.jsp page
<%#include file="/init.jsp" %>
<html>
<body>
<form action="<portlet:actionURL></portlet:actionURL>" method="post" name="userForm" onsubmit="return Account();">
<b>First Name:</b>
<input type="text" name="<portlet:namespace/>firstName" id="<portlet:namespace/>firstName"/><br/>
<b>Last Name:</b>
<input type="text" name="<portlet:namespace/>lastName" id="<portlet:namespace/>lastName"/><br/>
<b>E-mail:</b>
<input type="text" name="<portlet:namespace/>eMail" id="<portlet:namespace/>eMail"/><br/>
<b>Age:</b>
<select name="<portlet:namespace/>age">
<option value="20">20</option>
<option value="20-25">20-25</option>
<option value="25-30">25-30</option>
<option value="30-35">30-35</option>
<option value="35+">35+</option>
</select><br/>
<b>Region:</b>
<select name="<portlet:namespace/>region">
<option value="east">east</option>
<option value="west">west</option>
<option value="north">north</option>
<option value="south">south</option>
</select><br/>
<b>Gender</b><br/>
<input type="radio" name="<portlet:namespace/>sex" value="male">Male<br>
<input type="radio" name="<portlet:namespace/>sex" value="female">Female<br/>
</form>
<br/> <button class="btn btn-primary">Go Back</button>
<portlet:renderURL var="submitDetailURL">
<portlet:param name="jspPage" value="/submit.jsp"/>
</portlet:renderURL>
<button class="btn btn-primary">Next</button>
and the next button will redirect to submit.jsp page
<%#include file="/init.jsp" %>
<html>
<body>
<form action='<portlet:actionURL></portlet:actionURL>' method="post" name="valid" onsubmit="return Account();">
<b>Message:</b>
<textarea rows="4" cols="50" name="<portlet:namespace/>address">
</textarea>
<button class="btn btn-primary">Go Back</button>
<input type="submit" name="addUser" id="addUser" value="Submit">
</tr>
</form>
</body>
</html>
and my service.xml is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
<service-builder package-path="com.yogisha">
<author>Sony</author>
<namespace>yogisha</namespace>
<entity name="Campaign" local-service="true" remote-service="false">
<column name="campaignId" type="long" primary="true"></column>
<column name="firstName" type="String"></column>
<column name="lastName" type="String"></column>
<column name="eMail" type="String"></column>
<column name="age" type="String"></column>
<column name="region" type="String"></column>
<column name="sex" type="String"></column>
<column name="content" type="String"></column>
</entity>
</service-builder>
but it seems like its not working. can anyone tell my what i am missing?
Related
I have a custom module and i want to create a website form for my module. In the backend form the is a section where user enters service details through a one2many field. The form is to be made available to portal users on the website.How do i implement one2many field on the website so that the information can be recorded in backend??This is my backend form view
This is my website form.I've been able to do first part of form and need help with many2one
<template id="online_request_form">
<t t-call="portal.portal_layout">
<t t-set="breadcrumbs_searchbar" t-value="True"/>
<t t-call="portal.portal_searchbar">
<t t-set="title">Service Request</t>
</t>
<div id="wrap" class="oe_structure oe_empty">
<section class="s_website_form" data-vcss="001" data-snippet="s_website_form">
<div class="container">
<form action="/submit/request" method="post" enctype="multipart/form-data" class="o_mark_required" data-mark="*" data-model_name="" data-success-page="">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
<table style="border:0px; width:100%%; background-color:#D6EEEE; margin-top:5%%;">
<group>
<tr>
<td>
<group>
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 50%%" for="studio1">
<span class="s_website_form_label_content">Agency</span>
<span class="s_website_form_mark"> *</span>
</label>
<div class="col-sm">
<select name="agency" t-attf-class="form-control s_website_form_input" required="1">
<option value=""><i>Please Select</i></option>
<t t-foreach="agencies or []" t-as="agency">
<option t-att-value="agency.id">
<t t-esc="agency.name" />
</option>
</t>
</select>
</div>
</group>
<group>
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 50%%" for="studio1">
<span class="s_website_form_label_content">Agent</span>
<span class="s_website_form_mark"> *</span>
</label>
<div class="col-sm">
<select name="agent" t-attf-class="form-control s_website_form_input" required="1">
<option value=""><i>Please Select</i></option>
<t t-foreach="agents or []" t-as="agent">
<option t-att-value="agent.id">
<t t-esc="agent.name" />
</option>
</t>
</select>
</div>
</group>
</td>
<td>
<group>
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 50%%" for="studio1">
<span class="s_website_form_label_content"> IMDG Code / Un No.</span>
<span class="s_website_form_mark"> *</span>
</label>
<div class="col-sm">
<input id="imdg_code" type="text" class="form-control s_website_form_input" name="imdg_code" required="1"/>
</div>
</group>
<group>
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 50%%" for="studio1">
<span class="s_website_form_label_content">Phone</span>
<span class="s_website_form_mark"> *</span>
</label>
<div class="col-sm">
<input id="phone" type="text" class="form-control s_website_form_input" name="phone" required="1"/>
</div>
</group>
</td>
</tr>
</group>
<tr>
<td>
<group>
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 50%%" for="studio1">
<span class="s_website_form_label_content">Email</span>
<span class="s_website_form_mark"> *</span>
</label>
<div class="col-sm">
<input id="email" type="text" class="form-control s_website_form_input" name="email" required="1"/>
</div>
</group>
</td>
</tr>
</table>
<div style="width:200px; margin-top:2%%;" class="form-group col-12 s_website_form_submit" data-name="Submit Button">
<div class="s_website_form_label"/>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</section>
</div>
</t>
</template>
The template for website form.
#http.route('/service_requests', type='http', auth="user", website=True)
def service_request(self):
products = request.env['product.template'].sudo().search([])
agencies = request.env['res.partner'].sudo().search([])
agents = request.env['res.users'].sudo().search([])
values = {}
values.update({
'products': products,
'agencies': agencies,
'agents':agents,
'page_name': 'new_request',
})
return request.render("service_request.online_request_form", values)
Corresponding controller
I add multi radio box in twig page like this:
<div class="cc-selector">
<input id="avatar-1" type="radio" name="avatar" value="1" />
<label class="drinkcard-cc avatar-1" for="avatar-1"></label>
<input id="avatar-2" type="radio" name="avatar" value="2" />
<label class="drinkcard-cc avatar-2" for="avatar-2"></label>
<input id="avatar-3" type="radio" name="avatar" value="3" />
<label class="drinkcard-cc avatar-3" for="avatar-3"></label>
<input id="avatar-4" type="radio" name="avatar" value="4" />
<label class="drinkcard-cc avatar-4" for="avatar-4"></label>
<input id="avatar-5" type="radio" name="avatar" value="5" />
<label class="drinkcard-cc avatar-5" for="avatar-5"></label>
<input id="avatar-6" type="radio" name="avatar" value="6" />
<label class="drinkcard-cc avatar-6" for="avatar-6"></label>
</div>
in Output in see whitespace:
how do can i remove whitespace in twig template?!
You can use spaceless filter. It will do exactly what you want : removing whitespace between HTML elements only (keeping the ones inside).
Using this in Twig :
{% apply spaceless %}
<div class="cc-selector">
<input id="avatar-1" type="radio" name="avatar" value="1" />
<label class="drinkcard-cc avatar-1" for="avatar-1"></label>
<input id="avatar-2" type="radio" name="avatar" value="2" />
<label class="drinkcard-cc avatar-2" for="avatar-2"></label>
<input id="avatar-3" type="radio" name="avatar" value="3" />
<label class="drinkcard-cc avatar-3" for="avatar-3"></label>
<input id="avatar-4" type="radio" name="avatar" value="4" />
<label class="drinkcard-cc avatar-4" for="avatar-4"></label>
<input id="avatar-5" type="radio" name="avatar" value="5" />
<label class="drinkcard-cc avatar-5" for="avatar-5"></label>
<input id="avatar-6" type="radio" name="avatar" value="6" />
<label class="drinkcard-cc avatar-6" for="avatar-6"></label>
</div>
{% endapply %}
Will give this HTML :
<div class="cc-selector"><input id="avatar-1" type="radio" name="avatar" value="1" /><label class="drinkcard-cc avatar-1" for="avatar-1"></label><input id="avatar-2" type="radio" name="avatar" value="2" /><label class="drinkcard-cc avatar-2" for="avatar-2"></label><input id="avatar-3" type="radio" name="avatar" value="3" /><label class="drinkcard-cc avatar-3" for="avatar-3"></label><input id="avatar-4" type="radio" name="avatar" value="4" /><label class="drinkcard-cc avatar-4" for="avatar-4"></label><input id="avatar-5" type="radio" name="avatar" value="5" /><label class="drinkcard-cc avatar-5" for="avatar-5"></label><input id="avatar-6" type="radio" name="avatar" value="6" /><label class="drinkcard-cc avatar-6" for="avatar-6"></label></div>
Since the contents of the template is HTML I'd advise you to use SeeoX's approach.
But I've decided to mention the other option to assign the contents of a template to a variable and apply filters which could be useful sometimes:
{% set contents %}
{% include ('cc-selector.twig') %}
{% endset %}
contents spaceless:
{{ contents | spaceless }}
replace only new lines:
{{ contents | replace({"\n": ""}) | raw }}
working example
It may be because of the linebreak between the input & the label. Removing that space may/may not help, but try that.
<div class="cc-selector">
<input id="avatar-1" type="radio" name="avatar" value="1" /><label class="drinkcard-cc avatar-1" for="avatar-1"></label><input id="avatar-2" type="radio" name="avatar" value="2" /><label class="drinkcard-cc avatar-2" for="avatar-2"></label><input id="avatar-3" type="radio" name="avatar" value="3" /><label class="drinkcard-cc avatar-3" for="avatar-3"></label><input id="avatar-4" type="radio" name="avatar" value="4" /><label class="drinkcard-cc avatar-4" for="avatar-4"></label><input id="avatar-5" type="radio" name="avatar" value="5" /><label class="drinkcard-cc avatar-5" for="avatar-5"></label><input id="avatar-6" type="radio" name="avatar" value="6" /><label class="drinkcard-cc avatar-6" for="avatar-6"></label>
</div>
I need to call document library portlet's EditFileEntryAction (core liferay) on submitting my custom form.
I have created following actionURL:
<liferay-portlet:actionURL var="editFileEntryURL" portletName="<%=PortletKeys.DOCUMENT_LIBRARY %>" doAsGroupId="${scopeGroupId}" refererPlid="${plid}">
<portlet:param name="struts_action" value="/document_library/edit_file_entry" />
<portlet:param name="uploader" value="classic" />
</liferay-portlet:actionURL>
and I want to submit below form:
<aui:form action="<%= editFileEntryURL %>" cssClass="lfr-dynamic-form" enctype="multipart/form-data" method="post" name="fm">
<aui:input name="<%= Constants.CMD %>" type="hidden" />
<aui:input name="uploadProgressId" type="hidden" value="<%= uploadProgressId %>" />
<aui:input name="repositoryId" type="hidden" value="${themeDisplay.scopeGroupId}" />
<aui:input name="folderId" type="hidden" value="${categoryFolderId}" />
<aui:input name="fileEntryId" type="hidden" value="0" />
<aui:input name="workflowAction" type="hidden" value="<%= WorkflowConstants.ACTION_PUBLISH %>" />
<aui:input name="file" style="width: auto;" type="file">
<aui:validator name="acceptFiles">
'<%= StringUtil.merge(PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA)) %>'
</aui:validator>
</aui:input>
<aui:input name="title">
<aui:validator errorMessage="you-must-specify-a-file-or-a-title" name="custom">
function(val, fieldNode, ruleValue) {`enter code here`
return ((val != '') || A.one('#<portlet:namespace />file').val() != '');
}
</aui:validator>
</aui:input>
<aui:button type="submit" value="save" name="save" />
</aui:form>
I'd recommend to not have the HTTP-level cross-dependency on Liferay's document library portlet. Rather implement your own upload portlet and use the document library API to store the file yourself.
I have a form and formit call that works in one site and not another, which is a direct copy of the first [migrating to a new design] The sites are identical right now, files & database were just copied. All the plugins were checked and even reinstalled.
What I have is:
<!-- contact page -->
[[!FormIt?
&placeholderPrefix=`contact.`
&hooks=`spam,email,redirect,FormItAutoResponder`
&emailTo=`[[GetSystemSetting? &setting=`emailContactMailTo`]]`
&emailSubject=`domain.com Contact form has been submitted. [[+contact.subject]]`
&emailTpl=`ContactCustomEmailTpl`
&redirectTo=`346`
&emailReplyTo=`no-reply#domain.com`
&submitVar=`contactSubmit`
&validate=`name:required,email:email:required,subject:required,text:required:stripTags`
&fiarSubject=`Your contact request to domain.com`
&fiarTpl=`ContactCustomEmailTpl`
&fiarReplyTo=`no-reply#domain.com`
]]
<form class="form" action="[[~[[*id]]]]" method="post" role="form">
<input type="hidden" name="nospam:blank" value="" />
<div class="row">
[[!+contact.error_message:notempty=`<div class="col-sm-12"><div class="alert alert-danger">[[!+contact.error_message]]</div></div>`]]
<div class="col-sm-4[[+contact.error.name:notempty=` has-error`]]">
<div class="form-group">
<label for="name"> Name: *</label>
<input id="name" type="text" name="name" value="[[!+contact.name]]" class="form-control" />
</div>
</div>
<div class="col-sm-4[[+contact.error.email:notempty=` has-error`]]">
<div class="form-group">
<label for="email"> Email: *</label>
<input id="email" type="text" name="email" value="[[!+contact.email]]" class="form-control" />
</div>
</div>
<div class="col-sm-4[[+contact.error.subject:notempty=` has-error`]]">
<div class="form-group">
<label for="subject"> Subject: *</label>
<input id="subject" type="text" name="subject" value="[[!+contact.subject]]" class="form-control" />
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12[[+contact.error.text:notempty=` has-error`]]">
<div class="form-group">
<label for="text"> Message: *</label>
<textarea id="text" name="text" rows="7" class="form-control">[[!+contact.text]]</textarea>
</div>
</div>
<div class="col-sm-6 col-sm-offset-3">
<div class="form-group">
<label> </label>
<input class="btn btn-primary btn-block" type="submit" name="contactSubmit" value="Send Contact Inquiry" onClick="_gaq.push(['_trackEvent', 'ContactPage', 'Contact Submitted']);" />
</div>
</div>
</div>
</form>
</div>
The form will work if I remove the 'FormItAutoResponder' from the &hooks AND all items from the &validate parameters.
What is wrong with this form?
no usefull errors in modx or server logs
reinstalled formit
isolated it in a test page with no other markup
the emailTpl is present and mail gets sent if the 2 parameters are removed from the formit call
Perhaps the GetSystemSetting snippet is missing? Why not just use [[++emailContactMailTo]] instead?
Are the MODX and FormIt versions the same on both sites?
Try calling this debug snippet somewhere below the FormIt call. Look for unshown errors (starting with contact.error.) or any other unexpected placeholders.
Here is my code of send-page:
<p>[[!FormIt?
&hooks=`email,FormItLog,spam,emailUser,redirect`
&emailTo=`heash94#gmail.com`
&emailSubject=`[[+subject]]`
&emailFromName=`[[+name]]`
&emailTpl=`ContactTpl`
&redirectTo=`62` ]]</p>
<div>[[+fi.error.error_message]]</div>
<form action="[[~[[*id]]]]" method="post"><input type="hidden" name="nospam:blank" value="" />
<div>
<label for="name">Name: </label> <input id="name" type="text" name="name:required" value="[[+fi.name]]" /> <span>[[+fi.error.name]]</span>
</div>
<div>
<label for="name">Email: </label> <input id="email" type="text" name="email:email:required" value="[[+fi.email]]" /> <span>[[+fi.error.email]]</span></div>
<div>
<label for="subject">Theme: </label> <input id="subject" type="text" name="subject:required:stripTags" value="[[+fi.subject]]" /> <span>[[+fi.error.subject]]</span></div>
<div>
<label for="message">Text: </label><span>[[+fi.error.message]]</span> <br /> <textarea id="message" name="message:required:stripTags" rows="7" cols="55">[[+fi.message]]</textarea></div>
<div>
<input type="submit" name="Submit" value="Отправить" /></div>
</form>
I tried many examples, but they send to my email empty messages.
Here is my reciver-page code:
This message [[+name]] ([[+email]]) was sand with callback form:
[[+message]]
But in response I have only "This message () was sent with callback form: ".
Modx Revolution.
Sounds like modx is not seeing the name="email:email:required" as 'email' - put your CSS/JS validation in another attribute & also use the &validate attribute for the formit call.