Echo function displays on separate html page, can I possibly echo to a certain element by ID like JS? Alternative solutions?What characters can be used for up/down triangle (arrow without stem) for display in HTML?How can I set the default value for an HTML <select> element?Can I write a CSS selector selecting elements NOT having a certain class?Testing Contact Form with local WAMP serverunable to echo message sent in html page using phpCannot display HTML stringaria-describedby text not announced on <div> by JAWStrying to get feedback as email from a contact formAjax Error in Contact Formunable to receive form data sent from jquery to php post array

How to publish items after pipeline is finished?

Why we don’t make use of the t-distribution for constructing a confidence interval for a proportion?

C++ logging library

Possible runaway argument using circuitikz

Why can my keyboard only digest 6 keypresses at a time?

What differences exist between adamantine and adamantite in all editions of D&D?

tabular: caption and align problem

Can we completely replace inheritance using strategy pattern and dependency injection?

Do you have to have figures when playing D&D?

What is this Amiga 1200 mod?

Varying the size of dots in a plot according to information contained in list

Is Lambda Calculus purely syntactic?

What is the logic behind charging tax _in the form of money_ for owning property when the property does not produce money?

Grep Match and extract

Should I put programming books I wrote a few years ago on my resume?

Ability To Change Root User Password (Vulnerability?)

How to avoid typing 'git' at the begining of every git command

What would prevent chimeras from reproducing with each other?

If a Variant Human is Reincarnated, would they lose the feat and skill proficiency they started with?

Solving ‘Null geometry…’ error during distance matrix operation?

2019 gold coins to share

Why do radiation hardened IC packages often have long leads?

Did Apple bundle a specific monitor with the Apple II+ for schools?

What do the pair of vertical lines in empirical entropy formula mean?



Echo function displays on separate html page, can I possibly echo to a certain element by ID like JS? Alternative solutions?


What characters can be used for up/down triangle (arrow without stem) for display in HTML?How can I set the default value for an HTML <select> element?Can I write a CSS selector selecting elements NOT having a certain class?Testing Contact Form with local WAMP serverunable to echo message sent in html page using phpCannot display HTML stringaria-describedby text not announced on <div> by JAWStrying to get feedback as email from a contact formAjax Error in Contact Formunable to receive form data sent from jquery to php post array






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-2















INEXPERIANCED WITH PHP! SORRY FOR STUPID QUESTION!



My php email form submit is functioning as intended other than the success message. When I call my php from my form submit button the email sends correctly however the "echo "Thank You!" message at the end of the code displays on a new plaintext page ( only thing displayed is "Thank You!" ) with the slug "www.website.com/mail.php" ( the name of the php file ).



I understand this is possibly because I'm calling a separate file instead of running the php within the html document however I was hoping I wouldn't need to have my php in the same document, i'd rather keep it tidy and easier to work on in the future.



I have a few ideas as a workaround -



  • Instead of using echo I could call a seperate JS script which finds the tag with ID I wish to display the sucess message on.


  • Unsure if this would work but I could assign a global variable to have the sucess message then have php within my html which echos the variable.


  • Putting the PHP in the html ( as said above )


  • Instead using an alert if php is capable of that


However surely there is a better way of doing this? I cannot seem to find anyone who can help, believe me when I say I've googled so many times for a solution. Is my second solution the proper way? How should I be doing this "properly"?



Mail.php:



<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name n Email: $email n Message: $message";
$recipient = "ddddn@gmail.com";
$subject = "Contact Form";
$mailheader = "From: contact@sdasdsdaT.com rn";
mail($recipient, $subject, $formcontent, $mailheader);
echo "Thank You!";
?>


HTML form:



<form action="php/mail.php" method="post">
<div class="form-group">
<label for="name">Your Name</label>
<input type="name" class="form-control" name="name" id="name" aria-describedby="Name input feild" placeholder="Name">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" name="email" id="email" aria-describedby="emailHelp" placeholder="Email Address">
</div>
<div class="form-group">
<label for="Your Message">Your Message</label>
<textarea class="form-control messagebox" placeholder="Any and all enquiries are welcome!" name="message" rows="8" cols="80"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>


Not sure what i'd expect from the php currently there, possibly for the echo message to appear within the tag form tag where the php file is called?



Again, I've really used every resource I have and I'm trying my best here. Thank you so much for your time.










share|improve this question



















  • 2





    That's because that is all you output. If you want HTML then you'll need to add it. If you want it to appear on the same page you will need to learn about ajax.

    – John Conde
    Mar 24 at 20:44











  • Thanks for the AJAX thing. I'm looking now.

    – Lewis sun
    Mar 24 at 20:54

















-2















INEXPERIANCED WITH PHP! SORRY FOR STUPID QUESTION!



My php email form submit is functioning as intended other than the success message. When I call my php from my form submit button the email sends correctly however the "echo "Thank You!" message at the end of the code displays on a new plaintext page ( only thing displayed is "Thank You!" ) with the slug "www.website.com/mail.php" ( the name of the php file ).



I understand this is possibly because I'm calling a separate file instead of running the php within the html document however I was hoping I wouldn't need to have my php in the same document, i'd rather keep it tidy and easier to work on in the future.



I have a few ideas as a workaround -



  • Instead of using echo I could call a seperate JS script which finds the tag with ID I wish to display the sucess message on.


  • Unsure if this would work but I could assign a global variable to have the sucess message then have php within my html which echos the variable.


  • Putting the PHP in the html ( as said above )


  • Instead using an alert if php is capable of that


However surely there is a better way of doing this? I cannot seem to find anyone who can help, believe me when I say I've googled so many times for a solution. Is my second solution the proper way? How should I be doing this "properly"?



Mail.php:



<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name n Email: $email n Message: $message";
$recipient = "ddddn@gmail.com";
$subject = "Contact Form";
$mailheader = "From: contact@sdasdsdaT.com rn";
mail($recipient, $subject, $formcontent, $mailheader);
echo "Thank You!";
?>


HTML form:



<form action="php/mail.php" method="post">
<div class="form-group">
<label for="name">Your Name</label>
<input type="name" class="form-control" name="name" id="name" aria-describedby="Name input feild" placeholder="Name">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" name="email" id="email" aria-describedby="emailHelp" placeholder="Email Address">
</div>
<div class="form-group">
<label for="Your Message">Your Message</label>
<textarea class="form-control messagebox" placeholder="Any and all enquiries are welcome!" name="message" rows="8" cols="80"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>


Not sure what i'd expect from the php currently there, possibly for the echo message to appear within the tag form tag where the php file is called?



Again, I've really used every resource I have and I'm trying my best here. Thank you so much for your time.










share|improve this question



















  • 2





    That's because that is all you output. If you want HTML then you'll need to add it. If you want it to appear on the same page you will need to learn about ajax.

    – John Conde
    Mar 24 at 20:44











  • Thanks for the AJAX thing. I'm looking now.

    – Lewis sun
    Mar 24 at 20:54













-2












-2








-2








INEXPERIANCED WITH PHP! SORRY FOR STUPID QUESTION!



My php email form submit is functioning as intended other than the success message. When I call my php from my form submit button the email sends correctly however the "echo "Thank You!" message at the end of the code displays on a new plaintext page ( only thing displayed is "Thank You!" ) with the slug "www.website.com/mail.php" ( the name of the php file ).



I understand this is possibly because I'm calling a separate file instead of running the php within the html document however I was hoping I wouldn't need to have my php in the same document, i'd rather keep it tidy and easier to work on in the future.



I have a few ideas as a workaround -



  • Instead of using echo I could call a seperate JS script which finds the tag with ID I wish to display the sucess message on.


  • Unsure if this would work but I could assign a global variable to have the sucess message then have php within my html which echos the variable.


  • Putting the PHP in the html ( as said above )


  • Instead using an alert if php is capable of that


However surely there is a better way of doing this? I cannot seem to find anyone who can help, believe me when I say I've googled so many times for a solution. Is my second solution the proper way? How should I be doing this "properly"?



Mail.php:



<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name n Email: $email n Message: $message";
$recipient = "ddddn@gmail.com";
$subject = "Contact Form";
$mailheader = "From: contact@sdasdsdaT.com rn";
mail($recipient, $subject, $formcontent, $mailheader);
echo "Thank You!";
?>


HTML form:



<form action="php/mail.php" method="post">
<div class="form-group">
<label for="name">Your Name</label>
<input type="name" class="form-control" name="name" id="name" aria-describedby="Name input feild" placeholder="Name">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" name="email" id="email" aria-describedby="emailHelp" placeholder="Email Address">
</div>
<div class="form-group">
<label for="Your Message">Your Message</label>
<textarea class="form-control messagebox" placeholder="Any and all enquiries are welcome!" name="message" rows="8" cols="80"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>


Not sure what i'd expect from the php currently there, possibly for the echo message to appear within the tag form tag where the php file is called?



Again, I've really used every resource I have and I'm trying my best here. Thank you so much for your time.










share|improve this question
















INEXPERIANCED WITH PHP! SORRY FOR STUPID QUESTION!



My php email form submit is functioning as intended other than the success message. When I call my php from my form submit button the email sends correctly however the "echo "Thank You!" message at the end of the code displays on a new plaintext page ( only thing displayed is "Thank You!" ) with the slug "www.website.com/mail.php" ( the name of the php file ).



I understand this is possibly because I'm calling a separate file instead of running the php within the html document however I was hoping I wouldn't need to have my php in the same document, i'd rather keep it tidy and easier to work on in the future.



I have a few ideas as a workaround -



  • Instead of using echo I could call a seperate JS script which finds the tag with ID I wish to display the sucess message on.


  • Unsure if this would work but I could assign a global variable to have the sucess message then have php within my html which echos the variable.


  • Putting the PHP in the html ( as said above )


  • Instead using an alert if php is capable of that


However surely there is a better way of doing this? I cannot seem to find anyone who can help, believe me when I say I've googled so many times for a solution. Is my second solution the proper way? How should I be doing this "properly"?



Mail.php:



<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name n Email: $email n Message: $message";
$recipient = "ddddn@gmail.com";
$subject = "Contact Form";
$mailheader = "From: contact@sdasdsdaT.com rn";
mail($recipient, $subject, $formcontent, $mailheader);
echo "Thank You!";
?>


HTML form:



<form action="php/mail.php" method="post">
<div class="form-group">
<label for="name">Your Name</label>
<input type="name" class="form-control" name="name" id="name" aria-describedby="Name input feild" placeholder="Name">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" name="email" id="email" aria-describedby="emailHelp" placeholder="Email Address">
</div>
<div class="form-group">
<label for="Your Message">Your Message</label>
<textarea class="form-control messagebox" placeholder="Any and all enquiries are welcome!" name="message" rows="8" cols="80"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>


Not sure what i'd expect from the php currently there, possibly for the echo message to appear within the tag form tag where the php file is called?



Again, I've really used every resource I have and I'm trying my best here. Thank you so much for your time.







php html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 21:46







Lewis sun

















asked Mar 24 at 20:40









Lewis sunLewis sun

163




163







  • 2





    That's because that is all you output. If you want HTML then you'll need to add it. If you want it to appear on the same page you will need to learn about ajax.

    – John Conde
    Mar 24 at 20:44











  • Thanks for the AJAX thing. I'm looking now.

    – Lewis sun
    Mar 24 at 20:54












  • 2





    That's because that is all you output. If you want HTML then you'll need to add it. If you want it to appear on the same page you will need to learn about ajax.

    – John Conde
    Mar 24 at 20:44











  • Thanks for the AJAX thing. I'm looking now.

    – Lewis sun
    Mar 24 at 20:54







2




2





That's because that is all you output. If you want HTML then you'll need to add it. If you want it to appear on the same page you will need to learn about ajax.

– John Conde
Mar 24 at 20:44





That's because that is all you output. If you want HTML then you'll need to add it. If you want it to appear on the same page you will need to learn about ajax.

– John Conde
Mar 24 at 20:44













Thanks for the AJAX thing. I'm looking now.

– Lewis sun
Mar 24 at 20:54





Thanks for the AJAX thing. I'm looking now.

– Lewis sun
Mar 24 at 20:54












1 Answer
1






active

oldest

votes


















1














I am gonna explain a bit and help out a little bit so as to leave space for your learning.
So, currently what you are doing is you are calling another page when you submit your form.
When the new page loads you're are displaying "thank you" using PHP.



What I understood from the question is you want to stay on the same page while sending the email and then display the text. For this we have to use AJAX in order to stay and do that job. Now, AJAX would be much easier with JQ, however I am guessing you are only new to this so I am gonna put the code in JS.



HTML



<button onclick="call()" type="submit" class="btn btn-primary">Submit</button>


JS



<script>
function call()
console.log("called");
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
if (this.readyState == 4 && this.status == 200)
console.log(this.responseText);
var txt = this.responseText;
if(txt == "true")
alert("Thank You");

else
alert("false");


else
console.log(this.status);

;
xhttp.open("POST", "php/mail.php", true);
xhttp.send();

</script>


PHP



<?php
echo "true";
?>


In this you will be able to display alert on the same page. You can beautify it by using Sweet Alert library if you want. I am guessing you can figure out the integration of your code in this. Good Luck!






share|improve this answer























  • Thanks so much for the detailed response!! I have JQuery but haven't gotten into it yet. I'll try this out once I understand it, thankyou!

    – Lewis sun
    Mar 24 at 21:46











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328363%2fecho-function-displays-on-separate-html-page-can-i-possibly-echo-to-a-certain-e%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I am gonna explain a bit and help out a little bit so as to leave space for your learning.
So, currently what you are doing is you are calling another page when you submit your form.
When the new page loads you're are displaying "thank you" using PHP.



What I understood from the question is you want to stay on the same page while sending the email and then display the text. For this we have to use AJAX in order to stay and do that job. Now, AJAX would be much easier with JQ, however I am guessing you are only new to this so I am gonna put the code in JS.



HTML



<button onclick="call()" type="submit" class="btn btn-primary">Submit</button>


JS



<script>
function call()
console.log("called");
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
if (this.readyState == 4 && this.status == 200)
console.log(this.responseText);
var txt = this.responseText;
if(txt == "true")
alert("Thank You");

else
alert("false");


else
console.log(this.status);

;
xhttp.open("POST", "php/mail.php", true);
xhttp.send();

</script>


PHP



<?php
echo "true";
?>


In this you will be able to display alert on the same page. You can beautify it by using Sweet Alert library if you want. I am guessing you can figure out the integration of your code in this. Good Luck!






share|improve this answer























  • Thanks so much for the detailed response!! I have JQuery but haven't gotten into it yet. I'll try this out once I understand it, thankyou!

    – Lewis sun
    Mar 24 at 21:46















1














I am gonna explain a bit and help out a little bit so as to leave space for your learning.
So, currently what you are doing is you are calling another page when you submit your form.
When the new page loads you're are displaying "thank you" using PHP.



What I understood from the question is you want to stay on the same page while sending the email and then display the text. For this we have to use AJAX in order to stay and do that job. Now, AJAX would be much easier with JQ, however I am guessing you are only new to this so I am gonna put the code in JS.



HTML



<button onclick="call()" type="submit" class="btn btn-primary">Submit</button>


JS



<script>
function call()
console.log("called");
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
if (this.readyState == 4 && this.status == 200)
console.log(this.responseText);
var txt = this.responseText;
if(txt == "true")
alert("Thank You");

else
alert("false");


else
console.log(this.status);

;
xhttp.open("POST", "php/mail.php", true);
xhttp.send();

</script>


PHP



<?php
echo "true";
?>


In this you will be able to display alert on the same page. You can beautify it by using Sweet Alert library if you want. I am guessing you can figure out the integration of your code in this. Good Luck!






share|improve this answer























  • Thanks so much for the detailed response!! I have JQuery but haven't gotten into it yet. I'll try this out once I understand it, thankyou!

    – Lewis sun
    Mar 24 at 21:46













1












1








1







I am gonna explain a bit and help out a little bit so as to leave space for your learning.
So, currently what you are doing is you are calling another page when you submit your form.
When the new page loads you're are displaying "thank you" using PHP.



What I understood from the question is you want to stay on the same page while sending the email and then display the text. For this we have to use AJAX in order to stay and do that job. Now, AJAX would be much easier with JQ, however I am guessing you are only new to this so I am gonna put the code in JS.



HTML



<button onclick="call()" type="submit" class="btn btn-primary">Submit</button>


JS



<script>
function call()
console.log("called");
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
if (this.readyState == 4 && this.status == 200)
console.log(this.responseText);
var txt = this.responseText;
if(txt == "true")
alert("Thank You");

else
alert("false");


else
console.log(this.status);

;
xhttp.open("POST", "php/mail.php", true);
xhttp.send();

</script>


PHP



<?php
echo "true";
?>


In this you will be able to display alert on the same page. You can beautify it by using Sweet Alert library if you want. I am guessing you can figure out the integration of your code in this. Good Luck!






share|improve this answer













I am gonna explain a bit and help out a little bit so as to leave space for your learning.
So, currently what you are doing is you are calling another page when you submit your form.
When the new page loads you're are displaying "thank you" using PHP.



What I understood from the question is you want to stay on the same page while sending the email and then display the text. For this we have to use AJAX in order to stay and do that job. Now, AJAX would be much easier with JQ, however I am guessing you are only new to this so I am gonna put the code in JS.



HTML



<button onclick="call()" type="submit" class="btn btn-primary">Submit</button>


JS



<script>
function call()
console.log("called");
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
if (this.readyState == 4 && this.status == 200)
console.log(this.responseText);
var txt = this.responseText;
if(txt == "true")
alert("Thank You");

else
alert("false");


else
console.log(this.status);

;
xhttp.open("POST", "php/mail.php", true);
xhttp.send();

</script>


PHP



<?php
echo "true";
?>


In this you will be able to display alert on the same page. You can beautify it by using Sweet Alert library if you want. I am guessing you can figure out the integration of your code in this. Good Luck!







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 24 at 21:28









sc0rp1onsc0rp1on

967




967












  • Thanks so much for the detailed response!! I have JQuery but haven't gotten into it yet. I'll try this out once I understand it, thankyou!

    – Lewis sun
    Mar 24 at 21:46

















  • Thanks so much for the detailed response!! I have JQuery but haven't gotten into it yet. I'll try this out once I understand it, thankyou!

    – Lewis sun
    Mar 24 at 21:46
















Thanks so much for the detailed response!! I have JQuery but haven't gotten into it yet. I'll try this out once I understand it, thankyou!

– Lewis sun
Mar 24 at 21:46





Thanks so much for the detailed response!! I have JQuery but haven't gotten into it yet. I'll try this out once I understand it, thankyou!

– Lewis sun
Mar 24 at 21:46



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328363%2fecho-function-displays-on-separate-html-page-can-i-possibly-echo-to-a-certain-e%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript