Changing the whole page while keeping a div open - php

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>

Related

HTML PHP FORM two actions?

I have a HTML form where after the user submits the form they see my FormSubmit.php thank you page. Is there a way to make that thank you page still display after submission, but also add a link to another php page that shows you a list of who added their names?
I created a SignupList.php page that reads from a text file. I added the link to the form HTML page at the bottom and to the FormSubmit.php thank you page, but when I add a name ,reach my FormSubmit.php thank you page, then click the link to my SignupList.php page there are no names on it. I noticed on the HTML page in the form action section when I replace FormSubmit.php with SignupList.php I get my desired results a name displays after hitting submit, but my thank you page is gone since I removed the action to it. Any suggestions on how I can do both? Please let me know if I need to explain further.
<!DOCType html>
<html>
<head>
<title>Form</title>
<html lang="en">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
</head>
<body>
<form method="post" action="FormSubmit.php">
<p>Please sign up</p>
<p> First Name:<br>
<input type="text" name="firstname" size="30">
</p>
<p> Last Name:<br>
<input type="text" name= "last name" size="30">
</p>
<p>
<input type="submit" value="Submit Information">
</p>
View Sign Ups
</form>
</body>
</html>
edit: I am not sure why i was down voted, but i figured out the issue. I needed to edit my FormSubmit.php file to write to the document.
In your Formsubmit.php, add:
header('Refresh: 3;url=page.php');
which will refresh the header and redirect the page after 3 seconds.

When I open my index.php page, it opens showing the bottom

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>

How to process and display the outer layer of html first before 'loading' the content?

How can I ask PHP to process and display the outer layer of html first before 'loading' the content? For instance,
<html>
<body>
<p>Please wait, we are processing your request</p>
<?php include 'article.php';?>
</body>
</html>
I want to print this on the client browser first,
<html>
<body>
<p>Please wait, we are processing your request</p>
</body>
</html>
before showing whatever is included here,
<?php include 'article.php';?>
Is it possible?
You can do it with Jquery:
<html>
<body>
<div id='article'>
<p>Please wait, we are processing your request</p>
</div>
<script>
$("#article").load("article.php");
</script>
</body>
</html>
The .load command gets the contents from whatever URL you provide, and sticks it in the named DOM element (#article).
Read all about it:
http://api.jquery.com/load/

Printing the current page to pdf using wkhtmltopdf

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'.

Html Post Method get blank page after refresh

I am testing Html form using post method and got this odd result:
I have two html pages on server apache (already installed php): post.html and target.html, and the code for these page are followings:
post.html (don't worry about the html standard)
<div style="text-align: center">
<form method="POST" action="target.html">
<input type="text" name="testname" value="sometext" />
<input type="submit" value="submit" />
</form>
</div>
and target.html
<html>
<head>
</head>
<body>
<h1>Target page</h1>
</body>
</html>
When I entered data to the form on post.html page and hit submit button, I got to the target.html page. When on this page(target.html), I refreshed the page, and what I receive is a blank page. The second time I refreshed, It turned to normal Html page.
I don't know why it returned a blank page the first time I refreshed, I have tried the same approach but with PHP page, and the content of target page (assum name target.php) still remains (not blank like html files above)
So, could you explain me about this problem?
Thank you.
This definitely has something to do with your browser. Same here on a mac using Safari, on some pages after submitting the content, the page seems to freeze, I refresh it, and then it works again.
Definitely not a code problem, as far as I'm concerned.
It's because you cannot pass an input from html to html file. Your target.html should be a php file (target.php).
and try to put this code on your target.php
<?php
var_dump($_POST); //this will show the inputted text and also show the data type and will stop the code execution here. other codes below will not be executed.
echo $_POST['testname'];
?>
Additionally, change target.html to target.php in your form action
First I will start out by correcting your post.html
<div style="text-align: center;"> <!-- added a ; after center -->
<form method="POST" action="target.html">
<input type="text" name="testname" value="sometext" />
<input type="submit" value="submit" />
</form>
</div>
that may not matter but you should end all your styles with ;
To continue, everything looks fine. maybe something weird happened between refreshes.
save your form page in php than add the php script in the same page, here try this. remember save in .php.
<?php $testname = $_Post['testname'];
echo $testname ?>
<div style="text-align: center">
<form method="POST" action="">
<input type="text" name="testname" value="sometext" />
<input type="submit" value="submit" />
</form>
</div>

Categories