Okay I am loosing my mind over a simple thing like building a form
I needed to know how it works so I started building my own forms.
I`ve downloaded Skeleton module wchich passes variables to another php file.
Copied the part I needed but mine aint passing anything:
Original
Code: Select all
<?php
/**
*
* This is an example of a method to add
* database data on page using a template.
*
* If the "skeleton_id" parameter is set, this page will
* allow you to edit that record. Otherwise, it will let you
* add a new record .
*
* Note that it uses a template, and is thus very powerful,
* even if it's simple.
*/
/**
* For separated methods, you'll always want to start with the following
* line which check to make sure that method was called from the module
* API, and that everything's safe to continue:
*/
if (!isset($gCms)) exit;
// don't trust that this was safe, just because the link is hidden if the option is off!
// always code defensively! There are beasties that lurk and things go bump in the night.
if (! $this->GetPreference('allow_add',1) == 1) exit;
/**
* After this, the code is identical to the code that would otherwise be
* wrapped in the action.
*/
// get our records from the database
$db = $gCms->GetDb();
if (isset($params['skeleton_id']))
{
$query = 'SELECT skeleton_id, description, explanation from '.cms_db_prefix().
'module_skeleton where skeleton_id = ?';
$result = $db->Execute($query,array($params['skeleton_id']));
if ($result !== false)
{
// load in the record if there was no error
$row=$result->FetchRow();
$sid = $row['skeleton_id']; // stupid -- we're passing the param, and then using the database version.
$desc = $row['description'];
// we decode this next one, because it gets stored encoded, and the CreateTextArea API encodes as well, so
// if we didn't decode it, we'd get double encoding.
$exp = html_entity_decode($row['explanation']);
}
else
{
// yeah, that's graceful :(
echo "Database error!";
exit;
}
}
else
{
// if we didn't retrieve a record, set some default values
$sid = -1;
$desc = '';
$exp = '';
}
// set up form for Smarty
$smarty->assign('start_form', $this->CreateFormStart($id, 'save_record', $returnid));
// give Smarty translated field titles
$smarty->assign('title_description',$this->Lang('title_description'));
$smarty->assign('title_explanation',$this->Lang('title_explanation'));
// create inputs for the Form elements, and pass them to Smarty. You'd best look up the crazy long parameter
// lists for the Form API in lib/classes/class.module.inc.php
$smarty->assign('input_description',$this->CreateInputText($id,'description',$desc));
$smarty->assign('input_explanation',$this->CreateTextArea(true, $id, $exp, 'explanation', '', '', '', '', 40, 5));
// pass a hidden key value along with the submit button
$smarty->assign('submit', /*$this->CreateInputHidden($id,'skeleton_id',$sid).*/$this->CreateInputSubmit($id, 'submit', $this->Lang('submit')));
$smarty->assign('end_form', $this->CreateFormEnd());
// Display the populated template
echo $this->ProcessTemplate('add_edit.tpl');
?>
And the tpl
Code: Select all
{$start_form}
<div class="form_row">
<span class="field_title">{$title_description}</span>
<span class="field_input">{$input_description}</span>
</div>
<div class="form_row">
<span class="field_title">{$title_explanation}</span>
<span class="field_input">{$input_explanation}</span>
</div>
<div class="form_row">
<span class="field_title"></span>
<span class="field_input">{$submit}</span>
</div>
{$end_form}
And its passing the variables in the URL
&mact=Skeleton,cntnt01,default,0&cntnt01returnid=2&cntnt01returnid=2&cntnt01description=q2e4rfqwe&cntnt01explanation=fqwefqwef&cntnt01module_message=Added%20record.
Now lets copy the part I need and it should do the same
Code: Select all
$smarty->assign('start_form', $this->CreateFormStart($id, 'save_record', $returnid));
// give Smarty translated field titles
$smarty->assign('title_description',$this->Lang('title_description'));
$smarty->assign('title_explanation',$this->Lang('title_explanation'));
// create inputs for the Form elements, and pass them to Smarty. You'd best look up the crazy long parameter
// lists for the Form API in lib/classes/class.module.inc.php
$smarty->assign('input_description',$this->CreateInputText($id,'description',$desc));
$smarty->assign('input_explanation',$this->CreateTextArea(true, $id, $exp, 'explanation', '', '', '', '', 40, 5));
// pass a hidden key value along with the submit button
$smarty->assign('submit', /*$this->CreateInputHidden($id,'skeleton_id',$sid).*/$this->CreateInputSubmit($id, 'submit', $this->Lang('submit')));
$smarty->assign('end_form', $this->CreateFormEnd());
And the tpl
Code: Select all
{$start_form}
<div class="form_row">
<span class="field_title">{$title_description}</span>
<span class="field_input">{$input_description}</span>
</div>
<div class="form_row">
<span class="field_title">{$title_explanation}</span>
<span class="field_input">{$input_explanation}</span>
</div>
<div class="form_row">
<span class="field_title"></span>
<span class="field_input">{$submit}</span>
</div>
{$end_form}
But its not passing the variables in the URL
?mact=AutoReparatie,cntnt01,default,0&cntnt01returnid=1&cntnt01returnid=1&cntnt01module_message=Added%20record.
Difference
&mact=Skeleton,cntnt01,default,0&cntnt01returnid=2&cntnt01returnid=2&cntnt01description=q2e4rfqwe&cntnt01explanation=fqwefqwef&cntnt01module_message=Added%20record.
I have build several websites for my customers with CMSMS because I love to work with it but I have been trying to build a form now for 3 days.
I am really loosing my mind because I cant get a simple form to work.
What am I missing, probably something simple but I cannot figure out what?