FORUM IS CLOSED. PLEASE USE QUESTIONS / ANSWERS PAGE INSTEAD
Login  |  Forum  |  Search   

Board index » Development » Help requests




Post new topic Reply to topic  [ 4 posts ] 
 
Author Message
 Post subject: Adding new form field type to contact form
 Post Posted: Wed Jul 11, 2012 7:03 am 
Offline

Joined: Mon Jan 30, 2012 1:16 pm
Posts: 15
Hi,

I am in the process of adding a new type of form field (Select Dynamic) to my web page in order to let a customer pick from list products in the database in the contact form.

For a test I would just like to replicate the functionality of the static Select field, so what I do is I subscribe to the contentManagement.collectFieldTypes event in my plugin and create a new field type, in this way:

Code:
$newFieldType = new \Modules\standard\content_management\FieldType('IpSelectDyn', '\Modules\CustomFormFields\SelectDyn', $typeSelect . " dynamic", 'ipWidgetIpForm_InitListOptions', 'ipWidgetIpForm_SaveListOptions', \Ip\View::create('view/form_field_options/list.php')->render());
$event->addField($newFieldType);


For now the SelectDyn class just consists of inheriting everything from Select class:

Code:
class SelectDyn extends \Modules\developer\form\Field\Select {

    public function __construct($options = array()) {
   parent::__construct($options);
        print_r($options["values"]);
    }
}


The problem I get is that $options does not contain index "values" and thus the drop-down field is empty even though my class does absolutely nothing else except inherits from "Select". The entered values of my SelectDyn field however do get saved in the database and when editing a form they get correctly loaded with the ipWidgetIpForm_InitListOptions Javascript function.

I can't quite figure out the mechanism to debug this error further, can anyone point me in the right direction? I'm using IP 2.2.

Thanks and best regards,
Roman


Top 
 Profile  
 
 Post subject: Re: Adding new form field type to contact form
 Post Posted: Wed Jul 11, 2012 7:43 pm 
Offline
Project Developer

Joined: Tue Apr 28, 2009 9:43 am
Posts: 1720
Constructor gets the data that has been returned by JS function ipWidgetIpForm_SaveListOptions.

But if you want to populate select with products from database, you don't need "options" next to your input. That means you can skip last tree parameters in field initialization:

$newFieldType = new \Modules\standard\content_management\FieldType('IpSelectDyn', '\Modules\CustomFormFields\SelectDyn', $typeSelect . " dynamic");


And get data from database in the constructor:

public function __construct($options = array()) {
$options = data from DB in the way \Modules\developer\form\Field\Select expects it
parent::__construct($options);
}


Top 
 Profile  
 
 Post subject: Re: Adding new form field type to contact form
 Post Posted: Thu Jul 12, 2012 10:05 am 
Offline

Joined: Mon Jan 30, 2012 1:16 pm
Posts: 15
Hello, thank you for your answer - the problem I have is that the ipWidgetIpForm_SaveListOptions function does indeed return data, but the constructor does not receive it. Maybe it has something to do with inheriting my field from Select class and not from Field class.

Anyway, halfway through my debugging I have realized just as you have suggested, shunned the "Options" and filled in my values from the DB in the constructor. This is pretty much the result I was going for, but I wanted to make it a bit more universal, i.e. I wanted to specify the table and the value fields of the in the "Options" for the field and not have one custom class for each dropdown from Db (Products, People, ...).

Best regards,
Roman


Top 
 Profile  
 
 Post subject: Re: Adding new form field type to contact form
 Post Posted: Thu Jul 12, 2012 5:36 pm 
Offline
Project Developer

Joined: Tue Apr 28, 2009 9:43 am
Posts: 1720
Ok. I know why your options values were not passed to the constructor.

Look at this line:

$newFieldType = new \Modules\standard\content_management\FieldType('IpSelectDyn', '\Modules\CustomFormFields\SelectDyn', $typeSelect . " dynamic", 'ipWidgetIpForm_InitListOptions', 'ipWidgetIpForm_SaveListOptions', \Ip\View::create('view/form_field_options/list.php')->render());
$event->addField($newFieldType);

You need to extend: \Modules\standard\content_management\FieldType and use your extended class in this line.

Overwrite "createField" function in the way you need for your field to work.


Top 
 Profile  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 4 posts ] 

Board index » Development » Help requests


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron