Textfied with auto append <BR>
Moderator: General Moderators
Textfied with auto append <BR>
Hi, I'm new here, I need to find answer to my question thats why I got a way here.
I just wanted my textfield to be automatically append <BR> tag in every end of the lines before the contents save to my database.
Example:
this is just a test records for my database from my textfield.
This is just a test.
Just another test
After saving it in my database that will looks like this inside may database.
this is just a test records for my database from my textfield.<BR>
This is just a test.<BR>
Just another test<BR>
I need to make in that way coz without <BR> tag, data are appeared in my table cell in only one line.
Thanks.
I just wanted my textfield to be automatically append <BR> tag in every end of the lines before the contents save to my database.
Example:
this is just a test records for my database from my textfield.
This is just a test.
Just another test
After saving it in my database that will looks like this inside may database.
this is just a test records for my database from my textfield.<BR>
This is just a test.<BR>
Just another test<BR>
I need to make in that way coz without <BR> tag, data are appeared in my table cell in only one line.
Thanks.
Re: Textfied with auto append <BR>
Btw, it's not textfield, I am using TextArea for user inputs.
I tried this codes
But it doesn't work. Did I missed a thing?
Anyway it save my data to database but still no <br> tag in each new line.
I tried this codes
Code: Select all
<?php
$value = $_POST['newsArticle']
?>Code: Select all
$post['newsArticle'] = str_replace(array("\r\n", "\r", "\n"), "<br />", $value);Anyway it save my data to database but still no <br> tag in each new line.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: Textfied with auto append <BR>
Firstly, you are likely not saving the altered data to your database, correctly. $post and $_POST are not the same.
Secondly, nl2br() does what you want, as suggested by ~kaszu.
Secondly, nl2br() does what you want, as suggested by ~kaszu.
Re: Textfied with auto append <BR>
My data is saving successfully in my database but in straight line with no <br> tag append.superdezign wrote:Firstly, you are likely not saving the altered data to your database, correctly. $post and $_POST are not the same.
Secondly, nl2br() does what you want, as suggested by ~kaszu.
Can you help me to revise my code with nl2br2()? Sorry for that I'm newbie php.
here is the other part of the code:
<?php
$value = $_POST['newsArticle']
?>
Code: Select all
<?php
require_once 'News.php'; // Include The News Class
$news = new News(); // Create a new News Object
if(isset($_POST['addNews'])) // If the submit button was clicked
{
$post['newsTitle'] = $_POST['newsTitle'];
// add the news title to the $post array
$post['newsArticle'] = str_replace(array("\r\n", "\r", "\n"), "<br />", $value);
// add the news article to the $post array
//$post['postDateTime'] = date;
// add the current time and date to the $post array
$post['userId'] = 1;
// You can ignore userId, unless you have mutilple users
$post['currentStatus'] = 'Enabled';
// This will make sure its displayed
if($news->addNews($post))
{
echo 'The News was Added Succesfully<br/>'; // if adding was successful display this message
}
}
?>Re: Textfied with auto append <BR>
I tried to use nl2br()
But no data was save into my database after submit. although other info are save but not the content of my textarea
Here is my codes
But no data was save into my database after submit. although other info are save but not the content of my textarea
Here is my codes
Code: Select all
<?php
function nl2br2($alterednews) {
$alterednews =str_replace(array("\r\n", "\r", "\n"), "<br />", $_POST['newsArticle']);
return ($alterednews);
}
?>
<?php
require_once 'News.php'; // Include The News Class
$news = new News(); // Create a new News Object
if(isset($_POST['addNews'])) // If the submit button was clicked
{
$post['newsTitle'] = $_POST['newsTitle'];
// add the news title to the $post array
$post['newsArticle'] = $alterednews;
// add the news article to the $post array
//$post['postDateTime'] = date;
// add the current time and date to the $post array
$post['userId'] = 1;
// You can ignore userId, unless you have mutilple users
$post['currentStatus'] = 'Enabled';
// This will make sure its displayed
if($news->addNews($post))
{
echo 'The News was Added Succesfully<br/>'; // if adding was successful display this message
}
}
?>Re: Textfied with auto append <BR>
In you first code $value and in second code $alterednews are undefined (not defined). Try
Code: Select all
<?php
require_once 'News.php'; // Include The News Class
$news = new News(); // Create a new News Object
if(isset($_POST['addNews'])) // If the submit button was clicked
{
$post['newsTitle'] = $_POST['newsTitle'];
// add the news title to the $post array
$post['newsArticle'] = nl2br($_POST['newsArticle']); //$value and $alterednews were used here, but not defined before
// add the news article to the $post array
//$post['postDateTime'] = date;
// add the current time and date to the $post array
$post['userId'] = 1;
// You can ignore userId, unless you have mutilple users
$post['currentStatus'] = 'Enabled';
// This will make sure its displayed
if($news->addNews($post))
{
echo 'The News was Added Succesfully<br/>'; // if adding was successful display this message
}
}
?>Re: Textfied with auto append <BR>
Ouch sorry for that..I forgot to define first. Anyways, I solve my problem. I use nl2br() function, I just define just what you said. Thanks