PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
jknoxy
Forum Newbie
Posts: 1 Joined: Wed May 20, 2009 6:37 am
Post
by jknoxy » Wed May 20, 2009 6:39 am
Hey, New to HTML and especially PHP!
I have been given the PHP file as follows:
Code:
Code: Select all
<body>
<?php
echo "<pre>";
print_r($_GET);
echo "<pre>";
?>
</body>
I have to create any form elements i want and be able to submit them to this PHP file! How can i do this i have created my form i just need to tranfer the details over! exmaple of a part of the form:
Code:
Code: Select all
<form name = "InvoiceForm" id = "InvoiceForm" action="reflect.php" method="get">
Please Enter your details in the relavent boxes below:<br/><br/>
<label for = "UserName">UserName:<br/>
<input type="text" name = "UserName" id = "UserName" class = "FormSelect"/></label><br/><br/>
<label for ="FirstName">First Name(s):<br/>
<input type="text" name = "FirstName" id = "FirstName" class = "FormSelect"/></label><br/><br/>
<label for = "LastName">Last Name:<br/>
<input type="text" name = "LastName" id = "LastName" class = "FormSelect"/></label><br/><br/>
<label for = "Address">Address:<br/>
<textarea name="Address" id="FormAddress" class = "FormSelect" rows = "5" cols = "2">
</textarea></label><br/><br/>
<label for = "Email">E-mail:<br/>
<input type="text" name = "Email" id = "Email" class = "FormSelect"/></label><br/><br/>
<label for = "Telephone">Telephone Number:<br/>
<input type="text" name = "Telephone" id = "Telephone" class = "FormSelect"/></label><br/><br/>
<input type="submit" name="Submit" value="Submit"/>
</form>
Thanks
Last edited by
Benjamin on Wed May 20, 2009 8:04 am, edited 1 time in total.
Reason: Changed code type from text to html, php.
tahsinz
Forum Newbie
Posts: 4 Joined: Mon May 18, 2009 12:19 am
Post
by tahsinz » Wed May 20, 2009 11:10 pm
hi jknoxy,
You need to use method post for retrieving the form elements. A sample code is provided.
Code: Select all
<form action="index.php?module=profile&category=create&op=new" method="post">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" class="data_header"><div align="center" >Create New User </div></td>
</tr>
<tr>
<td width="8%"> </td>
<td width="22%"> </td>
<td width="70%"> </td>
</tr>
<tr>
<td height="22"> </td>
<td height="22"><div align="left"><strong>Username :</strong></div></td>
<td height="22"><input name="user_name" type="text" class="textbox" id="user_name" size="20"></td>
</tr>
<tr>
<td height="22"> </td>
<td height="22"><div align="left"><strong>Password :</strong></div></td>
<td height="22"><input name="password" type="password" class="textbox" id="password" size="20"></td>
</tr>
<tr>
<td height="22"> </td>
<td height="22"><div align="left"><strong>Name : </strong></div></td>
<td height="22"><input name="name" type="text" class="textbox" id="name" size="40"></td>
</tr>
<tr>
<td height="22"> </td>
<td height="22"><div align="left"><strong>Company : </strong></div></td>
<td height="22"><input name="company" type="text" class="textbox" id="company" size="40"></td>
</tr>
<tr>
<td height="22"> </td>
<td height="22"><div align="left"><strong>Address : </strong></div></td>
<td height="22"><input name="address" type="text" class="textbox" id="address" size="40"></td>
</tr>
<tr>
<td height="22"> </td>
<td height="22"><div align="left"><strong>Email : </strong></div></td>
<td height="22"><input name="email" type="text" class="textbox" id="email" size="30"></td>
</tr>
<tr>
<td height="22"> </td>
<td height="22"><div align="left"><strong>Phone : </strong></div></td>
<td height="22"><input name="phone" type="text" class="textbox" id="phone" size="30"></td>
</tr>
<tr>
<td height="22"> </td>
<td height="22"><strong>Domain : </strong></td>
<td height="22"><input name="domain" type="text" class="textbox" id="domain" size="30"></td>
</tr>
<tr>
<td height="22"> </td>
<td height="22"><div align="left"><strong>Product : </strong></div></td>
<td height="22"><select name="product" id="product" class="push_button">
<option value="Domain Register">Domain Register</option>
<option value="Starter">Starter</option>
<option value="Mini-Pro">Mini-Pro</option>
<option value="Pro">Pro</option>
<option value="Corporate">Corporate</option>
<option value="Mini-Studio">Mini-Studio</option>
<option value="Studio Gigs">Studio Gigs</option>
</select></td>
</tr>
<tr>
<td height="22"> </td>
<td height="22"><div align="left"><strong>Type : </strong></div></td>
<td height="22"><select name="type" id="type" class="push_button">
<option value="0">Customer</option>
<option value="1">Administrator</option>
</select></td>
</tr>
<tr>
<td height="22"> </td>
<td height="22"><div align="left"><strong>Validity Date : </strong></div></td>
<td height="22"><input name="validitydate" type="text" class="textbox" id="validitydate" size="30"></td>
</tr>
<tr>
<td height="22"> </td>
<td height="22"><div align="left"><strong> Theme : </strong></div></td>
<td height="22"><? echo populate_theme_list();?></td>
</tr>
<tr>
<td> </td>
<td><div align="left"></div></td>
<td></td>
</tr>
<tr>
<td> </td>
<td><div align="center"></div></td>
<td><input type="submit" name="Submit" value="Create User" class="push_button">
<input class="push_button" name="Reset" type="reset" id="Reset" value="Reset">
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
In order to process the form element, you need to get it through $_POST[element_name]. I hope the below code with help you.
Code: Select all
<?
if($_GET['op'] == "new")
{
$user_name=$_POST['user_name'];
if(validate_username($user_name))
{
$name=$_POST['name'];
$company=$_POST['company'];
$email=$_POST['email'];
$password=$_POST['password'];
$phone=$_POST['phone'];
$address=$_POST['address'];
$theme=$_POST['theme'];
$product=$_POST['product'];
$type=$_POST['type'];
$domain=$_POST['domain'];
$validitydate=$_POST['validitydate'];
}
?>
NOTE: validate_username($user_name) is a user made function.
with regards,
Tahsin
Last edited by
Benjamin on Thu May 21, 2009 8:35 am, edited 1 time in total.
Reason: Changed code type from text to php.