Display a Success Message like Twitter

Hi,

 

i find the Css and Jquery way to display the Error or Success Message Like Twitter. For this you need Jquery.js and the Small css

 

Here Is my Code

 

CSS

 

.notification
{
text-align: center;
display: none;
width: 100%;
position: fixed;
padding-top: 8px;
padding-bottom: 8px;
margin: 0;
font-weight: bold;
font-size: 1.2em;
overflow: visible;
}
.success {background:#FFF;color:#264409;border-color:#c6d880;}
.error, .alert, .notice, .success, .info {padding:0.8em;margin-bottom:1em;border:2px solid #ddd;}
.error, .alert {background:#fbe3e4;color:#8a1f11;border-color:#fbc2c4;}

Javascript

 

var notifyCallBack;

function showNotification(message, type, callback) {

notifyCallBack = callback;

var notification = $(“#notification”);
notification.removeClass(“success notice error”);
notification.addClass(type);

//Make sure it’s visible even when top of the page not visible
notification.css(“top”, $(window).scrollTop());
notification.css(“width”, $(document).width()/2 +40);

// $(“#notification-text”).html(message);

//show the notification
notification.slideDown(“slow”, function() {

});
}

function hideNotification() {
$(“#notification”).slideUp(“slow”, function() {
if (null != notifyCallBack && (typeof notifyCallBack == “function”)) {
notifyCallBack();
}
//reset the callback variable
notifyCallBack = null
});
}

 

In Html

 

Past the Below code

 

<div id=”notification” class=’notification’>

<span id=’notification-text’></span>

</div>

 

call the function Body on load or at the end of the page showNotification(”, “success”, function(){});

 

 

 

post to Twitter with PHP and cURL

Using this scripts you can send messages to Twitter
from your web  site in a second. All you need to do is:
make sure that cURL is enabled
assign values for  user name and Twitter password in
 file  insertTwitterMsg.php (see the source code).
put files insertTwitterMsg.php and twitterAPI.php in
 the same folder  in web root folder like htdocs or public_htm
open file insertTwitterMsg.php in your browser fill in the text box
 and press button and that’s it.

<?php /* ---------------------------------------- */ // Change these parameters with your Twitter // user name and Twitter password. /* ---------------------------------------- */ $twitter_username =''; $twitter_psw =''; /* ---------------------------------------- */   // Don't change the code below /* ---------------------------------------- */ require('twitterAPI.php'); if(isset($_POST['twitter_msg'])){ $twitter_message=$_POST['twitter_msg']; if(strlen($twitter_message)<1){ $error=1; } else { $twitter_status=postToTwitter($twitter_username,  $twitter_psw, $twitter_message); } } /* ---------------------------------------- */ ?>   <html> <head> <title>Send a message to Twitter using PHP</title> </head>   <body> <h2>Post a message on Twitter</h2> <p>This page use Twitter API to send a message with postToTwitter() function.</p> <!-- This is the form that you can reuse in your site --> <?php if(isset($_POST['twitter_msg']) && !isset($error)){?> <div><?php echo $twitter_status ?></div> <?php } else if(isset($error)){?> <div>Error: please insert a message!</div> <?php }?> <p><strong>What are you doing?</strong></p> <form action="insertTwitterMsg.php" method="post"> <input name="twitter_msg" type="text" id="twitter_msg" size="40" maxlength="140" /> <input type="submit" name="button" id="button" value="post" /> </form> <!-- END --> </div> </body> </html>
<?php
function postToTwitter($username,$password,$message){
 
    $host = "http://twitter.com/statuses/update.xml?
status=".urlencode(stripslashes(urldecode($message)));
 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $host);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_POST, 1);
 
    $result = curl_exec($ch);
    // Look at the returned header
    $resultArray = curl_getinfo($ch);
 
    curl_close($ch);
 
    if($resultArray['http_code'] == "200"){
         $twitter_status='Your message has been sent!
<a href="http://twitter.com/'.$username.'">See your profile</a>';
    } else {
         $twitter_status="Error posting to Twitter. Retry";
    }
	return $twitter_status;
}
?>