Home Techindex PHP Form, PHP guest form

 
 

PHP Form, PHP guest form
Posted on: September 23, 2010 at 12:00 AM
Advertisement
In this section we will develop PHP PHP Form for accepting some information from the guest.

PHP email form

HTML form

It's not a good idea to leave your private e-mail address on your web-site due to impossible activity of spammers. But nevertheless you need some way to get feedback from your visitors. In the three parts of this tutorial I'll tell you in details how to create a mailbox, that would be spam-protected, and will recieve text messages from you visitors. We'll create 2 small PHP files, one would send messages, the other will recieve them and simultaneuously delete them from the server. Realization of this project requires about 2 kbs of space on a server that supports PHP. Despite the fact, that these example files lack any ornamentation of programming or any other nature, they must just work without requiring any additional settings.

Let's create the first file, index.php

<html><head><title>BRIEF MESSAGE</title></head><body><br>
<table width="100%" height="100%"><tr><td align=center><br>
<form action="index.php"><br>
Message:<br><textarea name="mes"></textarea><br><br><br>
<input name="yes" type="hidden" value="1"><br>
<input type="reset" value="Clean"><br>
<input type="submit" value="Send"><br>
</form><br>
<?php
//php-code from the Part 2<br>
?>
<br>
</td></tr></table></body></html>


The first two lines and the last one - are well-known HTML tags with their attributes, their purpose is to place the input form into the center of the screen. The visible part of the form (form) contains a named multi-line input field textarea and two standard controlling buttons - one for clearing the form (reset) and the other for sending the message (submit). Their captions (value) match their purpose. The action attribute of form tag links to itself, so for controlling the php-script, that we'll write in the second part of the tutorial, let's add a hidden field named yes to the tutorial. As we'll see later, what really matters is not it's value, but the fact of it's existence. But in order not to make the variable empty, let's assign it some value, for example, 1.

If you see our new-created file in some browser, you'll see an input field with two buttons in the center of screen. Though that won't work yet.

receiving the message

Let's now examine the code of PHP script that is to be entered into the file that we've created in the fist part of the tutorial. Now let's give names to 2 simple text files, that will be being created and deleted dynamically by our scripts. Let it be n.txt to store the current number of messages, and m.txt - to store their text.

In order for our script to be executed only in return to the sending button (submit) being pressed, let's state the main condition. If a non-empty variable yes is received, then do work. That's how this rule will look from the point of view of PHP interpretation. After pressing Send button, this rule is held automatically.

if (!empty($_GET['yes'])){
//php code
}


Inside this rule we process the pressure of Send button. If there is an input, let's assign the value entered (text) to the $mes variable, or, if no input is made, we quit the script and inform user about it.

if(!empty($_GET['mes']))$mes=($_GET['mes']);else exit("Input message!");

Now let's write a code for the counter file - n.txt

if (!file_exists("n.txt")){//if there is no counter file,
// let's create it, write into it value "1" and close it.
$fp = fopen("n.txt","w+");
fputs($fp,1);
fclose($fp);
$n[0]=1;//it' s the value of the first and the only one lement of the array.
}else{//if there is a counter file,
//let's read it's value to the array $n, add 1 and close the file
$fp = @fopen("n.txt","r+");
$n = file("n.txt");
$n[0]++; // increase the counter onto 1
fputs($fp, $n[0]);
fclose($fp);
}


Now we need only to write down or add the text, that is entered by the user (together with it's number and date/time) from $mes into m.txt file and inform user about it. Of course, the file must be closed afterwards, and the script must be also be completed.

$dat = date("d m y H:i");//enter the variable - current date and time.
$fp = fopen ("m.txt", "a+");
fwrite ($fp, $n[0].". ".$dat."\n".$mes."\n\n");
fclose ($fp);
exit("Your message is accepted.");


The whole PHP code from the first part of the tutorial will look like the following:

if (!empty($_GET['yes'])){
if(!empty($_GET['mes']))$mes=($_GET['mes']);else exit("Input message!");
if (!file_exists("n.txt")){
$fp = fopen("n.txt","w+");
fputs($fp,1);
fclose($fp);
$n[0]=1;
}else{
$fp = @fopen("n.txt","r+");
$n = file("n.txt");
$n[0]++;
fputs($fp, $n[0]);
fclose($fp);
}
$dat = date("d m y H:i");
$fp = fopen ("m.txt", "a+");
fwrite ($fp, $n[0].". ".$dat."\n".$mes."\n\n");
fclose ($fp);
exit("Your message is accepted.");
}
?>

Reading and deleting the message

Let's create a file for reading and deleting messages. We'll call it, for example, read.php. As in the previous file, in this one the first and the last lines create the html-arrangement of a table.

<html><head><title>Read messages</title></head><body>
<table><tr><td>
<?php
//php-code
?>
</td></tr></table></body></html>


The meaning of the php-code listed below is the following. If no messages (the message file does not exist), we finish the script and inform the user about it. If there are messages, we create an array ($n) of m.txt file lines, and string by string, by the means of a loop from 0 up to the array size (count($n)) print the lines out to the screen. Afterwards we delete the n.txt and m.txt files in order to save disk space.

<?php
if (!file_exists("m.txt")){//if there is no message file
    exit("No messages!");
}else{//if there is a message file
//read messages from it into an array $n
$fp=@fopen("m.txt","r+");
$n=@file("m.txt");
fclose($fp);
//create a loop for a line-by-line print out to the screen
for ($i=0; $i<count($n); $i++)
echo $n[$i]."<br>";
unlink("n.txt");//delete the file
unlink("m.txt");//delete the file
exit;//finish the script
}
?>


Now we place both files creates in this lesson - that is, index.php и read.php - into a folder, that is called, for example, antispam, and put the folder onto a PHP-supporting server.

Than the send-message URL will be http://www.name_of_server.domen/antispam/, and read-message URL - http://www.name_of_server.domen/antispam/read.php

Keep in mind, that the information is deleted from the server, and save the received messages on your PC, if you need them.

Just one note. On a UNIX server it may be required for normal work to add a text files' attributes' setting chmod(), and, if the mailbox will be used intensely, a flock() blockage.

 

More Tutorials on roseindia.net for the topic PHP Form, PHP guest form.
PHP Form, PHP guest form
PHP email form HTML form It's not a good idea to leave your private e...'ll create 2 small PHP files, one would send messages, the other... of this project requires about 2 kbs of space on a server that supports PHP. Despite
 
PHP form
PHP form  Hi Sir/Madam, I am developing an attendance form using php, which displays the name and ID of a Employees which are fetched from Db and I... form and update them to respective coloumn... Please any one help mo out please
 
php form post to mysql
php form post to mysql  How to post data into mysql database from the PHP post data form
 
HTML to php form
HTML to php form  Hi, How I can submit the HTML form data to PHP Script? Give me example code. Thanks   Hi, Please see the following tutorials: PHP Form PHP email form Thanks
 
PHP JavaScript form Validation - PHP
PHP JavaScript form Validation  Just looking for a general PHP JavaScript form Validation. How can I write external JavaScript Validation? Please suggest!  Hi Friend, 1) form Enter Name Enter Address
 
php loging form connecitivity with mysql
php loging form connecitivity with mysql  my loging form is not connect
 
PHP Sticky form problem
PHP Sticky form problem  I have done the full coding of a sticky form... Calculator</title> <?php if (isset($_POST['submitted']) &&...;/head> <body> <h1>Simple Calculator</h1> <form action
 
PHP Sticky form problem
PHP Sticky form problem  I have done the full coding of a sticky form... Calculator</title> <?php if (isset($_POST['submitted']) && !isset...> <form action="simple_calculator.php" method="post"> <p>Number 1
 
Custom Form Validation - PHP
Custom Form Validation  Which is the best way or where should I implement the custom validation rules such as ? using number, capital letters and symbols to secure the password
 
php
php  plz tell me code for PHP SQL Insert,delete,update,view is used to insert the record from HTML page to Mysql database using in single PHP form
 
how to post data in mysql php form
how to post data in mysql php form  how to post data in mysql php form
 
how to create a user registration form in php
how to create a user registration form in php  how to create a user registration form in php
 
PHP Form
PHP Form In this tutorial you will learn how to pass any data from a html page to a php file, and how to use all those data. To do this we need at least two files one is html file and a php file. Here's the given example: userForm.html
 
php
php  im beginner to php. i faced problem with creating form and data...;head> <title>Form Input Data</title> </head> <body> <table border="1"> <tr> <td align="center">Form
 
php
php  im beginner to php. i faced problem with creating form and data...;head> <title>Form Input Data</title> </head> <body> <table border="1"> <tr> <td align="center">Form
 
php form having 2 submit buttons
php form having 2 submit buttons  i have a php form and some text boxes.and 2 buttons"approve" and "disapprove". when i click on approve button the data from form should go in mysql database and mail should go to appropiate
 
Multipage form
Multipage form  I have a multipage form in php with 2 pages wnhen i submit the form data from both the pages should go in database how should i pass teh data from 1st page to 2nd page and then put the entire form data in mysql
 
value in div from php, reloading form
value in div from php, reloading form  I am having one form with name... woth other login.php <?php include 'login2.php'; function form($name...; </form> <?php } ?> <?php form('','') ?>
 
Fetch the data from mysql and display it on php form
Fetch the data from mysql and display it on php form  when i press on login button, after succesful login the related data of that person should be display in other textbox
 
PHP MySQL Login Form
Login Form using PHP and MySQL: In any website generally it is mandatory to have a login form to keep your data secure. In this regard we need to have... will study how to create a login form, connect with the database server and login
 
PHP HTML Form
PHP & HTML Form: In the current tutorial we will study about PHP and HTML form, we will see how to send HTML . We will combine one html file and PHP...; <BODY> <form method="get" action="<?php $_SERVER
 
Invoice Form
Invoice Form  How can I create an Invoice web application (preferable PHP) with customer look-up (with option to add new customer) and a grid to add items (search for items) with a total line below the grid. The grid should have
 
How to implement Captcha in PHP Form using GD Library
How to implement Captcha in PHP Form using GD Library  Hi, How to show Captcha in PHP Form. So, please suggest any online reference so that i will try myself. Thanks
 
dynamic form
dynamic form  I need to make a dynamic form using php, for example, i... button wich once clicked we have a new list created on the same form. Thank you very much for your help   Here is a php application that creates
 
PHP : Form to Email
PHP : Form to Email       With the help of this tutorial you can send mails to a user using a form, as we have discussed in our earlier tutorial, it is very easy to send mails using PHP and any
 
PHP Form Part-1
Topic : HTML FORM Part - 1  In this tutorial, we will learn how to deal with Html Form, JavaScript Validation, MySQL Database and PHP Scripts. We... start with Html Form : If you have little bit  knowledge about Html
 
PHP Form Part-2
on PHP, so there are several ways to send the form to another page such as PHP..., if you want send it the form to itself in PHP, there is a popular technique...;  To handle the form data efficiently, we can add some PHP script also
 
How to Create Login/ Registration Form using PHP and MYSQL
How to Create Login/ Registration Form using PHP and MYSQL  Hi, I am learning PHP. I have some dilemma how to create a Login Form and make connectivity with HTML page using PHP and MYSQL. Is there any body can guide me
 
PHP Form Part-5
into our php form to get the result. Let's see the following code : Page : 1... will learn how to deal with radio button in php form.  ...Topic : HTML FORM Part - 5 In the previous parts of this tutorial, we covered
 
pre-populate form
pre-populate form  how to pre populate form in php   what do you mean by pre populate
 
PHP HTML Form Method Attribute
Topic : PHP HTML Form Method Attribute Part - 3 The second attribute in the form tag is Method. With the help of Method attribute, we can tell the browser that how the form information should be sent. Let's see how we used in our form
 
Session management in php - PHP
Session management in php  I am creating a simple program in PHP to manage the session of user. It's basically a simple form that will allow a user to fill & submit the offer form after login. Please Explain me how can i create
 
PHP HTML Form Submit Button
Topic : HTML FORM SUBMIT BUTTON Part - 4 The another part which is important... of the tutorial then our Html form has covered the action and method attribute. So, here we are going to implement these attributes into our form, in which
 
create a simple form
create a simple form  Helo. i am learning php, and i need help creating below for. Its simple but i need help. Create a form that contains: 1. Name, textbox 2. Submit button If the user inputs the Name textbox and clicks
 
php mail
php mail  how to send the submitted form to mail after 24 hours? pls help me
 
PHP FORM Part-8
Topic : HTML FORM While Loop Part - 8 In this part of tutorial, we will learn... is false. The syntax for a while loop in PHP is : initialize = value; ... in a better way : <?php $num = 1; while($num<11
 
connectivity with php
connectivity with php  i have make one html form and doing connectivity with php database but when i click on submit button on html form display all coding in php form about connectivity instead of adding data, i used in html
 
PHP Regular Expression
PHP regular expression allows programmer to perform various task like... expression one can easily validate user form or perform complex manipulations between strings. PHP Regular expression also allows you to validate a email, phone
 
form
form   Can I prevent a form from being submitted again
 
FORM Tag Correctly for Uploading Files.
for Uploading Files? <?php print("<html><form action=file...FORM Tag Correctly for Uploading Files.  How To Write the FORM Tag... is controlled by a properly written <FORM...> tag as: <FORM ACTION
 
PHP FORM Part-10
variable we can store multiple values.  For example of PHP Form Array...Topic : HTML FORM Part - 10: What is an Array  An array is a storage...; array( ); It is enough to tell the PHP that you wanted to set up the array
 
Sending mail (Contact Form in a website)
Sending mail (Contact Form in a website)  Hi, I just uploaded few... pages. Am very much new into this field. I want to write a contact form, which on submit should send the details to my inbox. I heard this can be possible in PHP
 
PHP Question
PHP Question  I am trying to make php Readline where it reads from line 2 and loops to the end. > if (isset($_POST['oldpass'])) { > >... = > @fopen("/home/users/".$username.".txt", > "r"); // Open file form read
 
PHP Question
PHP Question  I am trying to make php Readline where it reads from line 2 and loops to the end. > if (isset($_POST['oldpass'])) { > >... = > @fopen("/home/users/".$username.".txt", > "r"); // Open file form read
 
project on php
project on php   suppose i have five tabels and i must form them html then link them database and php then i want to make query between them these five tabels and data in each one pleaze help me Table of suppliers Source
 
Form for Update Customization.
Form for Update Customization In this example, you will learn to make a update customization form in PHP. The code for customization update will be called on HTML form.  In the following program, we have made a program for updating
 
displaying data for a single column from Mysql database in the list box in php form
displaying data for a single column from Mysql database in the list box in php form  I have a form in php.want to display data from a single column in an listbox in php.thanks..   <?php $data = @mysql_query("select
 
PHP - Ajax
PHP  How can ajax is used in php,plz expalin with example.  ...-Type', 'application/x-www-form-urlencoded'); xmlHttp.onreadystatechange... the current date and time from server and shows on the form. To view
 
Sitemap PHP Tutorial
| XML Expat Library | PHP : Form to Email | Create your Email Server... Form | PHP MySQLI Prep Statement... Questions | Site Map | Business Software Services India PHP Tutorial
 
PHP Variables Form
PHP Variables Form If you want to use one variable into multiple pages you... :( login.php) <html> <head> <title>PHP Variables Form</title> </head> <body> <form action="welcome.php"
 
Advertisement

Related Tags for PHP Form, PHP guest form:


Advertisements Advertisements
 

 

 

DMCA.com