This is a tricky question, and I think only Itamar can answer it.
In my dataform, I need to access the value of one field from another field.
Basically on the submission of the entry, the "shorturl" field needs to know the value of another field, "longurl" and then do some processing on it, and store it elsewhere.
The name of the other field can change. The relevant code is below.
$cd->target contains the name of the other field, which we are after. We get the dataform, entry and field objects fine. But the value of the field is nowhere and the $entry object just contains ids and no data. $so ultimately $longurl comes back as empty. I am sure this should be possible but I don't know how to do it.
//Get the dataform, entrymanager and entry
$df = \mod_dataform_dataform::instance($cd->dataformid, null, true);
$entryman = \mod_dataform_entry_manager::instance($cd->dataformid,0);
$entry = $entryman->get_entry_by_id($cd->entryid);
// Get the field name.
list($fieldname) = explode(':', trim($cd->target, '#[]'));
//Try to get the field value into $longurl variable
$options=array();
if ($field = $df->field_manager->get_field_by_name($fieldname)) {
if ($replacements = $field->renderer->get_replacements(array($cd->target), $entry, $options)) {
$replacement = reset($replacements);
$longurl =$replacement;
}}