Maintain field IDs in Export/Import

Labels

This Discussion is public

Notifications

I have created a form in my development environment and now I want to import it into my live site. However this does always change the involved IDs (e.g. of fields). That results in conditional not working and moreover my custom verification code has to be re-written everytime because as far as I know I can only use the fields' IDs for it?

Does anyone have an idea how syncing between development and productive installation can/should work?

Use field keys as references, not field IDs. Field keys don't change. Field IDs change because they depend on internal WordPress counters that will be different on every site unless you clone the entire database.

Ok, thanks!
That is fine for the validation part where I can check for the key and then use the ID for setting the error

if($posted_field->field_key == "KEY") {
$errors['field'.$posted_field->id] == "Error";
}

Still I don't know how I would be able to replace ID by KEY in reading other fields

$_POST['item_meta'][ID]

or in reading fields from an entry

$entry = FrmEntry::getOne( $item_id, true );
$entry->metas[VARIANTENFIELDID]

And the conditional logic for showing/hiding fields (as it can be defined in the UI) works with IDs. That is why it won't work after an import.

I don't think I am the only one dealing with these problems? The only solution I see for now would be to sync the involved wp_frm_forms and wp_frm_fields?

Every array Formidable builds has key as a value. For example, you are referencing $posted_field->id, use $posted_field->key

The browser's $_POST array also has key. $_POST['item_meta'][KEY]

If you use a debugger like Kint in your dev environment, you'll be able to examine the values of the PHP arrays and objects in real time.

Also, you can examine the post array in your browser's inspection tool in the network tab.

When you're importing and exporting, you have to use key otherwise you'll never get it to work. The only way to sync IDs is by cloning the database. You can't synchronize any other way because field id is generated by the internal counters WordPress creates for every element. Attempting to synchronize field IDs will break your WordPress installation.

Thanks again for your help! But at least in my installation this is not the case and theĀ $_POST array does not contain entries for KEYs only for IDs.

Not sure if you have any hook or configuration change in place that enables it.

I've never had a problem with importing/exporting after I switched to using keys. It just works.

Reply to this Discussion