Skip to content

fix: reject duplicate FieldID on add-new-field instead of silently overwriting - #127

Merged
alorbach merged 1 commit into
masterfrom
copilot/fix-duplicate-validation-add-field
May 6, 2026
Merged

alorbach merged 1 commit into
masterfrom
copilot/fix-duplicate-validation-add-field

Conversation

Copilot AI commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

The add-field POST handler in admin/fields.php used a single INSERT-or-UPDATE code path regardless of whether the request came from the "add new field" or "edit field" form. Submitting a new field with an existing FieldID silently overwrote the existing record.

Changes

  • src/admin/fields.php — Before INSERT/UPDATE, check $_POST['op']. When op=addnewfield and the FieldID already exists in the DB, set an error and abort instead of falling through to UPDATE. The editfield path is unchanged.
if ( $_POST['op'] == "addnewfield" && isset($myrow['FieldID']) )
{
    $content['ISERROR'] = true;
    $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_FIELDS_ERROR_FIELDIDEXISTS'], $content['FieldID'] );
}
else if ( !isset($myrow['FieldID']) )
{
    // INSERT ...
}
else
{
    // UPDATE (edit path only) ...
}
  • src/lang/{en,de,es,ja}/admin.php — Add LN_FIELDS_ERROR_FIELDIDEXISTS: "A field with the FieldID '%1' already exists. Use the edit function to modify an existing field."

Summary by cubic

Reject duplicate FieldID when adding a new field to prevent silent overwrites and provide a clear, localized error message.

  • Bug Fixes
    • In src/admin/fields.php, when op=addnewfield and the FieldID exists, return an error and do not update; edit flow is unchanged.
    • Added LN_FIELDS_ERROR_FIELDIDEXISTS to src/lang/{en,de,es,ja}/admin.php for consistent messaging.

Written for commit 1ac0570. Summary will update on new commits.

@alorbach

alorbach commented May 6, 2026

Copy link
Copy Markdown
Member

@codex review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@alorbach
alorbach merged commit 57b4b10 into master May 6, 2026
6 checks passed
@alorbach
alorbach deleted the copilot/fix-duplicate-validation-add-field branch May 6, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants