paulmo Posted January 6, 2009 Share Posted January 6, 2009 have form page and php page. need to echo form results on form page only (not re-direct to php page). how to do this? thanks Quote Link to comment https://forums.phpfreaks.com/topic/139634-echo-form-results-on-form-page/ Share on other sites More sharing options...
Maq Posted January 6, 2009 Share Posted January 6, 2009 Can we see some code? You would have to submit the page to itself and call the values when it's submitted but again, we need some code. Quote Link to comment https://forums.phpfreaks.com/topic/139634-echo-form-results-on-form-page/#findComment-730569 Share on other sites More sharing options...
paulmo Posted January 6, 2009 Author Share Posted January 6, 2009 ok, here's the form: <form name="myform" action="process.php" method="POST"> <input type="hidden" name="check_submit" value="1"/> </p><p>First Name: <input type="text" name="name" class="buttonsb"/></p><p> You're feeling: <input type="radio" name="theme" value="grey" /> grey <input type="radio" name="theme" value="dark" /> dark <input type="radio" name="theme" value="light" /> light </p> <input type="submit" value="Process" class="buttons" onclick="return CapitalizeNames()"> </form> and here's a php page echo statement (this is what needs to go on form page): switch($_POST['theme']) { case 'grey': echo "A gloomy {$phrase1} {$time} is here, {$_POST['name']}, {$phrase2} the php page includes all the cases, $phrases, $time, switch, date, db connect, and geo location js. but again, just need to echo example above in form page. thank you! Quote Link to comment https://forums.phpfreaks.com/topic/139634-echo-form-results-on-form-page/#findComment-730827 Share on other sites More sharing options...
l_kris06 Posted January 6, 2009 Share Posted January 6, 2009 Heres an example that will help you acheive this. Filename: Test.php <html><body> <form name="myform" action="" method="POST"> <input type="hidden" name="check_submit" value="1"/> First Name: <input type="text" name="name" class="buttonsb"/></p><p> You're feeling: <input type="radio" name="theme" value="grey" /> grey <input type="radio" name="theme" value="dark" /> dark <input type="radio" name="theme" value="light" /> light </p> <input type="submit" value="Process" class="buttons" onclick="return CapitalizeNames()"> </form> <?php if(isset($_POST['check_submit'])){ echo $_POST['check_submit']."<BR>"; } if(isset($_POST['name'])){ echo $_POST['name']."<BR>"; } if(isset($_POST['theme'])){ echo $_POST['theme']."<BR>"; } ?> </body></html> Rgds, Kris Quote Link to comment https://forums.phpfreaks.com/topic/139634-echo-form-results-on-form-page/#findComment-730838 Share on other sites More sharing options...
paulmo Posted January 6, 2009 Author Share Posted January 6, 2009 that seems easy...just leave action "" and put the whole php page on form page? is that less secure? thanks Quote Link to comment https://forums.phpfreaks.com/topic/139634-echo-form-results-on-form-page/#findComment-730852 Share on other sites More sharing options...
premiso Posted January 6, 2009 Share Posted January 6, 2009 that seems easy...just leave action "" and put the whole php page on form page? is that less secure? thanks Nope it is not. It depends on preference really. I always define my form to goto which page I want it to, even if it is itself. But that is my preference. Quote Link to comment https://forums.phpfreaks.com/topic/139634-echo-form-results-on-form-page/#findComment-730856 Share on other sites More sharing options...
paulmo Posted January 6, 2009 Author Share Posted January 6, 2009 getting ie cannot open web page operation aborted. i'm requiring the db connection below, and guessing that's tripping things up: <?php ini_set("display_errors", 1); error_reporting(E_ALL); mysql_connect("xxx", "xxx", "xxx") or die(mysql_error()); ?> in col 2 of form page: <div id="col2"> <?php require_once('xxx.php'); mysql_select_db("xxx") or die(mysql_error()); $name = mysql_real_escape_string($_POST['name']); $message = mysql_real_escape_string($_POST['message']); mysql_query("INSERT INTO xxx (name, message, created) [i]echo statements etc. [/i] Quote Link to comment https://forums.phpfreaks.com/topic/139634-echo-form-results-on-form-page/#findComment-730872 Share on other sites More sharing options...
paulmo Posted January 6, 2009 Author Share Posted January 6, 2009 just included entire php page (with db connection) on form page and getting undefined index error message on $name and $message variables. all worked fine when php page was separate. seem to isolate to empty action "" tag? Quote Link to comment https://forums.phpfreaks.com/topic/139634-echo-form-results-on-form-page/#findComment-730927 Share on other sites More sharing options...
l_kris06 Posted January 6, 2009 Share Posted January 6, 2009 Operation abored with IE7 is a bug in the MS IE parser. http://support.microsoft.com/kb/927917 By having form action return to the same page has no relation with security, anybody reading you http packets will see it regardless of your <form action> being blank. So bottomline, security should be the last thing u should worry about. Kindly post your code on which you are having problems, one of us here might be able to help. Maybe its just me, but whtever code u posted didnt really help me in understanding your problem. Rgds, Krishna Quote Link to comment https://forums.phpfreaks.com/topic/139634-echo-form-results-on-form-page/#findComment-731001 Share on other sites More sharing options...
paulmo Posted January 7, 2009 Author Share Posted January 7, 2009 krishna, thanks for volunteering to check out my code in more depth to see why it's not working. (there are some hidden notes // for stuff that's not working yet, cookies, user time, for reference): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html lang="en"> <head> <meta content="Interactive moments." name="description"> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title> Release Center Interactive</title> <link rel="stylesheet" type="text/css" href="columns.css"> <head> <script type="text/javascript"> function main(){ var hours = (new Date()).getHours(); var offset = document.getElementById('offset'); offset.value = hours - offset.value; } var FormName = "myform"; var FieldName = "name"; function CapitalizeNames() { var ValueString = new String(); eval('ValueString=document.'+FormName+'.'+FieldName+'.value'); ValueString = ValueString.replace(/ +/g,' '); var names = ValueString.split(' '); for(var i = 0; i < names.length; i++) { if(names[i].length > 1) { names[i] = names[i].toLowerCase(); letters = names[i].split(''); letters[0] = letters[0].toUpperCase(); names[i] = letters.join(''); } else { names[i] = names[i].toUpperCase(); } } ValueString = names.join(' '); eval('document.'+FormName+'.'+FieldName+'.value=ValueString'); return true; } </script> </head> <body onload="main();"> <div id="header"> <img src="banner.gif"> </div> <?php ini_set("display_errors", 1); error_reporting(E_ALL); ?> /*<script type="text/javascript"> function.GetClientUTC(); { var now = new Date(); var offset = now.getTimezoneOffset(); return offset; } </script> <script type="text/javascript"> var d = new Date(); document.write (d.toLocaleTimeString()); </script> */ <script type="text/javascript"> var myDate = new Date(); var myTime = myDate.toLocaleTimeString(); myDate.setDate(myDate.getDate()+1); setCookie('UserTime',myTime); function setCookie(c_name,value,expiredays) { var exdate=new Date(); exdate.setDate(exdate.getDate()+expiredays); document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString()); } </script> <script type="text/javascript" src="jquery-1.2.6.min.js"></script> <script type="text/javascript" src="jquery.corners.min.js"></script> <script type="text/javascript" src="jquery-impromptu.1.8.js"></script> //$.cookies.get('name'); jquery //$.cookies.set('name'); <div id="col1"> <div style="background-color:#FFFFFF; padding:10px" class="rounded {10px}"> <?php if (isset($_COOKIE["user"])) { $user_name = $_COOKIE["user"]; } else { $user_name = " "; } ?> <form name="myform" action="" method="POST"> <input type="hidden" name="check_submit" value="1"/> </p><p>First Name: <?php echo $user_name; ?> <input type="text" name="name" class="buttonsb"/></p><p> <img class="floatright" src="help.gif" alt="help" width="43" height="39" onmouseover="$.prompt('Take a moment and write a thought.')" /> //<script>onmouseover=$.prompt('text is here').children('#jqi').corner(); </script> <center>Write something.</center> <textarea name="message" rows="7" cols="35" class="buttonsb"></textarea></p><p> <input type="submit" value="Process" class="buttons" onclick="return CapitalizeNames()"> </form> <?php list($hours, $minutes, $seconds) = explode(":",$_COOKIE['UserTime']); echo "The time is $hours:$minutes"; //$time = ($hours < 12)?'morning'($hours < 17)?'afternoon':'evening'); $time = intval(date('G')) < 12 ? 'morning' : intval(date('G')) < 17 ? 'afternoon' : 'evening'; echo " on this ".date('l') ; echo " {$time}."; ?> <!--jquery $.cookies.get() $.cookies.set() $.cookies.del() $.cookies.test() $.cookies.setOptions() $('#username').cookify(); Set the value of an input to a cookie named after the input's name or id attribute The value of the input with id "username" is set to a cookie named after the name or id attribute of that input element $('#username').cookieFill(); Fill an input or textarea's value, or an element's innerHTML with the value of a cookie Set the value of the input with id, 'username', to the value of a cookie by the same name $('#username').cookieBind(); Bind an input to the cookies library/Fills the input with id, 'username' with the cookie named the same, and sets the input's change event to fire cookify() to update the cookie when the input value changes --> </div> </div> <script>$(document).ready( function(){ $('.rounded').corners("4px"); });</script> <script type="text/javascript" src="jquery-1.2.6.min.js"></script> <script type="text/javascript" src="jquery.corners.min.js"></script> <div id="col2"> <div style="background-color:#FFFFFF; padding:10px" class="rounded {10px}"> <?php mysql_connect("xxx", "xxx", "xxx") or die(mysql_error()); mysql_select_db("xxx") or die(mysql_error()); $name = mysql_real_escape_string($_POST['name']); $message = mysql_real_escape_string($_POST['message']); ?> mysql_query("INSERT INTO xxx (name, message, created) VALUES ('$name', '$message', NOW()) ") or die(mysql_error()); $row_id = mysql_insert_id(); //Put it in a variable for later //$query=mysql_query("SELECT name, message FROM xxx"); //WHERE message LIKE '%rising%'") $query = "SELECT name, message FROM xxx"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { echo "Name :{$row['name']} <br>" . "Message : {$row['message']} <br>"; } ?> <script type="text/javascript" src="jquery-1.2.6.min.js"></script> <script type="text/javascript"> $(function(){ //This syntax will execute when the page is done loading $.post("geobeta.php", {geoip_city: geoip_city(), geoip_region_name: geoip_region_name(), row_id: '<?php echo $row_id; ?>' //Pass it with the JavaScript // },function(message){ alert(message); }); }); </script> <p> <strong>Enjoy the day in <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script> <script language="JavaScript">document.write(geoip_city());</script>, <script language="JavaScript">document.write(geoip_region_name());</script>!</strong></p> <?php //setcookie("user", $_POST['name'], time()+3600); ?> <br/><br/> <ul> <li><a href="index.php">interactive</a></li> </ul> $(function(){ //This syntax will execute when the page is done loading $.post("geobeta.php", {geoip_city: geoip_city(), geoip_region_name: geoip_region_name(), row_id: '<?php echo $row_id; ?>' //Pass it with the JavaScript // },function(message){ alert(message); }); }); </script> <p> <strong>Enjoy the day in <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script> <script language="JavaScript">document.write(geoip_city());</script>, <script language="JavaScript">document.write(geoip_region_name());</script>!</strong></p> /*<?php setcookie("user", $_POST['name'], time()+3600); ?> </div> </div> <div id="footer"><img src="footer.gif"></div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/139634-echo-form-results-on-form-page/#findComment-731317 Share on other sites More sharing options...
Sesquipedalian Posted January 7, 2009 Share Posted January 7, 2009 You could also get fancy and use AJAX if for some reason you don't want to have the page reload when you submit your data. Quote Link to comment https://forums.phpfreaks.com/topic/139634-echo-form-results-on-form-page/#findComment-731340 Share on other sites More sharing options...
paulmo Posted January 7, 2009 Author Share Posted January 7, 2009 i'm sorry i wouldn't know the first thing about ajax or the page reloading. just trying to get the page to work, which it's not now. thanks Quote Link to comment https://forums.phpfreaks.com/topic/139634-echo-form-results-on-form-page/#findComment-731344 Share on other sites More sharing options...
paulmo Posted January 7, 2009 Author Share Posted January 7, 2009 bump—any suggestions why this isn't working? Quote Link to comment https://forums.phpfreaks.com/topic/139634-echo-form-results-on-form-page/#findComment-731736 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.