Search

I just tried to build a link that’s prepopulating multiple fields in a section, but didn’t manage to get it working.

I know the prepopulate-syntax looks different than the one used for filtering, but I thought adding a second parameter would simply work the same way. But obviously it does not:

.../images/new/?prepopulate[17]=15&prepopulate[33]=5

only prepopulates the first field whereas

../images/?filter=article:15&filter=position:5

works fine for both passed parameters.

I’m not sure if my syntax is just plain wrong or if prepopulating multiple fields simply isn’t possible, so any help would be appreciated.

Both filter and prepopulate only work with one field. Not sure how much extra work it’d be to make these work with arrays.

Are you sure the multiple filters actually work? If you pass two of the same name (filter) in a URL then PHP will only use one of them, the other is cancelled out. To use both you’d need to send them as an array:

../images/?filter[]=article:15&filter[]=position:5

But as I said, I don’t think Symphony picks these up.

Thanks for your quick answer Nick - you’re right: both only work with one parameter. I assumed filtering would work with 2 but that was just because it only takes the second parameter whereas prepopulating only seems to work with the first.

I’d really like to see this added to the core as it would definitively improve flexibility, though I have no idea how difficult it would be to implement… any chances we might see this in one of the upcoming releases?

Prepopulating multiple fields could be well done by an extension too I guess, but I don’t think I have the skills to develop it… but I may give it a try sometime soon.

Hi guys, first post here.

Unfortunately, I don’t think this could be done trough an extension, however I managed to patch the core.

Open symphony/content/content.publish.php Line ~437, find:

// Check if there is a field to prepopulate
if (isset($_REQUEST['prepopulate'])) {
    $field_id = array_shift(array_keys($_REQUEST['prepopulate']));
    $value = stripslashes(rawurldecode(array_shift($_REQUEST['prepopulate'])));

    $this->Form->prependChild(Widget::Input(
        "prepopulate[{$field_id}]",
        rawurlencode($value),
        'hidden'
    ));

    // The actual pre-populating should only happen if there is not existing fields post data
    if(!isset($_POST['fields']) && $field = $entryManager->fieldManager->fetch($field_id)) {
        $entry->setData(
            $field->get('id'),
            $field->processRawFieldData($value, $error, true)
        );
    }
}

replace with:

// Check if there is a field to prepopulate
if (isset($_REQUEST['prepopulate'])) {

    foreach ($_REQUEST['prepopulate'] as $field_id => $value) {

        $value = stripslashes(rawurldecode($value));

        $this->Form->prependChild(Widget::Input(
            "prepopulate[{$field_id}]",
            rawurlencode($value),
            'hidden'
        ));

        // The actual pre-populating should only happen if there is not existing fields post data
        if(!isset($_POST['fields']) && $field = $entryManager->fieldManager->fetch($field_id)) {
            $entry->setData(
                $field->get('id'),
                $field->processRawFieldData($value, $error, true)
            );
        }
    }
}

Still find my way around with git, so bare with me for not pushing, pulling or whatever on github. Would be nice to have some kind of guidelines for coding contributions.

Hope this helps, bye :)

Nice! I think it’s half way there — if you search for prepopulate inside content.publish.php there appear to be many more instances than just inside your code snippet, so be sure that this hasn’t broken things elsewhere.

Hi Nick!

You’ re right. I did some testing and it works and I’ m pretty sure It will not misbehave. However, re-scanning the code, I noticed this will only work with new entries.

Please report any issue :)

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