Jump to content

echo form results on form page?


paulmo

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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] 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.