Thursday, November 20, 2008

Submit form on same page using AJAX

http://www.simonerodriguez.com/ajax-form-submit-example/

An easy way to send a form without reloading the page. Build the form tag in the same way the example do.

1. In the head section () add the reference to the JS script:
http://www.simonerodriguez.com/ajax-form-submit-example/js/ajaxsbmt.js

2. In the form tag () add the event onsubmit and the call to xmlhttpPost function:

* The first parameter (response_ajax.asp) is the page the will receive the data.
* The second parameter (MyForm) is the NAME of the form.
* The third parameter (MyResult) is the ID of the DIV that will display the "wait message" and the form response.
* The forth parameter () is the waiting message (should be also HTML code)

3. Manage the received data like a normal form

Source Code (Form sender page):





Source Code (Form sender page):

<script src="js/ajaxsbmt.js" type="text/javascript"></script> <form name="MyForm" action="response_normal.asp" method="post" onsubmit="xmlhttpPost('response_ajax.asp', 'MyForm', 'MyResult', '<img src=\'pleasewait.gif\'>'); return false;"> <input name="sample_text" type="text" value="Test Text" /> <br /> <label> <textarea name="textarea" id="textarea" cols="45" rows="5">Test Textarea</textarea> </label> <label> <br /> <input name="checkbox" type="checkbox" id="checkbox" value="True" /> </label> <br /> <input type="radio" name="radio" value="radio1" /> <input type="radio" name="radio" value="radio2" /> <input type="radio" name="radio" value="radio3" /> <br /> <select name="List"> <option value="a">a</option> <option value="b">b</option> <option value="c">c</option> </select> <br /> <input name="send_button" type="submit" value="Send" /> </form> <div id="MyResult"></div>

Monday, October 20, 2008

Php script to hide relative path

1st option:
<?
$content_len=@filesize("file.zip");
Header("Content-type: application/zip");
Header("Content-type: octet-stream");
Header('Content-Disposition: attachment; filename="file.zip"');
if($content_len!=FALSE)
{
Header("Content-length: $content_len");
}
readfile("file.zip");
?>

2nd option:
<?
$files="servicesellersmasterscourse.zip";
$filenames="servicesellersmasterscourse.zip";
$url= "/www/download/";
$total=$url . $files;
Header ( "Content-Type: application/octet-stream");
Header ( "Content-Length: ".filesize($total));
Header( "Content-Disposition: attachment; filename=$filenames");
readfile($total);
?>

Saturday, October 18, 2008

Add form to website

Form is one of the basic elements to make a website interactive. It is used to received information from user. The information could be comment, contact details, query, order form etc.

A simplest form application will have atleast 2 parts – the form and the form processing script.

Form is developed in HTML. If you like someone’s form or the form element then you can simply view source of the page and can copy and the form or the form element and paste it in your page. Some complex forms are developed using server side scripting language. But the output is sent to client in HTML format.

Form data is sent to server as visitor clicks the submit button. On server we have a form processing page which processes the data. The path and name of the processing page is specified in the action tag of form. We can do any processing on the data like saving it to database or simply mailed to you on your email account.

The simple and very common use of form is on “contact us” page. I had already posted script to process contact us page. You can find it at: http://techutility.blogspot.com/2008/10/php-code-to-mail-form-content.html. This script will mail all the visitor’s filled information to you. Just create a file named process.php and paste the code into it. Edit the code and add your email ID. On form put process.php in the action field.

Use small forms on your website to get visitor’s comment. Don’t forget ever to reply to their queries.

If you face any problem in implementing form then contact me.

Thursday, October 16, 2008

PHP form processing script

The script sends all the data filled in the form on your website to your specified email id. The good thing about the script is that you didn't have to check the field names and add individually. The script takes all the variable and send to you with the field name you had put in the form. So, it is good to put meaningful field names.



<?php

$body = "*************************************************************************\n";



foreach($_POST as $i => $value){
if($i != 'B1_x' && $i != 'B1_y'){
$body .= "$i: ".stripslashes($value)."\n";
}
}


$body.="\n";
$body.="\nUSER AGENT: ".$_SERVER['HTTP_USER_AGENT'];
$body.="\nDATE: ".date("l dS of F Y h:i:s A");
$body.="\nComment for ".$_SERVER['HTTP_REFERER'];

$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "X-Priority: 1\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: excelsolutions.biz <> \n";
$headers .= "Reply-To: valid_id@yourdomain.com";


if(!$form_name) $form_name = "Page Feedback";

// $to = "valid_id@yourdomainname.com";
$to = "valid_id@yourdomainname.com";
$subject = $form_name;
mail($to, $subject, $body, $headers)

?>