When I open my index.php page, it opens showing the bottom, I want it to open normally, at the top. How can I do that?
Remove autofocus="on" from your form input fields, the first thing I notice when the page loads is the input has cursor focus, and since it's below the fold the browser is scrolling downwards.
<!DOCTYPE html>
<html>
<body>
<button type="button" onclick="alert('Hello world!')">Click Me!</button>
</body>
</html>
Related
I simplified my real php page just to get an idea, I have this simple php page with a div, I want to keep this div open and its input with the text that has been changed by the user, when I change the page and go to page2.php
<html>
<head> stuff.. </head>
<body>
stuff in the body..
<div>I want this div to stay in the other page, (without cloning it)
<input type="text" value="hello" />
</div>
</body>
</html>
For practice, on an html page, I have 2 buttons.
1 button was made using the tag, and it redirects to another page. (this works)
The second button, when pressed needs to display more features and options that populate the blank area of the page.
<?php
$action = (isset($_GET['sent'])) ? $_GET['sent'] : null;
If($action!=null){
?>
Other buttons go here, <b>Hello</b>
<?php
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'].'?sent=yes'; ?>" method="get">
<input type="submit" value="Show more buttons" />
</form>
Give or take that should do what you want to do. Although I recommend learning as this method is a little annoying as the entire contents of the page have to be refreshed. When dealing with text, it's not so bad, but most websites have images.
Try using CSS with javascript. Have the additional content in a separate div that is position:absolute and visibility:hidden. Attach javascript to the 2nd button, so that click changes visibility to visible.
Recently installed wkhtmltopdf. Was trying to capture the entire page in its current state, however, the below method seems to navigate to the initial state of that page without all the input fields that the user has entered.
PHP
shell_exec('wkhtmltopdf http://localhost/www/bolt/invoice.php invoice.pdf');
I was wondering if someone knew of an implementation of wkhtmltopdf that captures the current state of the page including any text entered in the text fields??
I appreciate any suggestions.
Many thanks in advance!
wkhtmltopdf hits the page independently of your current browsing session. If you hit it like that, you're going to get what anyone would see when they first go to your page. Probably what you want to do is save the current page using an output buffer, and then run wkhtmltopdf on the saved page. Here's some sample code:
sub.php
<?php
$documentTemplate = file_get_contents ("template.html");
foreach ($_POST as $key => $postVar)
{
$documentTemplate =
preg_replace ("/name=\"$key\"/", "value=\"$postVar\"", $documentTemplate);
}
file_put_contents ("out.html", $documentTemplate);
shell_exec ("wkhtmltopdf out.html test.pdf");
?>
template.php
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<h1>This is a page</h1>
<form action="sub.php" method="post" accept-charset="utf-8">
My Test Field:
<input type="text" name="test_field" value="">
<input type="submit" value = "submit">
</form>
</body>
</html>
Probably in the long run you should have some kind of base template that both pages would use, and one have some markers like value='%valueOfThisVariable%' in your input fields that you can replace with blanks when you present the fields to the user, and fill with the user data when you create the page that you want to write to pdf. Right now it's just going through and replacing all the name='this_name' with value='this_name->value'.
I have an HTML page which has a text box and a button...
<html>
<head></head>
<body>
<form name = "inputdata" method ="get" action ="prc.php">
<input type="text" name="data">
<button id ="checkbox" type="buttton" name="submit" value="submit">Submit!</button>
</form>
</body>
</html>
The code for prc.php is...
<?php
$data=$_GET['data'];
echo "<html><head></head><body><div id=\"maindata\"> ";
echo $data;
echo "</div></body></html>";
?>
I have a PHP file which gets the contents of the previous page...
<?php
file_get_contents("index.html");
?>
However, I would like to add functionality to the above PHP script such that it gets the page contents in the background and uses some jQuery on it:
$('#inputdata').val('hello boss');
$('#checkButton').click();
This will enable me to fill out the text box in the background and submit the button. Then I need to get the result from prc.php using jQuery...
$('#maindata').html();
Does anybody know how to do this?
It sounds like you want to submit the form on the page. This should be possible by simply requesting the resource in the action field. In your example, requesting the url prc.php with a parameter called data which contains the data input data you wish to submit.
prc.php?data=mydata
In my php file called "account.php" I have
<?php
// First we execute our common code to connection to the database and start the session
require("common.php");
// At the top of the page we check to see whether the user is logged in or not
if(empty($_SESSION['user']))
{
// If they are not, we redirect them to the login page.
header("Location: login.php");
// Remember that this die statement is absolutely critical. Without it,
// people can view your members-only content without logging in.
die("Redirecting to login.php");
}
?>
<html>
<body>
<link rel="icon" type="image/gif" href="favicon.gif" />
<?php include("header.php"); ?>
<div id="main-box">
<ul>
<li class="buttons">
<?php
//TEXT BOX WITH A LINE FROM **TEXT.txt** SHOULD APPEAR HERE AFTER USER CLICKS BUTTONS
?>
<input type="button" name="account" value="Get Your Account" onclick="#" />
</li>
</ul>
</div>
</body>
</html>
I want it so when the user clicks the button, a text box appears and displays ONE line from the text file and when they view it, it deletes it from the text file.
text.txt
Eddie so after the user clicks the button it displays this line to them and then deletes it after so that the next line would then become the first line.
Apples
Hello
People
If you don't understand my question then please let me know and I will try to explain further. Thank you. :)
My recommendation is to use javascript (or jQuery) to make an AJAX call to a PHP script that handles the reading of the text file, and then deletes the top line. The javascript would then need to take the script's response (the line on the text file) and add the text box to the page.