Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to save lines from "textarea"? #2276

Open
raxvell opened this issue Aug 10, 2022 · 2 comments
Open

How to save lines from "textarea"? #2276

raxvell opened this issue Aug 10, 2022 · 2 comments

Comments

@raxvell
Copy link

raxvell commented Aug 10, 2022

Now all text from "textarea" is saved as just solid text. How can I make the text stay in lines?

<textarea id="program_description" name="program_description" placeholder="Program description"></textarea>

`$program_description = $_POST['program_description'];

$document->setValue('program_description', $program_description);`

@TactiFail
Copy link

TactiFail commented Aug 10, 2022

I actually had the exact same problem yesterday, and I fixed it based off this comment:

#553 (comment)

I ended up doing the following in my controller:

public function process_newline_text($string)
{
    $lines = explode("\n", $string);
    $textrun = new TextRun();
    $textrun->addText(array_shift($lines));
    foreach ($lines as $line) {
        $textrun->addTextBreak();
        $textrun->addText(htmlspecialchars($line));
    }
    return $textrun;
}

$templateProcessor = new TemplateProcessor('template.docx');

$templateProcessor->setComplexValue(
    'someField',
    $this->process_newline_text($paragraph)
);

The htmlspecialchars() is optional, but needed in my situation. I tried to use the setting (I forget which it is) to auto-escape but it did not work for me.

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@github-actions github-actions bot added the Stale label Nov 9, 2022
@Progi1984 Progi1984 removed the Stale label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants