Does Drupal have print button like print link - php

Drupal has a print link function that I'm using in my .tpl.php
<?php
print l(t('Announcement'), 'node/30');
?>
l makes it become a link. Does drupal have an equivalent API function to make buttons?
If not, what's your best suggestion for this?

It comes down to what you mean by 'button'.
If you are talking about an actual form button, then you will want to look at the drupal form API for how to go about making forms.
If you are talking about making something that looks like a button, then I would still be using l(), but pass along something like "class" => "my-fancy-button" to the attributes array, then style the my-fancy-button class with CSS - either simply with a bg colour and some borders, or with a more complicated image background.

Start here: http://api.drupal.org
About forms: http://api.drupal.org/api/group/form_api/6
About writing modules: http://drupal.org/developing/modules
Examples of forms and others here: http://drupal.org/project/examples

Related

Angular ng-init fails to assign with html elemets

I have a administration corner on my web, where can Admin create and post news.
It's implemented with html alements as helper. Admin clics on buttons and elements helps him, to style his text.
It looks this:
I have an option to Edit existing News as well.
Problem is if I try to assign this html text into my variable in ng-init
It all go bad.
<h4 ng-init="TextAreaText = '<?php if ($_GET["NID"]) $Admin->DrawNewsByID($_GET["NID"]) ?>'"> Editor </h4>
It means if there is NewsID in Get, It selects News text in php and tries to assign it into TextAreaText varible.
But it is shown like this:
Because of my bad quotation marks.
As you can see: - source code from my browser
Is it possible to samehow fix it?
Thanks a lot.

Add class to url with php

I have a database with roughly 500 cards.
They have qualities 0,1,2,3,4,5.
Each quality has different colors, in CSS I have:
.quality0 { color: grey }, .quality1 { color: green } and so on...
I want if there's an URL on the page, like mywebsite.com/card/card_id_comes_here, then add a class called quality + print $card['quality']
$card['quality'] is the number (0,1,2,3,4,5) from database.
I use this code on pages where I just list the cards and their names, there's no problem with this, because everything is already there:
<a class="quality<?php print $card['quality'] ?>"
href="/card/<?php print $card['id']; ?>">
<?php print $card['name']; ?></a>
But if I create a new article and link to these card pages, It won't type manually to all URLs that class="quality3" or so...
I want if I have an URL with mywebsite.com/card/id to add the class quality + print the id from database as I mentioned above.
How is this possible?
You will have to retrieve the id from the url. The best way probably is to use the mod-rewrite module and retrieve the id-variable from the url via $_GET.
It is a bit tricky if you have never done it before, you better look at some examples and read a guide like this one: Guide to mod_rewrite
edit: If you have the ID, I guess you know how to do the rest, right?

i want to get data from another website and display it on mine but with my style.css

So my school has this very annoying way to view my rooster.
you have to bypass 5 links to get to my rooster.
this is the link for my class (it updates weekly without changing the link)
https://webuntis.a12.nl/WebUntis/?school=roc%20a12#Timetable?type=1&departmentId=0&id=2147
i want to display the content from that page on my website but with my
own stylesheet.
i don't mean this:
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
or an iframe....
I think this can be better done using jquery and ajax. You can get jquery to load the target page, use selectors to strip out what you need, then attach it to your document tree. You should then be able to style it anyway you like.
I would recommend you to use the cURL library: http://www.php.net/manual/en/curl.examples.php
But you have to extract part of the page you want to display, because you will get the whole HTML document.
You'd probably read the whole page into a string variable (using file_get_contents like you mentioned for example) and parse the content, here you have some possibilities:
Regular expressions
Walking the DOM tree (eg. using PHPs DOMDocument classes)
After that, you'd most likely replace all the style="..." or class="..." information with your own.

Wordpress - I want to add a <div></div> with a Plugin

I'm trying to learn wordpress and php.
Basically, I want the
function draw_ad() {
echo "IMAGE CODE INSIDE A DIV";
// echoing an image inside a div -- StackOverflow does not allow me to post img tags : )
}
add_action('the_content', 'display_ad');
===
Basically, I want to add a picture and be able to manipulate the "left" and "top" css options... but with a plugin. So it will be like a strange picture that covers whatever the area on the screen that I want it to cover :P.
Yes, it is kind of sloppy, but that's what I was asked to do : P.
The add_action('the_content', 'display_ad') kind of does it, but it removes the whole content.
Is there a better way to do this?
Is there a way to tell the wordpress PLUGIN to add this , say, before the theme's header, and not content? (As in, be able to put this thing wherever you want to in the html body tags?
Thank you, guys!
From theme developing I am sure you can add code to the header and at the end of the body tag. (wp-header, wp-footer)
The best thing is to insert the picture tag at the end of the body and style it with position:fixed;. You don't need a div around the img tag.

animate div background with php

Hello i am trying to animate a div background color this way with php and javascript html.
<div background="<?=for($step = 0; $step < 256; $step++)
echo "rgb($step, $step, $step);"; ?>" /> contents </div>
So the code will make change the div from black to white as my example clearly shows.
But it is not working, any ideas?
i want to implement it in my personal website http://www.nickersonweb.com/ buttons
Once your page is generated by PHP and sent to the client, your PHP code can no longer change the content on the client side.
That's where client-side code (Javascript) comes in.
To quickly achieve what you're trying to do, have a look at this question: jQuery animate backgroundColor , which recommends using jQuery with the jquery-color plugin. Here's a quick demo: http://jsfiddle.net/MCwxG/
p.s. I'm sure it's possible to do it with pure javascript, but my js-fu is not accomplished enough to show you how.
You can't do it with php, it's server side.
But you can do it with the color plugin with jQuery.
Well, you're using <?= with a for loop statement, when it should only be used with an expression. You need to change that to <?php (or <? if your server supports it).
<div>s don't have a background attribute. You'd need to modify their style.
You're writing all of the style changes to the page before you're writing the content.
The browser can't even try to render the <div> before it's closed with >, and all of your styles will be interpreted at once, and only the last one will be visible.

Categories