phalcon / phalcon/cphalcon

[NFR]: Forms should transform "" to NULL unless explicitly told not to

Open
#17,338 6 comments 0 reactions 1 assignee View on GitHub

@niden is already working on this.

Since Jul 14, 2026.

7.0 new feature request
Dominant language
PHP
Stars
10.8k
Forks
1.9k
Avg merge
7h 2m
Merged PRs (30d)
47

Description

Database
CREATE TABLE `accommodation` (
  ...
  `website` VARCHAR(60) DEFAULT NULL
  ...
Controller
// Request a transaction
$transaction = $this->transactionManager->get();

$accommodation = new Accommodation();
$accommodation->setTransaction($transaction);

...

$accommodationForm->bind(
    $_POST,
    $accommodation,
    [
        ...
        'website',
        ...
    ]
);

if ($accommodation->create() == false) {
    $transaction->rollback(__('Error has occured while creating accommodation'), $accommodation);
}

...

// no errors, commit changes
$transaction->commit();  
Form
// website input
$website = new Text('website');
$website->setLabel(__('Website'));
/*$website->addValidator(
    new Url(
        [
            "message" => __('Please enter valid website address')
        ]
    )
);*/
$this->add($website);
Expected behavior

DB field should be null when nothing was entered in the field

Actual behavior

DB field is empty string

Details
  • Phalcon version: 3.4.0
  • PHP Version: 7.2.8
  • Operating System: macOS
  • Installation type: Compiling from source
  • Server: Nginx
  • Database: MySQL 8.0.12

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.