Home
Download
Add-ons
Help
Forum
Organisation
Project
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
February 12, 2012, 03:40:07 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter
hier
und auf unserer
neuen Webseite
.
149659
Posts in
21100
Topics by
7539
Members
Latest Member:
ionline
WebsiteBaker Community Forum
English
Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
(Moderator:
Argos
)
x_cForm
Pages: [
1
]
Go Down
Author
Topic: x_cForm (Read 4267 times)
aldus
Offline
Posts: 1238
x_cForm
«
on:
September 03, 2008, 02:41:10 PM »
A simple modul snipplet for a class for
formulars
forms
Once you have the modul installed you can use a class "cForm" to build forms.
Notice: this is not QuickForm (PEAR) and it is not mean as a portation to WebsiteBaker at all;
even no recoding of the package.
Current Version: 0.1.3.beta - 2008-10-07
update: multiple selections support
Requirements:
WebsiteBaker 2.7
PHP 5.2.x
Known issues
No options/radio - groups
No validations
No file-upload
ToDo - Roadmap
add options/radio - groups
add simple client/serverside validations
file-upload
Bugfix in 0.1.2 Alpha: Checkbox-bugfix for missplaced "'" single quote ...
Bugfix in 0.1.1 Alpha: Typos ("cancle" instead of "cancel")
Any kind of improvment, critics, recomentations, code-cleanings, warnings and grumble
are always wellcome.
Some examples:
If you want to use this class in the backend you are in the need to import it first, like
Code:
<?php
require_once (
WB_PATH
.
'/modules/x_cform/include.php'
);
?>
If you want to use it inside a template you don't need it.
Initial within some formattributes, you can use any valid attribute as you like inside an assoc. array.
Code:
<?php
$form_attribs
= Array (
'name'
=>
"wb_addresses_form"
,
'class'
=>
"xForm"
,
'action'
=>
$_SERVER
[
'PHP_SELF'
]
);
$form
= new
c_form
(
$form_attribs
);
?>
Add a hidden field with the name "id" and a typical value to the formular
Code:
<?php
$form
->
addElement
( Array (
'type'
=>
'hidden'
,
'name'
=>
"id"
,
"value"
=>
$_REQUEST
[
'id'
]) );
?>
Add a textfield with an label to the formular
Code:
<?php
$form
->
addElement
( Array (
'type'
=>
'text'
,
'label'
=>
ucfirst
(
$i
),
'name'
=>
$i
,
'value'
=>
$data
[
$i
] ) );
?>
Add a textarea to the formular
Code:
<?php
$form
->
addElement
( Array (
'type'
=>
'textarea'
,
'label'
=>
ucfirst
(
$i
),
'name'
=>
$i
,
'content'
=>
$data
[
$i
] ) );
?>
Add a select to the formular
As a "content" you will have to pass an assoc. array in the form "Key" = value, where the Key is display
in the popup menu. You can also pass a "select"-value to the select.
Code:
<?php
$content
= array (
'Anna'
=>
1
,
'Judith'
=>
2
,
'Mary Lou'
=>
3
,
'Xanthippe'
=>
4
}
$form
->
addElement
( Array (
'type'
=>
'select'
,
'label'
=>
ucfirst
(
$i
),
'name'
=>
$i
,
'content'
=>
$group_select
,
'select'
=>
3
) );
?>
Add a submit-button within some javascript.
Code:
<?php
$form
->
addElement
( Array (
'type'
=>
'submit'
,
'name'
=>
'submit'
,
'value'
=>
$TEXT
[
'SAVE'
],
'onclick'
=>
"this.submit();"
) );
?>
update 0.1.3: support for multiple select ...
Code:
<?php
$form
->
addElement
( Array (
'type'
=>
'select'
,
'name'
=>
"group_id[]"
,
'label'
=>
$ADDRESSES
[
'DISPLAYGROUP'
],
'content'
=>
$group_select
,
'select'
=>
explode
(
","
,
$temp_data
[
'groups'
]),
// !
'multiple'
=>
'multiple'
,
'size'
=>
4
,
'onload'
=>
"alert(this);"
) );
?>
echo the complete form out of a module or template
Code:
<?php
echo
$form
->
toHTML
();
?>
Also supported types are "html", for "pur" html-code, "button", "cancel" and "checkbox".
To modify the output you can manipulate/change the template-strings (all public):
- $form_template - holds the complete form, default is:
"\n<form {{ attribs }}>\n{{ hidden }}\n<table>\n{{ content }}</table>\n</form>\n";
within the markers for
{{ attribs }} ::
the formular-attributes, e.g. name, class, onchange, onsubmit, action, method ...
{{ hidden }} ::
where to place the hidden values; by default at the begin of the formular
{{ content }} ::
the complete formular-content
- $element_template - holds a single element, default is:
"<tr>\n\t<td class='left'>{{ label }}</td>\n\t<td class='right'>{{ content }}</td>\n</tr>\n"
within the markers for
{{ label }} ::
where to display the label of the element
{{ content }} ::
where to display the element
So if you want to display the formular-elements inside divs you can easy overwrite the templates as you needed.
Regards
Aldus
«
Last Edit: October 07, 2008, 01:59:43 PM by aldus
»
Logged
aldus
Offline
Posts: 1238
Re: x_cForm
«
Reply #1 on:
September 15, 2008, 06:28:02 PM »
Update/Bugfix for 0.1.2 alpha
- Bugfix for "checkboxes" -> missplaced single quote bug ... could be problematic for some browsers
- Minor typos in the "info.php!" ...
Regards
Aldus
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4755
Re: x_cForm
«
Reply #2 on:
September 15, 2008, 08:52:21 PM »
Quote from: aldus on September 03, 2008, 02:41:10 PM
Any kind of improvment, critics, recomentations, code-cleanings, warnings and grumble
are always wellcome.
Have some "grumble"
I don't get the clue what this is all about.
I can't figure out what to do with this - no idea.
But looks very interesting.
Maybe a working example would help understanding.
Regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
aldus
Offline
Posts: 1238
Re: x_cForm
«
Reply #3 on:
September 16, 2008, 10:52:05 AM »
Make a new Page, Type: "code2", and place the following inside (PHP)
Code:
<?php
/**
* @version 0.1.0
* @date 2008-09-16
* @author aldus
* @package WebsiteBaker - code-examples
*
*/
$form_attribs
= Array (
'name'
=>
"search"
,
'class'
=>
"xForm"
,
'action'
=>
WB_URL
.
"/search/index.php"
);
$form
= new
c_form
(
$form_attribs
);
$form
->
addElement
( Array (
'type'
=>
'hidden'
,
'name'
=>
"page_id"
,
"value"
=>
$page_id
) );
$form
->
addElement
( Array (
'type'
=>
'hidden'
,
'name'
=>
"section_id"
,
"value"
=>
$section_id
) );
$form
->
addElement
( Array (
'type'
=>
'text'
,
'label'
=>
"Suchbegriff: "
,
'name'
=>
"string"
,
'style'
=>
"display:block;float:left;width:200px;"
)
);
$form
->
addElement
( Array(
'type'
=>
'html'
,
'content'
=>
" "
) );
$form
->
addElement
( Array (
'type'
=>
'submit'
,
'name'
=>
'submit'
,
'value'
=>
"Suchen"
,
'onclick'
=>
"this.submit();"
,
'style'
=>
"display:block;float:left;width:200px;"
)
);
echo
$form
->
toHTML
();
?>
As for other working examples you can take a look at "addresses" ...
Regards
Aldus
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4755
Re: x_cForm
«
Reply #4 on:
September 16, 2008, 12:04:44 PM »
Quote from: aldus on September 16, 2008, 10:52:05 AM
Make a new Page, Type: "code2", and place the following inside (PHP)
Cool.
Best Regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
Argos
Moderator
Offline
Posts: 2084
Re: x_cForm
«
Reply #5 on:
September 19, 2008, 12:52:23 PM »
What's a "formular"?
Can someone please explain in a few sentences what this thingy is and does, without people having to install it first?
Thanks.
Logged
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase:
http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
aldus
Offline
Posts: 1238
Re: x_cForm
«
Reply #6 on:
September 19, 2008, 01:05:49 PM »
Quote from: Argos on September 19, 2008, 12:52:23 PM
What's a "formular"?
Can someone please explain in a few sentences what this thingy is and does, without people having to install it first?
Thanks.
I must apologize for the "dinglish" and the confusion about the word - it's simple a form.
Regards
Aldus
Logged
aldus
Offline
Posts: 1238
Re: x_cForm
«
Reply #7 on:
October 07, 2008, 02:01:42 PM »
Update for 0.1.3 -
multiple select support for elementType "select".
Regards
Aldus
Logged
FrankH
Offline
Posts: 735
Re: x_cForm does not work
«
Reply #8 on:
March 19, 2009, 12:23:07 PM »
I just installed x_cForm 0.14 from AMASP successfully.
But when I want to add a page, I can't choose this page type x_cForm because I don't see it in the list.
What's wrong here?
Logged
Ochs und Esel in ihrem Lauf
halt ich leider auch nicht auf
aldus
Offline
Posts: 1238
Re: x_cForm
«
Reply #9 on:
March 19, 2009, 12:56:53 PM »
Because it's a "code"-modul (snippet) - not a page-module like "form" ...
To use it for the frontend you can use a code/code2 page like in the examples.
If you want to use it for the backend, e.g. inside a modul in "modify.php", you will have to include it first.
Regards
Aldus
Logged
bschaich
Offline
Posts: 25
Re: x_cForm
«
Reply #10 on:
September 24, 2011, 01:18:28 AM »
I found a small bug in your snippet and maybe I can get some help in return...
In line 358 of include.php there is one parameter too much, which brings up an error in php 5.3, as this parameter is deprecated.
Code:
$t = mktime( 0, 0, 0, $month, 1, 1, 2001);
However, the deprecated parameter was never intended to use, instead you just can delete on of the numbers "1", as they obviously somehow doubles unintended. Why the code worked anyways I did not follow up.
Well, and now here is my problem:
I see I can do nice date fields with that class, but how can this be integrated with a form? I expect I have somehow to do an addelement() with the date, but don't get it... Any hints?
regards,
Benny
Logged
Kant
Offline
Posts: 1
Re: x_cForm
«
Reply #11 on:
September 24, 2011, 01:34:50 PM »
Hello Benny
There is a littel "test.php" inside the modules itsleft within some example-code for the use of "dateSelect".
The simples way is to place it as an HTML-content - e.g.
Code:
<?php
/**
*
Just a simple call within inside a code/code2 section
*
Please keep in mind, you don't have to include the module file here, as this one
*
is a code-snippet.
*
If you want to use it in the backend you will have to include it first, e.g.
*
require_once (WB_PATH."/modules/x_cForm/include.php");
*
*/
$form_args
= array(
'method'
=>
"post"
,
'action'
=>
"#"
,
'class'
=>
"my_example_form_class"
);
$form
= new
c_form
(
$form_args
);
/**
*
Add a simple date-select
*
*/
$form
->
addElement
( array(
'type'
=>
"html"
,
'name'
=>
"example"
,
'content'
=>
$form
->
dateSelect
(),
'label'
=>
"example"
)
);
/**
*
Add submit button
*
*/
$form
->
addElement
( array (
'type'
=>
'submit'
,
'name'
=>
'submit'
,
'value'
=>
$TEXT
[
'SAVE'
],
'onclick'
=>
"this.submit();"
)
);
echo
$form
->
toHTML
();
unset(
$form
);
e.g. inside a code/code2 section. As for the (mini)-bug - thanks - as far as i can see version 0.2.0 is uploaded on AMASP.
Kind regards
Logged
sapere aude
bschaich
Offline
Posts: 25
Re: x_cForm
«
Reply #12 on:
September 24, 2011, 10:24:52 PM »
Thanks a lot, that was quite helpful!
Regards,
Benny
Logged
bschaich
Offline
Posts: 25
A "cancel" button?
«
Reply #13 on:
November 22, 2011, 08:50:50 PM »
Hi,
here is some of my code:
Code:
$form->addElement( Array (
'type' => 'submit',
'name' => 'submit',
'value' => "Sichern",
'onclick' => "this.submit();",
'style' => "display:block;float:left;width:100px;"
)
);
$form->addElement( Array (
'type' => 'cancel',
'name' => 'cancel',
'value' => "Abbrechen",
'style' => "display:block;float:right;width:100px;"
)
);
These are two buttons, a Submit and a Cancel button. Unfortunately the "cancel" button is interpreted as Textfield. I also checked the code of x_cForm and the word "cancel" is used as type directly. I cannot find anywhere in HTML a type "cancel". Actually the name of the type is "reset"...
Am i getting something wrong here?
Regards,
Benny
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4755
Re: x_cForm
«
Reply #14 on:
November 23, 2011, 03:16:11 AM »
The second array must have value of 'submit' in the 'type' index.
Regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
Bug
Offline
Posts: 181
Re: x_cForm
«
Reply #15 on:
November 23, 2011, 09:46:26 PM »
Can someone describe why to use this in stead of pmform?
Logged
bschaich
Offline
Posts: 25
Re: x_cForm
«
Reply #16 on:
December 05, 2011, 12:08:35 AM »
Quote from: Bug on November 23, 2011, 09:46:26 PM
Can someone describe why to use this in stead of pmform?
Good question. I need those values to put them into a database. To my knowledge PMForm puts all data into one field. This does not allow the use of foreign keys and a couple of more reasons why data usually is put into DB...
I'd be glad if I'm not right....
regards,
Benny
Logged
Pages: [
1
]
Go Up
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> General Announcements
-----------------------------
English
-----------------------------
=> Help & Support
-----------------------------
General
-----------------------------
=> WebsiteBaker Website Showcase
-----------------------------
English
-----------------------------
=> Modules
=> Templates, Menus & Design
=> WebsiteBaker Language Files
=> Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
-----------------------------
General
-----------------------------
=> Guest Area & Off-Topic
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.x discussion
=> WebsiteBaker 3
-----------------------------
General
-----------------------------
=> Security Announcements
-----------------------------
Deutsch (German)
-----------------------------
=> Hilfe/Support
-----------------------------
General
-----------------------------
=> Documentation
-----------------------------
Francais (French)
-----------------------------
=> Help/Support
-----------------------------
Italiano (Italian)
-----------------------------
=> Help/Support
-----------------------------
Deutsch (German)
-----------------------------
=> Ankündigungen
=> Diskussion über WB
=> Off-Topic
=> Archiv für Themen bis 2007
=> Module & Snippets
-----------------------------
English
-----------------------------
=> Archive (posts up to 2007)
-----------------------------
Nederlands (Dutch)
-----------------------------
=> Aankondigingen
=> Hulp & Ondersteuning
=> Niet-Terzake (Off Topic)
-----------------------------
Deutsch (German)
-----------------------------
=> jQuery
=> Tutorials
=> Templates & Design
-----------------------------
English
-----------------------------
=> jQuery
-----------------------------
Bakery (WB shop module)
-----------------------------
=> Bakery English
=> Bakery Deutsch
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.9
===> Announcements
===> Help/Support
===> Suggestions
-----------------------------
Deutsch (German)
-----------------------------
=> WebsiteBaker 2.9
===> Ankündigungen
===> Hilfe/Support
===> Vorschläge
-----------------------------
English
-----------------------------
===> Software bugs
-----------------------------
Deutsch (German)
-----------------------------
===> Softwarefehler
=====> Module / Extensions
-----------------------------
English
-----------------------------
=====> Modules / Extensions
-----------------------------
Deutsch (German)
-----------------------------
===> Erfahrungs und Testberichte
-----------------------------
KeepInTouch (Multi Contact Module)
-----------------------------
=> KeepInTouch English
=> KeepInTouch Deutsch
Loading...