I used this code to print the current page:
<form>
<input type="button" value="Print" onClick="window.print();" />
</form>
but when I view it using universal document converter. It has this url in the upper right corner. How do I get rid of it?
I believe that's a browser by browser setting and can't be set through the page. I'd love it if someone could prove me wrong, though. :)
Just as theIV says it depends on the browser.
One way of doing it would be to convert it to a PDF that can then be downloaded by the person wanting to print it. Maybe a starting point is this HTML to PDF converter online - try searching for more though.
Related
Im new to PHP, and by that I mean BRAND NEW. Today is the first time I've really even sat down and gave it a shot for an extensive period of time.... And the thing I'm trying to achieve is kinda silly... ive been making a little flash game website for quite some time now... Just to get my hands dirty with web design and HTML and CSS i seem to be doing fine with. The website is just a simple flash game website that I made so I could play some of my favorite flash games at school when i had nothing better to do. and I had remembered on an old website i use to go to in order to do the same thing had a "panic button" underneath every game which when clicked just took you to google... I thought it was a funny and smart idea so i wanted to improve on it, i figured i would make a little PHP script that would enable the user to change the link to whatever you want. So lets say the teacher says you need to be on, oh i dont know... SCIENCE.COM! you just copy and paste the URL into the input bar on the front page and it automatically saves it in your cookies that thats the URL you want to go to when you click the "panic" button... I guess ill post the code ive been trying to get it to work with so you can all see.
Heres the PHP:
$expire=time()+0*0*12*0;
setcookie('panic', $panic, $expire);
?>
Here is the HTML:
<form method="post">
<input type="text" name="panic" size="80" id="panic"/>
<input type="submit" value="Submit"/>
</form>
<br />
<?php
echo ('click HERE to see if it worked!');
?>
I probably dont seem too smart from this... Ive literally been going at this for hours, for some reason i just cant seem to figure it out.... And i dont know if its possible, can i have the main PHP for the cookie in a separate file from the HTML or no?...
I must also point out that out of desperation i went around editing lots of names, so i must say if anything seems extremely out of place its more then likely because i was getting frustrated and messing the the code in odd ways.
I think your problem is due to misused quotes around your PHP in the following code. Also you are using curly braces for your $_COOKIE[] selector, and trying to select the cookie by its contents, rather than its name (you are using $panic instead of 'panic'):
<?php echo ('click HERE to
see if it worked!'); ?>
Single quotes mean that you don't need to escape double quotes, and also that any PHP variables you include inside the quotes won't automatically be replaced, so these will need to be concatenated outside of the quotes.
Try replacing it for this:
<?php
echo ('click HERE to see if it worked!');
?>
It's because your html is wrong. You can't set cookies that way. PHP is run server-side, not client-side. Try this.
HTML
<form method="post">
<input type="text" name="panic" size="80" id="panic"/>
<input type="submit" value="Submit"/>
</form>
<br />
<?php
echo ('click HERE to see if it worked!');
?>
PHP
<?php
error_reporting(E_ALL ^ E_NOTICE); // prevent it from erroring if something isn't defined
if($_GET["viewcookie"]){
echo $_COOKIE["panic"];
} else if($_POST){
$panic = $_POST["panic"]
setCookie('panic', $panic, time()+(60*12)); //expires in 12 minutes
echo $_COOKIE["panic"];
}
?>
I have a php form on my website and it works well under firefox. But whenever I tested on IE(v8 and 9), the form doesn't get sent, and it returns a "IE can't display the webpage" error.
The script is located at http://www.fitnessgrace.com/Vancouver-Personal-Trainers/Vancouver-Personal-Trainers-Contact-Fitness-Grace.htm
Any insights would be very much appreciated.
you are posting the page to http://www.FitnessGrace.com/gdform.php
and you have a hidden input
<input type="hidden" name="redirect" value="../index.html" />
after this point, I can only guess, but I think you are trying to redirect to "../index.html", and since gdform.php is already at the root directory, ../ is meaningless. I think firefox somehow understands that you've made a mistake and doesn't care, but ie doesn't understand.
Ok this has had me banging my head for a while, I have posted on other forums but the info is sketchy at best, I hope you guys can help.
Scenerio:
I have a html landing page with a search field. here is the form:
<form method="get" action="URL TO EXTERNAL SEARCH" target=content>
<fieldset>
<input type="text" class="text" name="keywords" value="Search" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"maxlength="30" />
<input type="image" src="images/topnav/btn_search.png" class="button" />
</fieldset>
</form>
So it obviously takes the queried string and off it goes to an EXTERNAL domain which processors the string and returns the result as an HTML page, which in turn displays it in an Iframe named "content" within the same page.
<iframe src="DEFAULT CONTENT" name="content" width="803" height="1200" align="left">
Works a treat, however
PROBLEM:
I have other pages that DO NOT contain the Iframe but contain the search field.
WHAT I NEED TO ACHIEVE:
I need to enter the search string in a html page that DOES NOT contain an Iframe, and display in an Iframe on another html page.
I thought of using javascript/ jquery but due to cross site security issues it doesnt work hence PHP.
I know it can be done but lack the know how.
Any help suggestions would be greatly appreciated.
Thankyou
************UPDATE********************
Cheers for the suggestions so far but I have a few queries:
Thanks for the answer but I have a couple of questions so excuse my ignorance.
"landingpage.html" contains a search box but no Iframe to display the search result. "displaypage.html" contains a search box and an Iframe to display search results.
"displaypage.html" works fine; it sends the query string to the EXTERNAL server which returns a HTML page that I send to Iframe in "displaypage.html".
"landingpage.html" needs to direct the search query to "mysearchhandler.php" which in turn processors the query and returns the resulting html page to the Iframe located in "displaypage.html"
This is what I require to happen, I must have the search option on all my pages without an Iframe and be able to direct them to "displaypage.html"
My problem is lack of PHP understanding, so I am very grateful for your help guys but If possible could you place the code in context to relevant pages, it is easier for me to understand where the code goes and what it is doing.
Iam getting the stage where I am considering paying for the code, but I would like to
Anybody ?
What you could do is have a utility page that handles the search via PHP and returns the expected page.
<form method="get" action="mysearchhandler.php" target=content>
<input type="hidden" name="currentPage" value="thispage.php" />
And in mysearchhandler.php you could user http_get http://www.php.net/manual/en/function.http-get.php to pull down the information from the external search page. Use it with http_parse_message http://www.php.net/manual/en/function.http-parse-message.php
Use the hidden field to tell you which page to return, and update the page to look for the search data.
A simple mysearchhandler.php:
$search = clean($_POST['keywords']);
$currentPage = clean($_POST['currenPage']);
$url = <external search url with get parameters>
$searchResults = http_parse_message(http_get($url))->body;
//Need to validate $currentPage to prevent faked user input
include($currentPage); //Depending on your file system you may need to adjust this
Then in your page you could add:
if(exists($searchResults))
{
<Code to display the results>
}
When I press 'View source code' of a certain web page, it's kind of like this:
<form action="/WANem/index-advanced.php" method="post">
<table border="1" width="100%">
<tr>
<td width="10%" >Delay time(ms) </td>
<td width="10%" ><input type="text" name="txtDelay1" size="7" value=1200>
</td>
<input type="submit" value="Apply settings" name="btnApply">
</table>
</form>
My question is: How can i get '1200' in the code using PHP.
I mean i just want to get a certain string in the html code of another website without having to press 'view source code' and copy that string.
Thanks for any reply.
What you're trying to do is called "web scraping".
Here's a StackOverflow question with a bunch of helpful answers:
How to implement a web scraper in PHP?
And here is a tutorial that probably explains it better than I could by typing it out here:
http://www.thefutureoftheweb.com/blog/web-scrape-with-php-tutorial
Hope it helps and good luck!
In your php file it is something as simple as this:
$value = $_POST['txtDelay1'];
Although, it looks as a really basic question. I suggest you to go through some tutorials, to get the idea on how it all works.
First on in google php form tutorial: http://www.phpf1.com/tutorial/php-form.html
EDIT:
Oh, now i see your edits. In that case, you can't skip sending a http request to get the source code, just like a browser does. Next, you have to parse the response from the server, just like a browser does as well. Ah, The response will be the "Source code" you're asking for. If you can, consider using python to this. It will be much more faster and efficient.
If PHP is a must, be aware that this task is a pain in the ass;)
You can do this with file_get_contents() and preg_match().
//$url is whatever your URL is
$url = file_get_contents($url);
preg_match('|name="txtDelay1".*?value=([\d]+)|', $html, $html);
echo $html[1];
//should print your value 1200
Check out the regex here.
However
This is only going to work as long as this code appears exactly and is not duplicated. Also, if you are scraping from another site, it could be changed by the owner, and the regex would no longer work.
Is it ok to write like this?
<input type="button" value="New booking" />
The link should look like a button but it should open in the right part of the page. If its wrong, is there any other way to do it?
The above code works fine. i just don't know if its the correct way to do it.
Thanks
No, this is not allowed according to the HTML5 specification.
The <button> element is considered "interactive content".
The <a> element must contain "no interactive content".
The button will probably show up, but since you're violating the specification it may not behave as you want. You should avoid doing this.
The most reliable to way to make a button bring the user to a page is to create a <form> that targets that page, and make the button submit that form.
<form action="add-lead-new.php"><input type="submit" value="New Booking" /></form>
no, the button itself wont do anything - it's only usefull with javascript to trigger any functions.
you should use css to make some of your links like a button: http://www.zurb.com/article/266/super-awesome-buttons-with-css3-and-rgba
<input type="button" value="New booking" onclick="self.frames['rightframe'].location.href='add-lead-new.php'"/>
would be ok
It's better to just use CSS, but if you're really stuck on using a physical button, you can create a dummy form with no data:
<form action="href"><input type="submit" value="Click Here" /></form>
Yours is working but this is better,
<input type="button" value="New booking" onClick="top.frames['rightframe'].src='add-lead-new.php'" />
This is what worked for me.
<a><?php echo( "<button onclick= \"location.href='inc/name_of_php_file.php'\">your buttons name goes here</button>");?></a>
In other words nest your desired php code block inside an anchor element to 'link' it. Then add the php code block and inside that code block you'll want to add an echo(). Inside that echo you want to add your HTML code like normal. As if you weren't even writing in PHP.
Edit the folder name and file to your desired location. And then finally edit what text you want your button to show your viewers.
onclick= \"location.href='folder_name_goes_here/name_of_php_file_goes_here.php'\">your buttons name goes here
This should link to your page with your desired caption.
Please keep in mind the \" as this is utterly important. Without \ in front of the " your code wont read correctly due to the many "s found nested inside each other. \ allows HTML to ignore the first " as an end to the echo Sting.