django-displaying data the way they are entered by the user - html

I have a models.py file where i have a textfield
models.py
class xyz(models.Models):
abc=models.TextField()
I am using html form to save the data for the abc field.
The problem is that if i enter the data in multiple lines in the form and try to display it, the whole matter is displayed in a single line.
So what is the error?
Is it in the models or what?
Thanks in advance.

The user enters a plain text, and than you are trying to show it as HTML. these are different formats.
There are a lot of possibilities, the simplest one is to let the user enter HTML and than everything will work as expected.
To do this, use some HTML editor like tinymce
Other solution is to use some markup formatting

Related

Edit form AuthAll Django

I'm new using Django and i'm using AuthAll to login/logout, the problem comes when i try to edit the template of the original form. I've created a the templates but i want to change the form with the inputs, originally there are no inputs just "{{form}}" line 38 . Is there a way to access to that inputs and change the style? Thanks!!
I actually dont want to create views, i really want to use AuthAll and just change the style of the 2 inputs. I tried searching where its created the form but i think its automatic.

Inserting or copy/pasting picture to a textbox

I have a file with a textarea (named "Resolution support") in which you can explain how to solve a problem. My problem is that a user would be able to add a picture for a better explaining. If he copy/paste or he has to click and drag or anything i don't care, he HAS TO be able to put a picture into the textarea.
I wondered if another textbox that can do this would exist and what Type does the textbox has to be in PhpMyAdmin.
My textarea :
<textarea name="Escalade" class="longInput" cols="80%" rows="19" wrap="hard">
</textarea>
Without some kind of JavaScript WYSIWYG library this is not possible as vanilla textarea only takes text (clue is in the name).
I assume that you are viewing the submissions in phpMyAdmin which is an interface onto a MySQL database. It is good for developing stuff but not so great as an admin user interface long term. What you are asking about are called transformations.
Here are some tutorials on storing images in a database:
http://www.hockinson.com/programmer-web-designer-denver-co-usa.php?s=47
http://w3schools.invisionzone.com/index.php?showtopic=48068
How to store file name in database, with other info while uploading image to server using PHP?
Here are some lists of WYSIWYG editors:
http://www.sitepoint.com/html5-wysiwyg/
https://github.com/cheeaun/mooeditable/wiki/Javascript-WYSIWYG-editors
Those phpMyAdmin transformations:
http://docs.phpmyadmin.net/en/latest/transformations.html
That is about as much help as can be offered to you without seeing the PHP code behind the form at the very least. Hope this helps.
If someone is looking for an answer, I had asked my profesor and he answered that what I was looking for is a "Rich Text Editor". I'm using ckeditor with the plugin prgfilemanager. It allows me to insert pictures but I cannot copy/paste them which is pretty annoying...
You can try it here http://ckeditor.com/demo I hope it will help you if you have the same problem that I had :)
While it is true that you cannot use a textarea, the answer is very simple. You can use a content editable div, grab the contents as html and write it to a databae using AJAX and PHP.
Just name a div like this:
<div class="my_article" contenteditable></div>
and pass the contents on the click of a button into a JS variable and then pass that into PHP using AJAX.
var content1 = $('.my_article').html();
If anyone needs further help please comment and I'll be happy to obligue.

Saving text as HTML from form

I have a form with a text field that users input text into. They can use multiple lines, put in bold text, underlined text, etc., but the text, when saved to SQL Server doesn't have any formatting saved, just the text is saved. What is the best way to save the text with the HTML so that when it gets viewed by another user and pulled up from Sql Server the HTML is saved and the formatting is saved?
Ex.
hello
Paul
This would be saved as
helloPaul
you can't see it but there are bold and carriage return html tags rapped around the text
When receiving data from the user, on the server side code, use HTML encode to safely store the data:
var inputData = Server.HtmlEncode("<strong>some data input from user</strong>"); //insert your user input data variable here
Then when displaying the data in your cshtml page, decode the data to display it as the user entered it:
HttpUtility.HtmlDecode(saveUserDataFromDatabaseVariable);
All this is assuming you have a rich text editor being plugged into the input field. CKEditor and TinyMCE are good ones.
You can use a text editor. Take a look at CKEditor. It's free and easy to use :)
Can you post some code and more details?
I have had good success with CKEditor. It is customizable, and its content can easily be saved via postback to a standard asp:TextBox.
It is possible that the editor you are using is not actually updating the input/textarea that you are using, it may be cloning the text and drawing the formatting in an overlay. You can use developer tools, or javascript, to verify this by checking the value property of the input or textarea element. If it is being saved via AJAX or javascript the code may be using the textContent or innerText properties instead of innerHTML.
I used the richtexteditor dll that's free online. it gave me a wiziwig box that the user can edit texxt in.

How to fetch MYSQL data as hyperlink?

On my site, people can link to topics with buttons I made. Those buttons are putting out a (look: http://....) or (look: (link without http://) on the textarea and when they submit it, the hyperlink shows in their post. That is very nice, but if I fetch this data to show them their last posts, I don't get the hyperlink, but just the plain text. So (look: http://....) does not lead to a link...
I have seen in phpmyadmin that it is stored as plain text, so I can understand that, but how can I make those things hyperlinks and the rest of the text (the no-links) just plain?
Try using htmlentities to convert those hyperlinks before saving them in your database. You can then use html_entity_decode when getting the data from the database.
Please take into account the aforementioned comments about security issues. You have to sanitize data the user inputed data before you further process the data.
To answer your question. Store the links in a separate column of your table. Then fletch your links to the user via PHP - I guess you are using MySQL in combination with PHP - like you do with the posts. If you want to create a link you need to use the anchor HTML tag. E.g. Name link.

How to display HTML Page as in gridview c#?

Hi I am developing a html tag based user input, like a rich text box, which saves all the data into a database; including all the html tags.
I then am pulling this data using gridview in asp.net c#.
But when the gridview displays my data, it displays incorrectly.
For example: a user enter his name in bold in the rich textbox as such < b > Superman < /b >, to make it bold. Sadly the gridview displays ecxactly what was entered tags and all without making it bold.
Another example: To enter the name in italics:< i > Superman < /i >, Superman is being display, not in italics.
What I want is for the gridview to display like an HTML PAGE, just like the rich textbox does.
I am using to write question. <-- no idea
Can you help me please?
Thanks
when you bring the html(because that is what you are asking them to enter) back to the view, you are either going to need to transform it yourself or eval the html as is mentioned by #MikeB
alternatively if you are not using Razor try this question for some ideas:
Is there a way to insert Html into a gridview row?
You need to display the raw html. Otherwise it is html encoded to prevent people from being able to run scripts against your site.
You need to be extremely careful displaying user inputted raw html.
If you are using razor it will be something like this:
#Html.Raw(ViewBag.HtmlOutput)