CSS to align label and input

by in , 0

HTML Code Snippet:
<fieldset id="o-bs-sum-buginfo">
  <label for="o-bs-sum-bug-ErrorPrefix">Error Prefix</label>
  <input type="text" id="o-bs-sum-bug-ErrorPrefix" name="ErrorPrefix" value="" />

  <label for="o-bs-sum-bug-ErrorNumber">Error Number</label>
  <input type="text" id="o-bs-sum-bug-ErrorNumber" name="ErrorNumber" value="" />
Using only CSS (or jquery), irrespective of the browser size, I want to pair label and input elements next to each other. I also do have freedom to change tweak the HTML. if required.

Put the every label with its corresponding input into a p tag. Then add the following css:
  width:100px; //whatever width that suits your needs

    margin:10px 0; //manipulate the vertical spaces for each input..  

<fieldset >
    <label for="o-bs-sum-bug-ErrorPrefix">Error Prefix</label>
    <input type="text"  name="ErrorPrefix" value="" />

jquery disable form submit on enter

by in , 0

You can disable button on Submit but user can Enter to submit.

So you i use this code:

I have the following javascript in my page which does not seem to be working.
$('form').bind("keypress", function(e) {
  if (e.keyCode == 13) {               
    return false;
I'd like to disable submitting the form on enter, or better yet, to call my ajax form submit. Either solution is acceptable but the code I'm including above does not prevent the form from submitting.


jquery disable form submit on enter

Usually form is submitted on Enter when you have focus on input elements.
We can disable Enter press on input elements within a form:
$("form :input").on("keypress", function(e) {
    return e.keyCode != 13;

Get Remote file size without downloading file

by 0

Is there a way to get the size of a remote file http://my_url/my_file.txt without downloading the file?


Found something about this :
Here's the best way (that I've found) to get the size of a remote file. Note that HEAD requests don't get the actual body of the request, they just retrieve the headers. So making a HEAD request to a resource that is 100MB will take the same amount of time as a HEAD request to a resource that is 1KB.
<?php/** * Returns the size of a file without downloading it, or -1 if the file * size could not be determined. * * @param $url - The location of the remote file to download. Cannot * be null or empty. * * @return The size of the file referenced by $url, or -1 if the size * could not be determined. */function curl_get_file_size( $url ) {  // Assume failure.  $result = -1;  $curl = curl_init( $url );  // Issue a HEAD request and follow any redirects.  curl_setopt( $curl, CURLOPT_NOBODY, true );  curl_setopt( $curl, CURLOPT_HEADER, true );  curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );  curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );  curl_setopt( $curl, CURLOPT_USERAGENT, get_user_agent_string() );  $data = curl_exec( $curl );  curl_close( $curl );  if( $data ) {    $content_length = "unknown";    $status = "unknown";    if( preg_match( "/^HTTP\/1\.[01] (\d\d\d)/", $data, $matches ) ) {      $status = (int)$matches[1];    }    if( preg_match( "/Content-Length: (\d+)/", $data, $matches ) ) {      $content_length = (int)$matches[1];    }    // http://en.wikipedia.org/wiki/List_of_HTTP_status_c...     if( $status == 200 || ($status > 300 && $status <= 308) ) {      $result = $content_length;    }  }  return $result;}?>
$file_size = curl_get_file_size( "http://abc.com/questions/2602612/php-remote-file-size-without-downloading-file" );

PHP: Remote file size without downloading file

Prevent multiple inserts when submitting a form in PHP

by in 0

Sometimes the user may press Enter twice, and the post is inserted twice.

Is there a solution to prevent this other than check if there is already a post with the same title and content?

1- Use JavaScript to stop it from sending

2 - disable the submit button once the user has submitted the form, using JavaScript. That is what, for example
3 - Include a unique token on each POST worked for me. However, my form still submits when a user refreshes the page (F5). I managed to solve this by adding a reset:
            // reset session token
            $_SESSION['token'] = md5( $_POST['token'] . time() );
my final scripts goes like:
if (isset($_SESSION['token'])) {
    if (isset($_POST['token'])) {
        if ($_POST['token'] != $_SESSION['token']) {
            echo '<h3>Oops! You already submitted this request.</h3>';
        } else {
            // process form
            // reset session token
            $_SESSION['token'] = md5( $_POST['token'] . time() );
    } else {
        echo 'post token not set';
        $_SESSION['token'] = md5( $somevariable . time() );
oh! don't forget to add session_start(); before <!DOCTYPE>
I am a PHP newbie so please correct me if you find irregularities.

How to prevent multiple inserts when submitting a form in PHP?

Remove URL from string PHP

by in 0

f I have a string that contains a url (for examples sake, we'll call it $url) such as;

$url = "Here is a funny site http://www.tunyurl.com/34934";
How do i remove the URL from the string? Difficulty is, urls might also show up without the http://, such as ;
$url = "Here is another funny site www.tinyurl.com/55555";

There is no HTML present. How would i start a search if http or www exists, then remove the text/numbers/symbols until the first space?


function containsTLD($string) {
  $has_tld = (count($M) > 0) ? true : false;
  return $has_tld;

function cleaner($url) {
  $U = explode(' ',$url);

  $W =array();
  foreach ($U as $k => $u) {
    if (stristr($u,".")) { //only preg_match if there is a dot    
      if (containsTLD($u) === true) {
      return cleaner( implode(' ',$U));
  return implode(' ',$U);

$url = "Here is another funny site badurl.badone somesite.ca/worse.jpg but this badsite.com www.tinyurl.com/55555 and http://www.tinyurl.com/55555 and img.hostingsite.com/badpic.jpg";
echo "Cleaned: " . cleaner($url);

Cleaned: Here is another funny site badurl.badone but this and and

Free Music player for website, blogger

by in , 0

Ketnooi Music release Free new Music player for Webmasters.
You can embed K-Player to your blog, blogspot easily.
Demo see this blog
- Free music/Video for your vistors
- Easy to embed
- Light speed
- Integrate with any website, blog.
- Music is not breakable even if vistor go to new page

Just go to Video.Ketnooi.com, then create your own playlist, Save it, then get embed Code
Have fun!

javascript replace only first instance .replace?

by in 0

I have this
 var date = $('#Date').val();
this get the value in the textbox what would look like this
Now I do this on it
var id = 'c_' + date.replace("/", '');
and the result is
It misses the last '/' I don't understand why though.

Read more »