Jump to content

Recommended Posts

Posted

Hello everyone!

I'm stumbling upon a form, again... I'm trying to get the Text out of my Form with the newline characters. I'm using PW 2.5.3

What I have in Code a little bit cut down:

$form = $modules->get("InputfieldForm");
$form->action = "./";
$form->method = "post";
$form->attr("id+name",'subscribe-form');

// create a textarea input for the actual message
$field = $modules->get("InputfieldTextarea");
$field->label = "Nachricht";
$field->attr('id+name','message');
$field->required = 1;
$form->append($field); // append the field to the form

// form was submitted so we process the form
if($input->post->submit) {

    $message = $sanitizer->textarea($form->get("message")->value);

	$out .= "<strong>Nachricht:</strong></br>";	
	$out .= $message."</p>";

} else {
    // render out form without processing
    $out .= $form->render();
}

I can't get it with newlines, what am I doing wrong?

 

Thanks in advance for your support :-) 

Posted

Sanitizer removes linefeeds. Allow multiline in the options array. This one should work:

$message = $sanitizer->textarea($form->get("message")->value, array('multiLine' => true));
// or 
$message = $sanitizer->textarea($input->post->message, array('multiLine' => true));

 

Posted

Sorry I forgot an important detail, it was a little bit late yesterday :-)

@kixe I tried this "multiline" option. Unfortunately it doesn't work.

I also tried the following code:

$message = $form->get("message")->value;

$message does not contain newline characters, so I suspect to set an option in this code:

$field = $modules->get("InputfieldTextarea");
$field->label = "Nachricht";
$field->attr('id+name','message');
$field->required = 1;
$form->append($field); // append the field to the form

 

Posted (edited)

The simple thing we was missing (if not another) is nl2br() - @phippu try :

$out .= nl2br($message);

You should get your multiline output.

Edited by flydev
link reference
Posted

Thank you very much! That's very logic, but wasn't aware of this behavior... It's now working!

shouldn't this php method be implemented in Textarea? Just a thought... :rolleyes:

 

 

Posted

Newline characters are the de facto correct way of handling newlines in text. It's just that html does not care about them, which is why you need <br> tags instead. 

  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...