confused and dazed Posted December 22, 2011 Share Posted December 22, 2011 Hello internet. I have been sending my site out to people to test out and mess around with and some feedback I am getting is that they are having pop-up blocker issues and even when they temporarily turn the pop-up blockers off they still do not get my echo's that I really need them to get. So - how do I send the echo right to the same webpage that the form is on? Link to comment Share on other sites More sharing options...
birbal Posted December 22, 2011 Share Posted December 22, 2011 pop up blocker will block some js action which cause pop ups. but there is nothing to do it with php. once a page has been served its out of scope of php. echo should show the data as it should be,at the time of page serving. can you tell more about what are you trying to do actualy? or codes? Link to comment Share on other sites More sharing options...
confused and dazed Posted December 22, 2011 Author Share Posted December 22, 2011 All I really want to happen is have the current page refresh with the processed form data OR have the processed form data actually show up on the same page as the from. Is there a way to do this? Link to comment Share on other sites More sharing options...
thescientist Posted December 22, 2011 Share Posted December 22, 2011 have the form submit to itself. i.e. the action and the page with the form will be the same. Just make sure to check for submit in GET/POST so you don't get errors trying to echo out values when the haven't been set yet. Link to comment Share on other sites More sharing options...
Don E Posted December 22, 2011 Share Posted December 22, 2011 Here's a way so you can get an idea: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Same page submit</title></head><body><?php if(isset($_POST['submit']) && !empty($_POST['fname']) && !empty($_POST['lname'])) // after submitting and all fields are filled, this gets ran and the form below disappears{ $firstName = $_POST['fname']; $lastName = $_POST['lname']; echo "<p>Hello $firstName $lastName, how are you today?</p>"; }else // when the page loads, this else clause gets ran first{ echo '<p style="color:red;">Please fill in all fields</p>';?><form action="samepageform.php" method="post"><label for="fname">First Name:</label><input type="text" name="fname" id="fname" /><label for="lname">Last Name:</label><input type="text" name="lname" id="lname" /><input type="submit" name="submit" /></form><?php}?></body></html> Link to comment Share on other sites More sharing options...
justsomeguy Posted December 22, 2011 Share Posted December 22, 2011 There are more examples of forms here: http://w3schools.invisionzone.com/index.php?showtopic=12509 Link to comment Share on other sites More sharing options...
confused and dazed Posted December 23, 2011 Author Share Posted December 23, 2011 Don E: the curly brackets look strange in your code. Also the php file samepageform... where is the code for that? I dont quite get how to use the code you offered. Please help. Justsomeguy: I will look through the information you sent and look for the parts that would apply to my question. Thanks. Link to comment Share on other sites More sharing options...
Don E Posted December 23, 2011 Share Posted December 23, 2011 The page above is called samepageform.php. When clicking on submit, it goes to the same page. If you look at the comments, you can get an idea of whats going on. When the page first loads, since the 'if' is false, it will execute what's in the 'else' clause, which is the form itself. Once the user enters all the info and clicks on submit, since the page is submitting to itself, it goes through the whole if-else again, and this time the 'if' is executed(since it's true). not the 'else' clause thus not showing the form. You may be confused with how the else clause looks like. You can do that; you can mix HTML and PHP together like that. Here's basically what you're familiar with seeing. This example will always show the form no matter what: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Same page submit</title></head><body><?php if(isset($_POST['submit']) && !empty($_POST['fname']) && !empty($_POST['lname'])){ $firstName = $_POST['fname']; $lastName = $_POST['lname']; echo "<p>Hello $firstName $lastName, how are you today?</p>"; }else{ echo '<p style="color:red;">Please fill in all fields</p>';}?><form action="samepageform.php" method="post"><label for="fname">First Name:</label><input type="text" name="fname" id="fname" /><label for="lname">Last Name:</label><input type="text" name="lname" id="lname" /><input type="submit" name="submit" /></form></body></html> Link to comment Share on other sites More sharing options...
confused and dazed Posted December 23, 2011 Author Share Posted December 23, 2011 I used the code you typed in verbatim and when the page loads (after submit button is pressed) there is an error message that states website cannot be found. Do I need to name my .html a certain name?Not sure how to fix that. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 23, 2011 Share Posted December 23, 2011 You need to name it samepageform.php, or change the action in the form to whatever you named the file. This is a PHP file, by the way, not a .html file. Link to comment Share on other sites More sharing options...
thescientist Posted December 23, 2011 Share Posted December 23, 2011 Also the php file samepageform... where is the code for that? I dont quite get how to use the code you offered. Please help.samepageform.php IS your page and your action., hence why we keep telling you the form submits to itself. And it should be a PHP page, in case you weren't aware, but I am thinking you are trying to submit a form to another page. You need to realize both are the same in this situation. have the form submit to itself. i.e. the action and the page with the form will be the same. Just make sure to check for submit in GET/POST so you don't get errors trying to echo out values when the haven't been set yet.what i said is pretty much exampled by Don E'.s post. Like he said, the commenting should give you a good idea of how the logic is working. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.