Forum Moderators: coopster
I have a form with a textarea so users can update db entries. After the form is submitted it is sent to a validation script where, among other checks, I run the nl2br() function using the following line of code:
$formVars["newsAbstract"] = nl2br($formVars["newsAbstract"]);
This function works, and when I go back to the textarea in the user form I can see the inserted <br /> tags. So if I enter the following text into the textarea of the form:
line1
line2
After I hit submit, the textarea will show the following:
line1<br />
<br />
line2
Now, if I go straight back to the update form and hit submit after changing nothing the textarea shows the following:
line1<br /><br />
<br /><br />
line2
So the script has added an extra 2 <br /> tags eventhough I changed nothing. So I have 2 questions.
1) How do I stop the <br /> tags showing up in the form?
2) How do I stop inserting these extra <br /> tags into the script upon hitting the submit button?
Many thanks in advance for your help! :o)
i would normally only use nl2br when outputing to HTML, not when saving to a database or similar.
i.e.
- user enters data via textarea
- save data into database/array exactly as it was entered
- if the data is going to be sent back to the textarea then you need do nothing with it as it will be formatted the same as when it was submitted.
- if it's going back to HTML use nl2br on it then.
this helps keep the input clean to much around with it at a later date.
make sense? ;-)
Hughie
That probably made even less sense but I hope it helps...
Cheers
Richard