Long Text

Allikas: Juhised

Handling of a long text value in forms[muuda]


If using a textarea then the form part should look like this:

  1. 							<textarea id="content" name="content" rows="3" cols="40"
  2. 								onkeyup="document.getElementById('previewOContent').innerHTML = this.value;"
  3. 								onmouseup="document.getElementById('previewOContent').innerHTML = this.value;">{VALUE-CONTENT}</textarea>
  5. 							<script type="text/javascript">
  6. imageBrowse = "{PATH-TO-ROOT-FOLDER}whizzybrowse3.php?d=assets/images/upload";
  7. linkBrowse = "{PATH-TO-ROOT-FOLDER}whizzybrowse3.php?d=assets/images/upload";
  8. makeWhizzyWig("content", "all");
  9. 							</script>
  11. 							<br/>
  12. 							<span id="content_remaining" class="remaining"></span>

If we do not want to show a real-time preview then we ignore the onkeyup and onmouseup events. Anyway, it only works without Whizzywig's editor.

If we want to show how many characters he/she has entered and how many are necessary and what is the limit then we need the last span element. We can suppress JavaScript to validate the field value before we submit it by adding this script (the script needs the id of the field to be set):

validanguage.el =
		errorMsg: "Palun sisesta menüütekst, mille pikkus on kõige rohkem 12 märki.",
		onblur: true,
		onsubmit: true,
		required: true


We have to get the values either from the validated form elements or directly:

		$valOContent = '';
		if (isset ($validatedElements) &&
				isset ($validatedElements['content']->value))
			$valOContent = $validatedElements['content']->value;
		else if (isset ($email->content))
			$valOContent = $email->content;

There where we put the value into a variable of the template we do it like this:

			'VALUE-OF-CONTENT' => $valOContent,

If we have to display an error message then we do it like this:

			'ERROR-OF-CONTENT' => (!isset ($validatedElements) ||
					!isset ($validatedElements['content']->error)) ?
					'&#160;' : $validatedElements['content']->error,


The class must have a variable of the chosen object on the form:

	 * @var string the email content
	var $content;

In the constructor, the value must be set:

				$this->content = func_get_arg(8);

We have to remember the entered values if something goes wrong:

			new ElementToValidate('content', $this->content, array (

The queries will be constructed up to the database structure and therefore, there is no standard method to show here. But do not forget to update the set-method!


There where we construct the object we put the form value in:

				$email = new Email(
			isset ($_POST['content']) ? $_POST['content'] : NULL
					[other values]

For the rich text editor, we need to load the JS file:

				$pageAdminView->buildPage(array (
					'php', // needed for whizzywig
					'sport', // needed for whizzywig
				), $page, array (), 'NewsInAdmin', FALSE, $news);

Remember that if you get an error message that whizzies is not found then you have to ensure that the file php.js is loaded.


Sometimes, it is necessary to add a corresponding field into the database: