cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Krijn Tanis" <i...@krijntanis.nl>
Subject CForms + MySQL (database)
Date Mon, 10 Mar 2008 06:59:36 GMT
Hello all,

 

For the last couple of weeks I am quite stuck on one thing within cocoon:
CForms and a database. The most forms are used to get data from a database
(search for example) or to put data in the database (user registration). The
main thing I want to do, it to put data from the form in a database. I think
there are two way to do this, the first way is to add some code to the
flowscript  and the second way is to do it with a XML file with a insert SQL
query. 

 

The main problem is, I don't know what I need to do exactly. The first way
to do it, I don't know what I need to include and what I need to program
there. In the second way I don't know how I get my return information back
to the XML script. I use CInclude in my cocoon application, so I don't know
how I can put the return vars in the right pipeline.  Maybe someone can tell
me how I can achieve it on the first or second way (although I prefer to do
it in the flowscript). 

 

My code (only relevant parts):

Main sitemap:

----------------------------------------------------------------------------
-------------------------------------------------

<map:pipelines>

 

 <map:pipeline>

  <!-- images -->

  <map:match pattern="images/*.gif">

   <map:read mime-type="image/gif" src="resources/images/{1}.gif"/>

  </map:match>

 

  <!-- CSS stylesheets -->

  <map:match pattern="styles/*.css">

   <map:read mime-type="text/css" src="resources/styles/{1}.css"/>

  </map:match>

 </map:pipeline>

 

 <map:pipeline internal-only="true">

  <map:match pattern="algemeen">

   <map:generate src="resources/layout/algemeen.xml"/>

   <map:serialize type="xml"/>

  </map:match>

  <map:match pattern="menu">

   <map:generate src="resources/layout/menu.xml"/>

   <map:serialize type="xml"/>

  </map:match>

 </map:pipeline>

                               

 <map:pipeline>

  <map:match pattern="layout">

   <map:aggregate element="index">

    <map:part src="cocoon:/algemeen" element="algemeen"/>

    <map:part src="cocoon:/menu" element="menu"/>

   </map:aggregate>

   <map:transform src="index.xsl"/>

   <map:serialize type="xml"/>

  </map:match>

 </map:pipeline>

 

 <map:pipeline>

 <map:match pattern="">

   <map:mount check-reload="yes" src="studenten/sitemap.xmap"
reload-methode="synchron" uri-prefix=""/>

  </map:match>

  <map:match pattern="*.continue">

   <map:mount check-reload="yes" src="cijfer_toevoegen/sitemap.xmap"
reload-methode="synchron" uri-prefix=""/>

  </map:match>

  <map:match pattern="*.*">

   <map:mount check-reload="yes" src="{1}/sitemap.xmap"
reload-methode="synchron" uri-prefix=""/>

  </map:match>

  <map:match pattern="*">

   <map:mount check-reload="yes" src="{1}/sitemap.xmap"
reload-methode="synchron" uri-prefix=""/>

  </map:match>

 </map:pipeline>

 

</map:pipelines>

----------------------------------------------------------------------------
-------------------------------------------------

 

Sub sitemap:

----------------------------------------------------------------------------
-------------------------------------------------

<?xml version="1.0"?>

<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">

 

  <map:components>

    <map:transformers default="xslt">

      <map:transformer name="cinclude"
src="org.apache.cocoon.transformation.CIncludeTransformer"/>

      <map:transformer name="i18n"
src="org.apache.cocoon.transformation.I18nTransformer">

        <catalogues default="forms">

          <catalogue id="forms" name="messages"
location="resource://org/apache/cocoon/forms/system/i18n"/>

        </catalogues>

        <cache-at-startup>true</cache-at-startup>

      </map:transformer>

    </map:transformers>

  </map:components>

 

  <map:flow language="javascript">

    <map:script src="script/cijfer_form.js"/>

  </map:flow>

 

  <map:pipelines>

 

   <map:pipeline>

 

     <map:match pattern="*.continue">

       <map:call continuation="{1}"/>

       <map:redirect-to uri="cocoon:/success"/>

     </map:match>

     

     <map:match pattern="content">

       <map:call function="formulier"/>

     </map:match>

     

     <map:match pattern="form_weergeven">

       <map:generate type="jx" src="content/cijfer_form_temp.xml"/>

       <map:transform src="xsl/page2html.xsl"/>

       <map:serialize type="xml"/>

       

     </map:match>

 

     <map:match pattern="resultaat_weergeven">

       <map:redirect-to uri="cocoon:/success"/>

     </map:match>

 

     <map:match pattern="resources/*/**">

       <map:read src="resource://org/apache/cocoon/{1}/resources/{2}"/>

     </map:match>

 

   </map:pipeline>

        <map:pipeline>

                                               <map:match pattern="success">

                                                               <map:mount
check-reload="yes" src="success/sitemap.xmap" reload-methode="synchron"
uri-prefix=""/>

                                               </map:match>

                               </map:pipeline>

                               <map:pipeline>

                                               <map:match pattern="layout">

                                                               <map:generate
src="cocoon://layout"/>

 
<map:serialize type="xml"/>

                                               </map:match>

                               </map:pipeline>

                               <map:pipeline>

                                               <map:match pattern="*">

                                                               <map:generate
src="cocoon:/layout"/>

 
<map:transform type="cinclude"/>

 
<map:serialize type="html"/>

                                               </map:match>

                               </map:pipeline>

 </map:pipelines>

</map:sitemap>

----------------------------------------------------------------------------
-------------------------------------------------

 

Flowscript:

----------------------------------------------------------------------------
-------------------------------------------------

cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");

 

function formulier() 

{

    var form = new Form("content/cijfer_form.xml");

 

    form.showForm("form_weergeven");

 

    var viewData = { "module_code" : form.getChild("module_code").getValue()
}

    cocoon.sendPage("resultaat_weergeven", viewData);

}

----------------------------------------------------------------------------
-------------------------------------------------

 

Cijfer_form.xml:

----------------------------------------------------------------------------
-------------------------------------------------

<fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition">

  <fd:widgets>

                <fd:field id="module_code" required="true">

      <fd:label>Module code:</fd:label>

      <fd:datatype base="string"/>

    </fd:field>

  

    <fd:field id="studentnummer" required="true">

      <fd:label>Studentnummer:</fd:label>

      <fd:datatype base="integer"/>

    </fd:field>

    

    <fd:field id="cijfer" required="true">

      <fd:label>Cijfer:</fd:label>

      <fd:datatype base="string"/>

    </fd:field>

    

    <fd:field id="datum" required="true">

      <fd:label>Datum:</fd:label>

      <fd:datatype base="string"/>

    </fd:field>

  </fd:widgets>

</fd:form>

----------------------------------------------------------------------------
-------------------------------------------------

 

Cijfer_form_temp.xml:

----------------------------------------------------------------------------
-------------------------------------------------

<div xmlns:ft="http://apache.org/cocoon/forms/1.0#template"
xmlns:fi="http://apache.org/cocoon/forms/1.0#instance"
xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">

  <jx:import
uri="resource://org/apache/cocoon/forms/generation/jx-macros.xml"/>

    <ft:form-template action="#{$continuation/id}.continue" method="POST">

     <table class='tabel'>

      <tr>

       <td class='contentkop'><ft:widget-label id="module_code"/></td>

       <td class='contentcel'><ft:widget id="module_code"/></td>

      </tr>

      <tr>

       <td class='contentkop'><ft:widget-label id="studentnummer"/></td>

       <td class='contentcel'><ft:widget id="studentnummer"/></td>

      </tr>

      <tr>

       <td class='contentkop'><ft:widget-label id="cijfer"/></td>

       <td class='contentcel'><ft:widget id="cijfer"/></td>

      </tr>

      <tr>

       <td class='contentkop'><ft:widget-label id="datum"/></td>

       <td class='contentcel'><ft:widget id="datum"/></td>

      </tr>

     </table>

     <p><input type="submit"/></p>

    </ft:form-template>

</div>

----------------------------------------------------------------------------
-------------------------------------------------

 

 

General information:

Cocoon version 2.1.10

 

I hope someone can help me with this,

 

Krijn Tanis

The Netherlands


Mime
View raw message