Giter Site home page Giter Site logo

Checkbox not working? about fpdm HOT 8 OPEN

codeshell avatar codeshell commented on July 24, 2024 1
Checkbox not working?

from fpdm.

Comments (8)

MelvinNau avatar MelvinNau commented on July 24, 2024 2

Same issue here.

Text for field is ok. But checkbox doesn't work

from fpdm.

asphub avatar asphub commented on July 24, 2024 2

Any progress on this issue. Still facing issues with checkboxes

from fpdm.

Amal-p avatar Amal-p commented on July 24, 2024 1

any possible solution this issue. still now 2022

from fpdm.

Amal-p avatar Amal-p commented on July 24, 2024 1

Did you tried like this ?
$fields = array( 'name' => 'My name', 'address' => 'My address', 'city' => 'My city', 'phone' => 'My phone number', 'checkbox1' => true );
It works fine for me.

Is you setting in properties checkbox?

not work in my case

from fpdm.

msiemaszko avatar msiemaszko commented on July 24, 2024 1

Hi, I have the same issue. I dig into the code and see that parser 'parsePDFEntries' is not finding the 'checkbox_yes' and 'checkbox_no' values, or they are simply not in my PDF file.
My PDF file was generated with AcrobarReaderPro and treated with pdftk.
How to properly prepare a pdf file to correctly fill checkbox fields via fpdm?

from fpdm.

GiovanniMounir avatar GiovanniMounir commented on July 24, 2024 1

I had the same issue; turns out that the checkbox_no and checkbox_yes infos were not populated, which are used by FPDM to detect the right values for on/off states. I harcoded the states to Off and Yes to workaround the issue.

This the modified set_field_checkbox function:

fpdm/src/fpdm.php line 940

public function set_field_checkbox($name, $value)
{
    /* START HARDCODE THE checkbox_no AND checkbox_yes VALUES  */
    if (!isset($this->value_entries["$name"]["infos"]["checkbox_no"])) $this->value_entries["$name"]["infos"]["checkbox_no"] = "Off";
    if (!isset($this->value_entries["$name"]["infos"]["checkbox_yes"])) $this->value_entries["$name"]["infos"]["checkbox_yes"] = "Yes";
    /* END HARDCODE THE checkbox_no AND checkbox_yes VALUES  */
    //------------------------------------
    $offset_shift=0;
    $verbose_set=($this->verbose&&($this->verbose_level>1));
    //Get the line(s) of the misc field values
    if (isset($this->value_entries["$name"])) {
        if (isset($this->value_entries["$name"]["infos"]["checkbox_state_line"])
        && isset($this->value_entries["$name"]["infos"]["checkbox_no"])
        && isset($this->value_entries["$name"]["infos"]["checkbox_yes"])) {
            $field_checkbox_line=$this->value_entries["$name"]["infos"]["checkbox_state_line"];
            if ($field_checkbox_line) {
                if ($verbose_set) {
                    echo "<br>Change checkbox of the field $name at line $field_checkbox_line to value [$value]";
                }
                $state = $this->value_entries["$name"]["infos"]["checkbox_no"];
                if ($value) {
                    $state = $this->value_entries["$name"]["infos"]["checkbox_yes"];
                }
                $CurLine =$this->pdf_entries[$field_checkbox_line];
                $OldLen=strlen($CurLine);
                $CurLine = '/AS /'.$state;
                $NewLen=strlen($CurLine);
                $Shift=$NewLen-$OldLen;
                $this->shift=$this->shift+$Shift;
                //Saves
                $this->pdf_entries[$field_checkbox_line]=$CurLine;
                return $Shift;
            // $offset_shift=$this->_set_field_value($field_checkbox_line, $state);
            } else {
                if ($verbose_set) {
                    echo "<br>Change checkbox value aborted, parsed checkbox definition incomplete.";
                }
            }
        } else {
            if ($verbose_set) {
                echo "<br>Change checkbox value aborted, the field $name has no checkbox definition.";
            }
        }
    } else {
        $this->Error("set_field_checkbox failed as the field $name does not exist");
    }
    return $offset_shift;
}

The function will afterwards use the hardcoded checkbox_yes value ("Yes") when a value is provided, or checkbox_no ("Off") in case there is no value provided (i.e empty, false, etc)

Example usage:

$fields = array(
"CHECKBOX_FIELD_NAME" => true //or any value that is not empty/false/0/etc
);
$fpdm = new FPDM('fillable_pdf_example.pdf');
$fpdm->useCheckboxParser = true;
$fpdm->Load($fields, true);
$fpdm->Merge();
$fpdm->Output();

from fpdm.

Robszyy avatar Robszyy commented on July 24, 2024

Did you tried like this ?

$fields = array( 'name' => 'My name', 'address' => 'My address', 'city' => 'My city', 'phone' => 'My phone number', 'checkbox1' => true );

It works fine for me.

from fpdm.

nusamata avatar nusamata commented on July 24, 2024

Did you tried like this ?

$fields = array( 'name' => 'My name', 'address' => 'My address', 'city' => 'My city', 'phone' => 'My phone number', 'checkbox1' => true );

It works fine for me.

Is you setting in properties checkbox?

from fpdm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.