Archive for the 'JavaScript' Category

Form Submit in different way

Tuesday, September 19th, 2006

Few days ago i was working on a pager script where i have to submit a form manually to send a page. But due to user requirements thats need to send in delay and i was about to use CRON job for that. But this time i was in deep problem to send that page. I was using CURL, fsockopen and many others way to submit the form but none of those works for unknown reason. It was really a funny problem but at least i solved that.

Here i want to discuss about the different way to submit a form.

Traditional Form Submit:
This is the most common form uses everywhere.

< form action="targetpage.php" name="myForm">
[form elements]
< input type="submit" value="send" name="send" />
< /form >

JavaScript Form Submit:

You can call a javascript function at any event for example onClick at button or OnChange at combo box and so on. And inside your javascript just write the line above.

document.myForm.submit();

CURL Form Submit:
This technique is rarely used in our application but we can submit any form using CURL just like normal form. Here is an example :

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url); // set the post-to url
curl_setopt ($ch, CURLOPT_HEADER, 1); // Header control
curl_setopt ($ch, CURLOPT_POST, 1); // tell it to make a POST, not a GET
curl_setopt ($ch, CURLOPT_POSTFIELDS, urlencode($queryString));
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$response = curl_exec($ch);
curl_close ($ch);

FSOCKOPEN Form Submit:

This is also rarely used in our general application. For the Internet domain, it will open a TCP socket connection to hostname on port port. hostname may in this case be either a fully qualified domain name or an IP address. Here is a sample code:

$method =”GET” ; // POST or GET define here
$fp = fsockopen($host,80);
if ($method == ‘GET’)
$path .= ‘?’ . $data;
fputs($fp, “$method $path HTTP/1.1\n”);
fputs($fp, “Host: $host\n”);
fputs($fp, “Content-type: application/x-www-form-urlencoded\n”);
fputs($fp, “Content-length: ” . strlen($data) . “\n”);
fputs($fp, “User-Agent: MSIE\n”);
fputs($fp, “Connection: close\n\n”);
if ($method == ‘POST’)
fputs($fp, $data);

while (!feof($fp))
$buf .= fgets($fp,128);
fclose($fp);
return $buf;

AJAX Form Submit:

At any AJAX application we frequently use such code.

var http_request = false;
url ="myformactionpage.php";
parameters ="field1=val1&field2=val2";
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
` http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}

http_request.onreadystatechange = alertContents;
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);

Share your tought if you find any others way to submit a html form.

Enjoy PHPing......

Javascript Flash Player detection and embed script

Thursday, July 13th, 2006

Few days ago when i was validating a site for W3 Standard and i was fixing error one by one. I saw that the < object > tag doesnt support W3 standard . And i was in deep trouble to fix those problem . But at least i got a Javascript thats detect flash player and helps me from removing that bugs.

this is very easy to use and configure. You just have to include a JS file and put the following line :

[For the further help, you can view the raw javascript here.]

Javascript Code ::

------------------
var so = new SWFObject("movie.swf", "mymovie", "200", "100%", "7", "#336699");
so.addParam("quality", "low");
so.addParam("wmode", "transparent");
so.addParam("salign", "t");
so.write("flashcontent");
---------

Here You can find the details about it . http://blog.deconcept.com/swfobject/

I really loved it !!!!

Lightbox Image Effect

Tuesday, June 20th, 2006

Lightbox JS is a simple, unobtrusive script used to overlay images on the current page. It’s a snap to setup and works on all modern browsers.This is very usefull tools for those application where need to show thumbnail and as well as large images. When you’l click on image it will disable the parent window and shows a preloader while loading the image with a nice effect. Its an eye catching effect !!!!

Example of LightbOx

lightbox example
Lets download it and build your own image effect !!

Javascript Color Picker

Tuesday, June 20th, 2006

There is a cool javascript color picker ! You can generate colors by dragging RGB color’s scroll bar or you can enter the Hex code or RGB color code to see its exact color . See the Javascript’s magic !!!!!

click here