Search

I'm trying to write my first extension. I've created a class that extends AdministrationPage. I have also made the following requirements:

require_once(TOOLKIT . '/class.administrationpage.php');
require_once(TOOLKIT . '/class.mysql.php');
require_once(TOOLKIT . '/class.entry.php');

I've been able to create a new tab in the Symphony control panel, create different pages and develop a form that I am trying to post to different db tables that were created when the extension was installed on the test server. The form mark up looks like this.

 <form action="http://wjn.com/symphony/extension/peopleManager/contacts/addProcess" method="post" name="addContact" encoding="multipart/form-data">

When the form posts I cannot recall the $_POST['contact'] array. When I test for it, it seems to not be set at all.

**How does one successfully post using the Symphony OOP framework?**

Thanks for your help.

wjnielsen, just to be sure: You don't have to create own form. It's created by AdministrationPage class. You just add fields to it inside view() function:

$fields = $_POST['fields'];
$fieldset = new XMLElement('fieldset');
$fieldset->setAttribute('class', 'settings');
$fieldset->appendChild(new XMLElement('legend', __('Essentials')));
$label = Widget::Label(__('Name'));
$label->appendChild(new XMLElement('i', __('Enter some name')));
$label->appendChild(Widget::Input('fields[name]', $fields['name']));
$fieldset->appendChild((isset($this->_errors['name']) ? $this->wrapFormElementWithError($label, $this->_errors['name']) : $label));
$this->Form->appendChild($fieldset);

At the and of view() function add submit button like this:

$div = new XMLElement('div');
$div->setAttribute('class', 'actions');
$div->appendChild(Widget::Input('action[save]', ($this->_context[0] ? __('Save Changes') : __('Create translation')), 'submit', array('accesskey' => 's')));
$this->Form->appendChild($div);

Then inside action() function:

if (array_key_exists('save', $_POST['action'])) $this->save();

And then create save() function with:

$name = trim($_POST['fields']['name']);
if (strlen($name) < 1) {
    $this->_errors['name'] = __('You have to specify some name.');
    return;
}

One more thing: it's good to look into existing extensions code for examples. And probably also Symphony's core code too. I got most of answers to my "how to..." questions just by reading code written by others :).

ahwayakchih,

Thanks for the tips. Since my initial post I've been able to get my forms posting by working through some of the other extensions and core classes of Symphony (as you suggested).

You confirmed I was on the right path with making the form using $label->appendChild(Widget::Input('fields[name]', $fields['name'])); and etc. So thank you very much for that.

Could you help me understand a bit about the following code you posted?

 $div->appendChild(Widget::Input('action[save]', ($this->_context[0] ? __('Save Changes') : __('Create translation')), 'submit', array('accesskey' => 's')));

How does the $this->_context[0] var work here?

Thanks again for your help.

wjnielsen, glad i could help.

Context variable is... not needed in that example. I was copying code form one of my extensions (which was earlier copied from parts of Symphony ;), and forgot to clean up that part.

_context variable contains parameters passed through URL. For example, if You create "extensionexample" with page called "edit", URL will look like:

symphony/extension/extensionexample/edit/

Every additional path node will be parsed as parameter (except for word "symphony" which seems to screw things up if You use it in path, at least it did last time i tried :). So, for example:

symphony/extension/extensionexample/edit/handle1/option2/whatever3/

will make _context array look like:

_context = array(
    0 => 'handle1',
    1 => 'option2',
    2 => 'whatever3',
);

As far as i know, Symphony uses maximum 2 parameters for it's administration pages, but You can use more if needed.

Marcin,

Thanks much that helps and saves __soooo__ much time.

I'm glad i could help :).

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details