1

I have an HTML form. When you click on the submit button it stores the data from the boxes into a table and then displays a message. the message is sent from a PHP file then it is displayed by js in an HTML file. The problem is that the message has br tags in it and when the message is displayed it shows the <br> tag instead of breaking the line.

This is where i am testing it - http://ft5.cu.cc/ Click on the heart logo to see the form.

HTML FORM

<div class="contact">
            <form method="post" action="daalo.php">
                <input type="text" maxlength="30" class="text" name="ign" id="ign" placeholder="Please type your IGN(In Game Name)" required="required"/>
                <input type="email" maxlength="30" class="required email" name="email" id="email" placeholder="Please type your email" required="required"/><span class="status"></span>
                <table width="100%">
                <tr>
                <td><input type="text" maxlength="30" class="text" id="steamid" name="steamid" placeholder="Enter your Steam ID" required="required"/></td>
                <td><span class="status">
                <img id="tick" alt="Good"src="images/tick.png" width="16" height="16"/></td>
                </tr>
                </table>
                <span id="cross">Steam Id Already Added</span>
                </span>
                <input type="submit" name="register" id="register" value="Submit" disabled="disabled" />
            </form>
            <div id="loading">Processing your <b>WHITELIST</b> entry....</div>
        <div id="success"></div>
    </div>

*Php Insert*

<?php
include('connecti.php'); //Ganja Login


 // Check connection
 if (mysqli_connect_errno())
   {
   echo 'Failed to connect to MySQL: ' . mysqli_connect_error();
   }

//Insert
$lab1='IGN<br>'; 
$lab2='Email ID<br>'; 
$lab3='Steam ID<br>';
$lab4='Submitted.';
$lab5='Whitelist is updated everyday at 8pm (UTC+01:00) Brussels, Copenhagen, Madrid, Paris.';

$sql="INSERT INTO rusty_whitelist (name, email, steamid) VALUES ('$_POST[ign]','$_POST[email]','$_POST[steamid]')";

 if (!mysqli_query($con,$sql))
   {
   die('Error: ' . mysqli_error($con));
   }
    echo $lab1;
    echo $lab2;
    echo $lab3;
    echo $lab4;
    echo $lab5;

 mysqli_close($con);
 ?>

Java Script

(function($) {
$('form').submit(function(e){
    var thisForm = $(this);
    e.preventDefault();
    $(this).fadeOut(function(){
        $("#loading").fadeIn(function(){
            $.ajax({
                type: 'POST',
                url: thisForm.attr("action"),
                data: thisForm.serialize(),
                success: function(data){
                    $("#loading").fadeOut(function(){
                        $("#success").text(data).fadeIn();
                     });
                }
            });
        });
    });
});
$('.md-trigger').tipsy({gravity: 's'});
})(jQuery);

$(function(){
  $().ready(function() {
    $('#videobg').tubular({videoId: 'tDvBwPzJ7dY'}); // where idOfYourVideo is the YouTube ID.
  });
});
PointedEars
  • 14,752
  • 4
  • 34
  • 33
  • 2
    I cleaned up your question to format things properly. Please read about [how to format your posts](http://stackoverflow.com/help/formatting). Anyway, I don't think you have given us nearly enough information about how you are displaying this. We can't answer it because you haven't shown us any code. – elixenide Mar 05 '14 at 22:10
  • yeah i am tryin to put that in now its not letting me. i tried this way also '$lab1='IGN
    ';' '$lab2='Email ID
    ';' and then after the insert 'echo $lab1;' 'echo $lab2;'
    – user3079935 Mar 05 '14 at 22:12
  • i posted it in the comments but it looks like it didn't come up properly and its not letting me edit it any more – user3079935 Mar 05 '14 at 22:13
  • That's not the code I'm talking about. I'm talking about the PHP that does the output and the JS that processes it. – elixenide Mar 05 '14 at 22:13
  • Educated guess: You are either escaping `<` or you are setting the `nodeValue` or `textContent` property instead of the (proprietary) `innerHTML` property. – PointedEars Mar 05 '14 at 22:16
  • I'm not going to visit a Website. Your posted code checks out. You could try using double quotes `$lab1="IGN
    ";` but I doubt this will make any difference. Show your code or will vote to close otherwise.
    – Funk Forty Niner Mar 05 '14 at 22:17
  • ok it was very easy to put the code sry i am stupid. anyway there it is – user3079935 Mar 05 '14 at 22:17
  • tried double quotes didnt work – user3079935 Mar 05 '14 at 22:19
  • If that is your actual code, you're missing a `<` for your `div class="contact">` but... I doubt it and think you may have made a typo. – Funk Forty Niner Mar 05 '14 at 22:20
  • 2
    Sidenote: You're also [`Open to SQL injection`](http://stackoverflow.com/q/60174/) for your DB; use prepared statements. – Funk Forty Niner Mar 05 '14 at 22:22
  • lol yes i made a mistake while copying it for here. the website is running. although ur browser might say its a phishing site cuz of the domain. ft5.cu.cc – user3079935 Mar 05 '14 at 22:22
  • http://validator.w3.org/check?uri=http%3A%2F%2Fft5.cu.cc%2F&charset=%28detect+automatically%29&doctype=HTML5&group=0&user-agent=W3C_Validator%2F1.3+http%3A%2F%2Fvalidator.w3.org%2Fservices – Quentin Mar 05 '14 at 22:25

2 Answers2

1

I think the issue is how you are using the value returned by Ajax into your code. Instead of using the jQuery .text() method, try the .html() method.

tjons
  • 4,749
  • 5
  • 28
  • 36
1

As I suspected in my comment, you are setting the textContent property of an element object (or the DOM Level 2 equivalent of that) by means of jQuery's text() method.

You need to call the html() method instead to set the innerHTML property (or the equivalent of that).

PointedEars
  • 14,752
  • 4
  • 34
  • 33