I have a webpage and a place to submit data. I made a preview page for this, and whenever a user clicks 'preview' he can see what it would look like. The trouble is whenever they click the back button from the preview all the data is gone. How do I avoid this and keep the data without any very complex solutions?
preview.php
<?php
session_start();
$getTitle = $_POST['title'];
$getEntry = $_POST['entry'];
date_default_timezone_set('UTC');
$getTime = date('D, M jS, o, H:i a e');
$user = $_SESSION['username'];
?>
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<link rel="stylesheet" type="text/css" href="css/main.css">
<head> <title> Blog - Preview </title> </head>
<body>
<div class="wrap">
<div class="navPreview">
<ul>
<li>Back<br></li>
</ul>
</div>
<div class="main">
<h1>Preview</h1>
<div class="mainscroll">
<?php
echo "<span>Submitted at: $getTime by $user</span><br>";
echo "<h2>$getTitle</h2>";
echo "<p>$getEntry</p><hr>";
?>
</div>
</div>
</div>
<div class="footer">x</div>
</body>
addentry.html
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<link rel="stylesheet" type="text/css" href="css/main.css">
<head> <title> Blog - Add Entry </title> </head>
<body>
<div class="wrap">
<div class="header">
<h2> Welcome.. </h2>
<p>..add an entry below</p>
</div>
<div class="nav">
<ul>
<li>Home<br></li>
<li>Add Entry<br></li>
<li>Logout<br></li>
</ul>
</div>
<div class="main">
<form id="entryForm" action="addentry.php" method="post">
<p class="title">
<label>Title:</label>
<input type="text" name="title"><br>
</p>
<p class="body">
<label>Entry:</label>
<textarea name="entry"></textarea><br>
</p>
<p class = "buttons">
<script type="text/javascript">
function clearConfirm() {
var confirm = window.confirm("Are you sure you want to clear?");
if (confirm) {
document.getElementById("entryForm").reset();
}
}
function previewForm(action) { document.getElementById('entryForm').action = action;
document.getElementById('entryForm').submit();
}
</script>
<input type="button" onclick="clearConfirm()" value="Clear" />
<input type="button" onclick="previewForm('preview.php')" value="Preview" />
<input type="submit" value="Submit" />
</p>
</form>
</div>
<div class="footer">x</div>
</div>
Maybe add a target="_blank" ? It will open the preview in a new tab.
<input type="button" onclick="previewForm('preview.php')" value="Preview" target="_blank"/>
EDIT: Oups not in the form but on your preview link...
Or something like this : http://www.w3schools.com/tags/att_button_formtarget.asp
Related
i am try to learn kohana and have problem with kohana+ajax, console say me about response with full page+ print_r + name\phone for ajax response if run example without kohana , just php+ajax , all ok
UPD:
wait: name: $name ,phone:$phonenumber.
recieve(look console.log): page from main template + print_r+ response for ajax and name:undefined,
phone: undefined.
here code for reproducing the behaviour:
Controller/example.php:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Example extends Controller_Common
{
public function action_index()
{
$content = View::factory('/example/show')
->bind('example', $example)
->bind('errors', $errors);
if ($this->request->is_ajax()) {
if (isset($_POST["name"]) && isset($_POST["phonenumber"]) ) {
$result = array(
'name' => $_POST["name"],
'phonenumber' => $_POST["phonenumber"]
);
print_r($result);
echo json_encode($result);
}
}
else $this->template->content=$content;
}}
View:
<!doctype html>
<html lang="en">
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
</head>
<body>
<form method="post" id="ajax_form" action="" >
<input type="text" name="name" placeholder="NAME" /><br>
<input type="text" name="phonenumber" placeholder="YOUR PHONE" /><br>
<input type="button" id="btn" value="send" />
</form>
<br>
<div id="result_form"></div>
</body>
</html>
<script>
$( document ).ready(function() {
$("#btn").click(
function(){
sendAjaxForm('result_form', 'ajax_form');
return false;
}
);
});
function sendAjaxForm(result_form, ajax_form) {
jQuery.ajax({
url: '',
type: "POST",
dataType: "html",
data: jQuery("#"+ajax_form).serialize(),
success: function(response) {
//console.log(response);
//result = jQuery.parseJSON(response);
result = response;
console.log(result);
document.getElementById(result_form).innerHTML = "name: "+result.name+"<br>phone: "+result.phonenumber;
},
error: function(response) {
document.getElementById(result_form).innerHTML = "Error";
}
});
}
</script>
Controller/Common:
<?php defined('SYSPATH') or die('No direct script access.');
abstract class Controller_Common extends Controller_Template {
public $template = 'main';
public function before()
{
parent::before();
View::set_global('title', 'My Site');
View::set_global('description', 'My Site');
$this->template->content = '';
$this->template->styles = array('main');
$this->template->scripts = '';
}
} // End Common
Main Template View:
<!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><?php echo $title; ?></title>
<meta name="description" content="<?php echo $description; ?>" />
<?php foreach($styles as $style): ?>
<link href="<?php echo URL::base(); ?>public/css/<?php echo $style; ?>.css"
rel="stylesheet" type="text/css" />
<?php endforeach; ?>
</head>
<body>
<div class="layer">
<div class="container">
<div class="header"><h1>Logo</h1></div>
<div class="left">
<h3>Menu</h3>
<br />
<ul>
<li>Home</li>
<li>about</li>
<li>Reg</li>
<li>contacts</li>
<li>Articles</li>
</ul>
<li>Article1</li>
<li>Article2</li></ul>
</div>
<div class="content"><?php echo $content; ?></div>
<div class="clearing"></div>
<div class="footer">2011 All rights reserved</div>
</div>
</div>
</body>
</html>
Console.log :
Array
(
[name] => 1
[phonenumber] => 1
)
{"name":"1","phonenumber":"1"}<!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>My site</title>
<meta name="description" content="My site" />
<link href="/public/css/main.css"
rel="stylesheet" type="text/css" />
</head>
<body>
<div class="layer">
<div class="container">
<div class="header"><h1>Logo</h1></div>
<div class="left">
<h3>Menu</h3>
<br />
<ul>
<li>Home</li>
<li>about</li>
<li>Reg</li>
<li>contacts</li>
<li>articles</li>
</ul>
<li>article1</li>
<li>article2</li></ul>
</div>
<div class="content"></div>
<div class="clearing"></div>
<div class="footer">2011 All rights reserved</div>
</div>
</div>
</body>
</html>
problem solved, get anwer from :
autor: croll ,
Source
after json_encode(); add exit; // for unknown reasons, the main template was attached to the answer for ajax and exit; fix it.
and result = response;=>result = jQuery.parseJSON(response); // for decode ajax answer
So all I want is to rotate my webcam using a servo moteur, so when I click one of the three buttons (which the program will execute a python script) I get no result! Please any help?
The Code:
<?php
if (isset($_POST['rotateright'])) {
shell_exec("python Rotateright.py");
}
elseif (isset($_POST['rotatedefault'])) {
shell_exec("python defaultpositon.py");
}
elseif (isset($_POST['rotateleft'])) {
shell_exec("python Rotateright.py");
}
?>
<html lang="fr">
<head>
<meta charset="utf-8">
<link href="camerasurveillance.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="container1">
<img class="home" src="home.png"/>
</div>
<div class="container">
<br><br><br>
<!--<img class="live" src="http://192.168.1.8:8082/?action=stream"
width="500" height="350" alt="Live Feed" title="Raspberry pi" />-->
<br>
<form method="POST">
<input class="Rotater" type="submit" name="rotateright" value="Rotation
à droite">
<input class="default" type="submit" name="rotatedefault"
value="Position initiale">
<button class="Rotatel" name="rotateleft">Rotation à gauche</button>
</from>
</div>
</div>
First time posting here (so please be gentle, as I am a relative PHP newbie).
I am building an intranet for our company and one of the things I need to do is to create a form that lists all outstanding sales orders (pulled from our accounting database) and provides a "submit" button beside each one to create the relevant work order.
Here is the code:
<div class="report_column">
<div class="report_header">
<div class="report_column_title" style="width:150px;margin-left:5px">ship date</div>
<div class="report_column_title" style="width:200px">customer</div>
<div class="report_column_title" style="width:140px;text-align:right">item</div>
<div class="report_column_title" style="width:120px;text-align:right">quantity</div>
</div>
<?php
// Open connection
include 'includes/dbconnect.php';
// Perform query
$result = mysqli_query($con,"SELECT * FROM tSalOrdr ORDER BY dtShipDate ASC");
// Retrieve results
while($row = mysqli_fetch_array($result)) {
$order = $row['lId'];
if ($row['bCleared'] == 0) {
$shipdate = substr($row['dtShipDate'], 0,10);
$customer = $row['sName'];
$po = $row['sComment'];
echo '<div class="report_item" style="width:750px";>';
echo '<form class="form" action="index.php?page=form&item=create_work_order" method="POST">';
echo '<div class="report_item_date" style="width:120px">'.$shipdate.'</div>';
echo '<div class="report_item_name" style="width:530px">'.$customer;
echo '<input type="hidden" name="po" value="'.$po.'" />';
echo '<input type="submit" class="submit" style="height: 25px;width:100px;margin:0px;padding:0px;margin:0px" value="work order"/>';
echo '</div>';
$result2 = mysqli_query($con,"SELECT * FROM tSOLine WHERE lSOId=$order ORDER BY sDesc ASC");
while($row = mysqli_fetch_array($result2)) {
if ($row['dRemaining'] <> 0) {
echo '<div class="report_item_details">';
echo '<div class="report_item_item">'.$row['sDesc'].'</div>';
echo '<div class="report_item_quantity">'.$row['dRemaining'].'</div>';
echo '</div>';
}
}
echo '</form>';
echo '</div>';
}
}
// Close connection
mysqli_close($con);
?>
</div>
What happens when I do this is that the first "submit" button will, for some reason, send me back to "index.php". The other buttons will load the correct page, however, they do not POST the required value.
Is there something I am doing wrong or is this something that needs different methodology than what I am currently using? My research on this seems to indicate that perhaps I should use javascript or an array to deal with this, but, having never dealt with either, I am not sure how to proceed. Any pointers would be appreciated.
Thanks.
#maniteja: The index.php is as follows:
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="en" />
<title></title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<link href="css/forms.css" rel="stylesheet" type="text/css" />
<link rel="icon" type="image/ico" href="favicon.ico" />
<script type="text/javascript" src="scripts/jquery-2.1.0.min.js" ></script>
<script type="text/javascript" src="scripts/tabcontent.js" ></script>
</head>
<body>
<!-- BEGIN MAIN CONTENT -->
<div id="wrapper">
<!-- BEGIN HEADER -->
<div id="header">
<img src="images/logo.jpg">
</div>
<!-- END HEADER -->
<!-- BEGIN MAIN MENU -->
<div id="leftcolumn">
<?php include 'includes/menu.php'; ?>
</div>
<!-- END MAIN MENU -->
<!-- BEGIN CONTENT FRAME -->
<div id="rightcolumn">
<div id="content_area">
<?php
if (isset($_GET['page']))
{$page = $_GET['page'];
include('pages/' . $page . '.php');}
else {include('pages/home.php');}
?>
</div>
</div>
<!-- END MAIN CONTENT -->
</body>
</html>
I've made seventeen other forms with it, so I don't think that it is the problem. I'm hoping that this is just a typo or a logic error on my part.
u can use
<button type='submit' class='' name='' onclick=''>Submit</button>
Try to do onclick. See my example below.
input type="button" name="submit" onclick='location.href="index.php?id=$id"'
AS far as I understand, you are making your forms go to index.php:
echo '<form class="form" action="index.php?page=form&item=create_work_order" method="POST">';
Can you explain what is your expected behavior when a button is pushed?
The page is getting messed up because of something in the page I searched a while and I just cant find what is wrong.
Probably the div in zoek.html but could you guys take a look?
EXACTLY WHATS HAPPENING: NORMAL PAGE MENU FLOATS IN THE MID WHEN OPENING THIS ONE THE MENU GOES TO THE LEFT CORNER AND ALSO the CONTENT menu goes to the left.
home_zoek.php *PHP:
<?php
include("config/instellingen.php");
ob_start();
session_start();
$loggedin = $_SESSION['loggedin'];
if (empty($_SESSION['naam'])){
die("Log eerst in voordat u deze pagina bezoekt.");
}
if (isset($_GET['logout'])){
session_destroy();
header("Refresh: 0; url=\"index.php\"");
}
date_default_timezone_set("Europe/Amsterdam");
$logdate = date('H:i:s');
$logs = "INSERT INTO `logs` (`id` ,`naam` ,`text`,`datum`,`ip`)VALUES (NULL , '$_SESSION[naam]', 'Heeft pagina $_SERVER[PHP_SELF] bekeken', '$logdate','$_SERVER[REMOTE_ADDR]');";
$meldingen2 = mysqli_query($connect, $logs);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Heijmans | Planning</title>
<link href='http://fonts.googleapis.com/css?family=Droid+Serif:400italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="css/_style_logged.css" />
<link rel="stylesheet" type="text/css" href="css/_style_menu_left.css" />
<link rel="stylesheet" type="text/css" href="../css/_style_menu_left.css" />
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet'>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="../js/script.js"></script>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<?php include("home_menu.php"); ?>
<div id="header-with-tabs">
<?php include("home_menu-3.php"); ?>
</div>
<div id="content">
<?php include("home_menu-2.php"); ?>
<div class="page-full-width cf">
<div class="side-content fr">
<div class="content-module">
<div class="content-module-heading cf">
<h3 class="fl">Hoofd pagina</h3>
<span class="fr expand-collapse-text">Klik om te verkleinen</span>
<span class="fr expand-collapse-text initial-expand">Klik om te vergroten</span>
</div>
<div class="content-module-main">
<thead>
<p>
<font color="black">Zoek hier op postcode of klantvraagnummer de resultaten verschijnen automatisch en zijn altijd up to date</font>
</p>
<p>
<font color="black">Minimum 3 letters, bijv. 1093 VD.</font>
</p>
<?php include("zoek.html"); ?><br />
<div id="show_results"></div>
</div>
</div>
</div>
</div>
</thead>
</ul>
</table>
</div>
</div>
</div>
<?php include("home_footer.php"); ?>
</body>
</html>
zoek.html *PHP:
<head>
<script type="text/javascript" src="js/search.js"></script>
<script src="js/pagination.js" type="text/javascript"></script>
<script>
htmlData('search.php', '');
</script>
</head>
<body>
<div id="form">
<input type="text" id="terms" onkeyup="getScriptPage('show_results','terms','1')" onblur="if ( this.value == '' ) this.value = this.defaultValue" onfocus="if ( this.value == this.defaultValue ) this.value = ''"/>
</div>
</div>
</html>
It is important to ident your code to see if you have extra tags, or missplaced tags in your html code. In this case, your </thead> in your <div class="content-module-main"> is at the wrong place. Furthermore, you have extra </div> tags.
Another issue here is that you have <head>, <body> and </html> tags in your zoek.html file. They are not expected here since the code is directly inserted in the parent file home_zoek.php.
Remove them, clean your code and it should behave as expected.
I currently am trying to use print inside of the JQuery footer by writing it is not working. Instead nothing shows up. In the earlier php page I stored it into the session using...
session_start();
$_SESSION['username'] = $_POST['username'];
my code in my html page is as follows...
<?php session.start();
?>
<!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>Food For Thought</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css" />
<script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js"></script>
</head>
<body>
<div data-role="page" id="page1">
<div data-role="header" id = "hdrMain" name = "hdrMain" data-nobackbtn = "true">
<h1>Food for Thought</h1>
</div><!-- /header -->
<div data-role="content" align ="center">
Play
Profile
Logout
</div><!-- /content -->
<div data-role="footer">
<p>Logged in as: <?php print $_SESSION["username"]; ?> </p>
</div>
</div>
</body>
</html>
Thank you any help is appreciated.
Edit: Problem was that the file I was trying to run php code ended in .html instead of .php. Thank you all who tried to help.
Well, you're HTML page has:
session.start();
it should be
session_start();