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
You have to escape the quotes in the string by adding a backslash before "
or using single quotes inside double quotes
or even using Heredoc
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: