[opencms-dev] HTML forms

Joao Dias joao.dias at sybase.pt
Mon Jul 31 15:18:43 CEST 2006


Hi, 

 

I’ve altered the file list_events_right.jsp from the
org.opencms.frontend.templateone.modules module.

 

I’ve included a HTML form with 2 hidden fields, so that when I submit it, it
writes the data inputed on the database.

 

The strange thing is that, when I’m working Offline everything works fine
and the data is correctly inserted on the database. However when I’m testing
it Online, it doesn’t work. I’ve determined that when Offline the Strings
I’ve created are correct with the data sent from the form, when Online those
Strings are empty. 

 

Everything is correctly published.

 

Here is my code for that jsp (everything in bold is what I did for the
form):

 

 

 

 

<%@ page session="false" import="org.opencms.frontend.templateone.modules.*
, java.util.* , org.opencms.file.* , org.opencms.workplace.tools.content.*,
org.opencms.frontend.templateone.*" %><%--

--%><%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %><%--

--%><%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %><%--

--%><%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>

<jsp:directive.page import="java.sql.*" />

<%

 

CmsTemplateModules cms = new CmsTemplateModules(pageContext, request,
response);

CmsTemplateBean cmstb = new CmsTemplateBean(pageContext, request, response);

CmsElementChangeLocaleSettings cmsl = new CmsElementChangeLocaleSettings();

 

 

if (cmsl.getOldLocale() == null)

{

            cmsl.setOldLocale("pt");

}

 

// get currently active locale to initialize message bundle

String locale = cms.getRequestContext().getLocale().toString();

pageContext.setAttribute("locale", locale);

 

String folder = request.getParameter("folder");

String folderTitle = cms.property("Title", folder, "");

 

//String nome = new String("");

String nome = (String) request.getParameter("nomeutilizador");

if (nome == null){

            nome="";

}

 

//String email = new String("");

String email = (String) request.getParameter("emailutilizador");

if (email == null){

            email="";

}

 

System.out.println("NOME: " + nome);

 

if(!nome.equals("")) {

            Class.forName("org.gjt.mm.mysql.Driver");

            Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost:3306/opencms", "root",
"");

            Statement statement = connection.createStatement();

            String lc = (String) cmstb.getProperties().get("locale");

 

            statement.executeUpdate("insert into EMAILS values('" + nome +
"', '" + email + "', '" + lc + "');");

 

            statement.close(); 

            connection.close();

}

 

%>

 

<script LANGUAGE="JavaScript" SRC="../js/calendar.js"></script>

<script>

 

 

function saveemail() {

            

            var nome = document.newsletterform.nome.value;

            var email = document.newsletterform.email.value;

            

            if (document.newsletterform.nome.value=="") {

                        alert("Introduza o seu nome.");

                        return;

            }

            

            if (document.newsletterform.email.value=="") {

                        alert("Introduza o seu Email.");

                        return;

            }

            

            var emailRegxp =
/^([\w]+)(.[\w]+)*@([\w]+)(.[\w]+)*(.[\w]{2,3}){1,2}$/;

            if (emailRegxp.test(document.newsletterform.email.value) !=
true){

                                   alert("Formato do campo e-mail
incorrecto. O e-mail deve ser da forma: xxxxx at xxx.xx");

                                   return;

            }

                        

 

            document.newsletterform.nomeutilizador.value=nome;

            document.newsletterform.emailutilizador.value=email;

            

            alert(document.newsletterform.nomeutilizador.value);

            alert(document.newsletterform.emailutilizador.value);

            document.newsletterform.submit();

}

 

 

</script>

 

<cms:contentload collector="${param.collector}"
param="${param.folder}event_${number}.html|event|${param.count}"
preload="true"><%--

 

--%><cms:contentinfo var="contentInfo" scope="request" /><%--

--%><c:if test="${! contentInfo.emptyResult}"><%--

 

--%><fmt:setLocale value="${locale}" /><%--

--%><fmt:bundle
basename="org/opencms/frontend/templateone/modules/workplace"><%--

 

--%><div class="sidelist">

<!--<p class="sidelisthead"><% if (!"".equals(folderTitle)) {
out.print(folderTitle); } else { %><fmt:message key="events.headline" /><% }
%></p>-->

<img
src="/opencms/opencms/ccawww/resources/<%=cmstb.getProperties().get("locale"
)%>/imagens/_03.jpg"/>

<table valign="top" border="0" class="tableformat" width="187">

<tr>

<td>

<!--<p class="sidelisthead"></p>-->

<cms:contentload editable="true">

 

<p class="sidelistitem"><!--<a class="sidelistitemhead"
href="<cms:link><cms:contentshow element="${opencms.filename}" />?uri=<%=
cms.getRequestContext().getUri() %></cms:link>"><cms:contentshow
element="Title" /></a><br>-->

<cms:contentcheck ifexists="Date"><c:set var="dateString">

            <cms:contentshow element="Date" />

</c:set>

<%

            cms.setDate("dateString");

%>

<fmt:formatDate value="${date}" type="date" dateStyle="short" /> 

</td>

</tr>

<tr>

<td>

<cms:contentcheck
ifexists="Teaser"></cms:contentcheck></cms:contentcheck><cms:contentcheck
ifexists="Teaser"><cms:contentshow element="Teaser" /></cms:contentcheck>

<%if (cmstb.getProperties().get("locale").equals("pt")) {%>

<a class="sidelistitemhead" href="<cms:link><cms:contentshow
element="${opencms.filename}"
/>?uri=/ccawww/mundo_juridico.html</cms:link>">(+)</a>

<%}else {%>

            <a class="sidelistitemhead" href="<cms:link><cms:contentshow
element="${opencms.filename}"
/>?uri=/ccawww<%=cmstb.getProperties().get("locale")%>/mundo_juridico.html</
cms:link>">(+)</a>

<%}%>

</p>

</cms:contentload></div></td></tr></table>

<br>

<img
src="/opencms/opencms/ccawww/resources/<%=cmstb.getProperties().get("locale"
)%>/imagens/_04.jpg"/>

<table valign="top" border="0" class="tableformat" width="187">

<tr>

<td class="newsletter">

 

<%if (cmstb.getProperties().get("locale").equals("pt")){%>

            Subscreva já.<br>Introduza aqui o seu nome e email.

<%} else { if (cmstb.getProperties().get("locale").equals("en")){%>

            REGISTER NOW.<br>WRITE HERE YOUR NAME AND EMAIL.

<%} else {%>

            REGISTRO AHORA.<br>ESCRIBIR AQUÍ TU NOMBRE Y EMAIL.

<%} }%>

<tr> 

<form id="newsletterform" name="newsletterform" method=POST>

            <input type=hidden name=nomeutilizador id=nomeutilizador>

            <input type=hidden name=emailutilizador id=emailutilizador>

<td>

<input type="text" name="nome"/> 

</td>

</tr>

<tr>

<td>

<input type="text" name="email"/>

</td>

<td>

<label title='Gravar Email' style="cursor: pointer;"
onclick="javascript:saveemail();">

            <img
src="/opencms/opencms/ccawww/resources/<%=cmstb.getProperties().get("locale"
)%>/imagens/bt12.jpg" border=0>

</label>

</td>

</tr>

</form>

</td></tr></table>

<br><%--

--%></fmt:bundle></c:if></cms:contentload>

 

 

 

Thanks for your help,

João Dias

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20060731/5923c4da/attachment.htm>


More information about the opencms-dev mailing list