[TYPO3-dev] Showing / Using Forms with checkboxes in own extension

bernd wilke xoonsji02 at sneakemail.com
Tue Feb 19 02:43:32 CET 2008


on Wed, 13 Feb 2008 15:10:50 +0100, Ansgar Brauner wrote:

> Hi there,
> 
> i've got a few questions about developing FE-Extensions with formulars.
> 
> First of all i'd like to know if there is some kind of tutorial "how to
> develop an extension using HTML Templates and formulars"?
> 
> Another question is how can i use radio-buttons and checkboxes to
> display content retrieved from the DB backend and how can i change this
> values.
> 
> I did found the short tutorial about using HTML-Templates but nothing
> about using forms in those extensions.
> 
> The goal should be:
> 
> 1st time a page is shown the current values should be retrieved from the
> DB-Backend.
> 
> In the 2nd Step the user can change those values.
> 
> in the 3rd and last step the user submitts the form, the values in the
> backend are changed and the form is shown again with new values.
> 
> I hope everything is explained well enough. Thanks in advance
> 
> best regards
> 
> Ansgar

no real tutorial, but some thoughts:

// 1. fill in defaultvalues from DB
$records=$GLOBALS['TYPO3_DB']->exec_SELECTgetRows(...);
$ma=$records[0];

// 2. fill in some global values for form-template
$ma['prefixid']=$this->prefixId;
$ma['action']=$this->pi_getPageLink($GLOBALS['TSFE']->id);

// 3. replace fields from form
foreach ((array)($this->piVars) as $k=>$v) {
	$ma[$k]=$v;
}

if ($this->piVars['submit'] && $this->validate($ma)) {
    if ($this->piVars['accept'] ) {
	// show values to accept
	$content .= $this->cObj->substituteMarkerArray($tplacceptpart
                                                      ,$ma
                                                      ,'###|###'
                                                      ,1
                                                      );
    } else {
	// send mail
	mail(...);
	
	// save to DB
	$fv=$ma;
	$res=$GLOBALS['TYPO3_DB']->exec_INSERTquery( ... , $fv);
    }
} else {
	// show form
	$content .= $this->cObj->substituteMarkerArray($tplformpart
                                                      ,$ma
                                                      ,'###|###'
                                                      ,1
                                                      );
}

and in the template something like this:
<!-- ###FORM### start -->
<div class="a-form">
    <h2>your message:</h2>
    <p class="bodytext">
	<div class="errinfo">###REQINFO###</div>
    </p>
    <form action="###ACTION###" method="POST">
        <input type="hidden" name="###PREFIXID###[name]" 
value="###NAME###" />
        <input type="hidden" name="###PREFIXID###[submit]" value="1" />
	<div class="info"><div class="msg"><b>###MSG###</b><br /></div></
div>
:
        <div class="info">
		<div class="button">
			<input type="submit" name="###PREFIXID###
[preview]" value="preview">
		</div>
	</div>
    </form>
</div>
<!-- ###FORM### stopp -->


<!-- ###PREVIEW### start -->
<p class="bodytext">
	everything ok?
</p>
<div class="previewform">
    <p class="bodytext">
	<br /><span class="errinfo">###REQINFO###</span>
    </p>

    <div class="info"><div class="prompt">name   </div>
                      <div class="inp">###NAME###</div></div>
	:

    <form action="###ACTION###" method="POST">
        <input type="hidden" name="###PREFIXID###[name]"       
value="###NAME###"       />
	:
        <div class="info button">
		<div class="prompt"><input type="submit" 
name="###PREFIXID###[back]" value="Back" /></div>
		<div class="fcdata"><input type="submit" 
name="###PREFIXID###[accept]" value="accept" /></div>
	</div>
    </form>
</div>
<!-- ###PREVIEW### stop -->


good luck
Bernd
-- 
http://www.pi-phi.de/t3v4/cheatsheet.html




More information about the TYPO3-dev mailing list