PHP scripts and programs for Beginner to Master

php programs, php ready to use scripts & functions, css tutorials, html, javascripts, ajax examples for Beginner to Master

At many places we require the contact us or feedback form to get some input from the user or to get some feedback from the user.
Today i will be showing you how to create a very simple feedback form or contact us form in php with the mail function and without any database.

1) First we will be creating a simple form to accept the user input like name, email and their message or feedback or query.





















Name : "/>
Email : "/>
Message :
 





2) In the form tag we have not specified any action part and we kept action="" in the form tag, so when the form is submitted at that time it will call itself.
So on submit we will execute our code to send the mail.





3) some css for the form and good look.

.textbox,.textarea {
width:300px;
border:solid 2px #00CCFF;
padding:3px;
margin:10px;
}
.error {
background: #FBBFDC;
color:#EF013D;
border:solid 1px;
padding:5px;
margin:5px;
}


4) After the page is submitted we will process the form data.



5) When the form is filled then we will be calling a function sendmail.



Finally, merge all the code to create a simple contact us form or feedback form.
Full source code is here for your reference



.textbox,.textarea {
width:300px;
border:solid 2px #00CCFF;
padding:3px;
margin:10px;
}
.error {
background: #FBBFDC;
color:#EF013D;
border:solid 1px;
padding:5px;
margin:5px;
}




















Name : "/>
Email : "/>
Message :
 



if(isset($_POST["Submit"]))
{
$email = $_POST["email"];
$msg = $_POST["message"];
$username = $_POST["name"];
if($username!="" and $email!="" and $msg!="")
{
sendmail($username,$email,"",$msg,"");
}
else
{
echo "
Fill all the fields ! Thank you.
";
}
}
function sendmail($username,$email,$data,$msg,$footer)
{
$to="youremailidhere";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
//$headers .= "From: ".$from."\r\n";
$headers .= "From: $username <$email>\r\n";
$headers .= "Reply-To: youremailidhere\r\n";

$body="

Dear Admin,

";
$body.="

Message from : $username

";
$body.="

Email id : $email

";
$body.="

Message : $msg

";

$body.="Feedback end

";

if(@mail($to,'feedback from http://programming-in-php.blogspot.com',$body,$headers))
{
echo "Thank you for your valuable feedback !";
}
else
{
echo "
Can't send email ! ! !
";
}
}
?>

This part is for Horizontal Menu using CSS.

The below one will come under the Head Tag.


The below one will come under Body Tag.



This code was taken from http://www.w3schools.com/css/tryit.asp?filename=trycss_float5

Sometimes we require that when the users click on a textarea at that time all the text should get selected.
This can be done with a small javascript.







When a user clicks on a textarea then all the contents will get selected.

Hi guys,

Generally we require that all the contents of our website should be centered to display the website properly.
For this we can make use of this code so that your website will be in the center of the browser, doesnt matter what is the resolution.

We will create a div with id "outer-div" in the body tag of our webpage.




Now we will apply a CSS styling to the "outer-div" div.




The full code to test is here

Hello,
Today we will be seeing a javascript which will help us to show how many characters are remaining for a textbox or textarea,As soon as the user starts typing in a textbox or textarea, then we will show how many characters are remaining for entering into the textbox.

Here we are creating a simple textbox, and we are specifying the "maxlength" of the textbox to 20.





And "onKeyUp" event of the textbox we are calling a javascript function "countCharacters()".

we will be writing a standard function which accepts only some parameters and rest of the processing will be done in the function.

To this function we have to pass 3 parameters
1) id of the span - where counter will be shown when user types something
2) max_chars - length of the textarea which we specified in maxlength="20"
3) myelement - the id of the textbox where user types text

The function is as below





Now you can use this function anywhere, without a need to modify this function.

The full code to try out is here



Put a link back to our site, if you like this !

Hi,

Today i will be showing you how to create a simple 1 level vertical navigation menu with the help of css.
It is very easy and same like the 1 level horizontal navigation menu.

So lets start,

For this we will be using one image


first we will create a simple code to display "unordered list" with ul and li 





So now our display of the ul will be like this



Now we will apply our css to this ul



After applying this css our menu will look like this



Full code of the vertical menu with css is as, just copy and paste it, and modify links and its over.



Hi friends,

here is a simple example of 1 level horizontal navigation menu.
for this i am using 2 images - one is orange and another is blue

you can copy these images from here 


For creating a "1 level horizontal navigation menu" we are going to use "unordered list"




Now this will create an unordered list.





Now we will apply a CSS to this unordered list to make it a horizontal navigation menu.




Hey ! Its ready ! See it !





Completed ready use script and code is here

We always require some kind of login box for any system which has members.

Here i will be showing a simple example with the help of CSS and HTML to create a attractive login box.

To begin with We will create a login box first and then apply the CSS to it

Replace "youfilename.php" with your script which has the logic to check the login.





When you will add this code to your login file then display will be like this - fully stretched on the page with a simple look.

Now we will add a css to this login box to make it look nice.





Now after applying this css see at our login box.



Now combining all together we have created a very simple nice looking login box without using any other images.
Full source code is given below. Just copy and paste it in your project, if necessary just modify the css.