- Forums
- PHP
- How To Crate A Dynamic Form With PHP Scripts Tutorial By Example Code
This Page Contains information about How To Crate A Dynamic Form With PHP Scripts Tutorial By Example Code By webmaster in category PHP with 14 Replies. [989], Last Updated: Sat May 18, 2024
webmaster
Tue Dec 05, 2006
14 Comments
10913 Visits
A greate thing about PHP is ability to display dynamic content to web pages. If you don't already have PHP hosting, please visit our friends at www.webune.com they have great PHP hosting.
One way to create interactive web pages is to ask for user input. The way to get the information from a user is through a web form. once the user submits the information, it then process (by PHP) and depending on what process you have programmed, it displays the results.
In my example, i will be asking for a user's name, once the user submits their name, i will display a friendly rely with their name.
for example, the page will ask for the user to enter their name, and when they submit the form, the form will be process and depending on what the user submits, it will give a message like: Hi username! PHP is great!
So here is the code to make it happen:
1. copy and paste the following code into your editor, you can use notepad i f you don't have a web editor:
CODE:
<?php
#############################################################
############# TUTORIAL BY Wallpaperama.com #########
#############################################################
function form($prompt){ ?>
<form action="<?php $_SERVER['REQUEST_URI']; ?>" method="post">
<p><?php echo $prompt; ?>
<input name="user_name" type="text" size="25"><br /><br />
<input type="submit" name="submit" value="Submit">
</p>
</form>
<?
return;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Creating Dynamic PHP Pages with Form By Wallpaperama.com</title>
</head>
<body>
<h1 align="center">Dynamic Form Tutorial by <a href="http://www.wallpaperama.com">Wallpaperama.com</a></h1><hr />
<?php
if($_POST['submit']) {
if($_POST['user_name']) {
echo '<h1 align="center">Hi '.$_POST['user_name'].', PHP is Great!!</h1><br /><div align="center"><a href="'. $_SERVER['REQUEST_URI'].'">Try Again</a></div>';
}
else {
echo form('<strong style="color:#FF0000">ERROR: Please Provide A Name</strong>');
}
}
else {
echo form("Please enter your name:");
}
?>
<div align="center">
<p align="left"><a href="http://www.wallpaperama.com/forums/how-to-crate-a-dynamic-form-with-php-scripts-tutorial-by-example-code-t565.html"><< Go Back To Forums</a></p>
<p align="left"> </p>
<p align="left">If you have found this simple and short tutorial helpful, we would like to ask you to please link to our website at <a href="http://www.wallpaperama.com">http://www.wallpaperama.com</a> by linking to Wallpaperama you will help us make tutorials like this one more easier to find by others who are looking for answers like this one. Thank You - Wallpaperama Team. </p>
<p>hosting provided by <a href="http://www.webune.com">Webune</a></p>
</div>
</body>
</html>
2. Next you want to save this file as dynamic-php-form-tutorial.php and uploaded to your site and open it with your browser, if you have PHP in your hosting, you should see a page like our demo below, otherwise, you many not have PHP in you hosting plan, if you don't you can visit our friends at www.webune.com and sign up for a PHP hosting pacakage.
[url=http://www.wallpaperama.com/tutorials/dynamic-php-form-tutorial.php]CLICK HERE FOR DEMO[/url]
IF you've found this tutorial helpful, we would appreciate a link back to wallpaperama from your home page.
Thank You
Wallpaperama Team