skip to Main Content

I have built an ajax contact form using this tutorial.

How to Create an AJAX Contact Form

My AJAX Contact Form works well – perfectly inline with the tutorial.

But rather than just the plain text

echo "Thank You! Your message has been sent.";

I would like to include a hyperlink in the Thank you message.

echo "<p><a href="#">Thank You! Your message has been sent.</a>";

But the ajax outputs my HTML as plain text.

2

Answers


  1. You have to escape the quotes in the string by adding a backslash before "

    echo "<p><a href="#">Thank You! Your message has been sent.</a></p>";
    

    or using single quotes inside double quotes

    echo "<p><a href='#'>Thank You! Your message has been sent.</a></p>";
    

    or even using Heredoc

    echo <<<EOL
    <p><a href="#">Thank You! Your message has been sent.</a></p>
    EOL;
    
    Login or Signup to reply.
  2. This has already been stated by Steverst, but I’m going to say it anyway. Just use single quotes. The reason that this is happening is because # is the symbol for a comment in PHP, so anything past it on that same line is going to be commented out if it isn’t formatted as text. What you did was you ended the quote right before the # by using a second double quote, and it was interpreted as closing your quote because your double quotes paired up. What you should’ve done is enclosed the whole thing in single quotes instead of double quotes or you could’ve enclosed the # in single quotes. Example:

    echo "<p><a href='#'>Thank You! Your message has been sent.</a>";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search