Page 1 of 1
Registration
Posted: Tue Jun 05, 2007 2:48 am
by kpraman
I am making a registration form. I have to follwing file structure.
1. register1.php - it contails all the html and html tags (getting from a class file).
example,
Code: Select all
<?php
require_once('../includes/html.php');
$db=new HTML;
?>
<form name="form1" method="post" action="../index.php">
<table width="33%" border="1" align="center">
<tr>
<td colspan="2"><div align="center">Account Information </div></td>
</tr>
<tr>
<td width="51%">Email Address</td>
<td width="49%"><?=$tag=$db->Text('username', 'username');?></td>
I want to handle all the actions in a class file. This is how it is,
Code: Select all
class Register
{
function Register1()
{
if(empty($_POST))
header('Location: html/register1.php');
}
function PostedData($)
{
}
}
$display=new Register;
$display=$display->Register1();
How do i get the posted data?
Posted: Tue Jun 05, 2007 8:17 am
by superdezign
$_POST.
Posted: Tue Jun 05, 2007 8:55 am
by kpraman
Code: Select all
$mistake=$register->Validate($_POST);
if(!empty($mistake)) $register->submit($_POST);
its working fine.
I have made html and php pages seperately. In the php file,
Code: Select all
ob_start();
require_once('includes/html.php');
require_once('includes/db.php');
class Register extends html
{
function Register1()
{
if(empty($_POST))
header('Location: html/register1.php');
}
function Validate($data)
{
$mistake=array();
if(empty($data['lastname'])) array_push($mistake,'Last Name is invalid');
if(!empty($mistake))
$mistake=$this->MistakeTable($mistake);
return $mistake;
}
function Submit($data)
{
DbConnect::Submit($data);
}
}
$display=new Register;
$display->Register1();
ob_end_flush();
The HTML page - saved as .php,
Code: Select all
<?php
require_once('../includes/html.php');
require_once('../index.php');
$tag=new Html;
$register=new Register;
$mistake=$register->Validate($_POST);
if(!empty($mistake)) $register->submit($_POST);
?>
<form name="form1" method="post" action="">
<table width="33%" border="1" align="center">
<tr>
<td colspan="2"><div align="center">Account Information </div></td>
</tr>
<tr>
<td width="51%">Email Address</td>
<td width="49%"><?=$tag->Text('email', $email);?></td>
</tr>
<tr>
<td>Last Name</td>
<td><?=$tag->Text('lastname', $lastname);?></td>
</tr>
<tr>
<td>First Name</td>
<td><?=$tag->Text('firstname', $firstname);?></td>
</tr>
<tr>
<td>User Name</td>
<td><?=$tag->Text('username', $username);?></td>
</tr>
<tr>
<td>Password</td>
<td><?=$tag->Password('password', $password);?></td>
</tr>
<tr>
<td>Confirm Password</td>
<td><?=$tag->Password('cpassword', $cpassword);?></td>
</tr>
<tr>
<td>Contact number1</td>
<td><?=$tag->Text('contact1', $contact1);?></td>
</tr>
<tr>
<td>Contact number2</td>
<td><?=$tag->Text('contact2', $contact2);?></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="submit"></td>
</tr>
</table>
</form>
The index file redirects to html/register1.php. The siteurl changes to ../html/register1.php. - How do i solve it without redirecting the page. I tried to readthe file and display in the index file itself, but on displaying the tags were not appearing, instead plain texts (codes) were displayed. Another thing is i am getting Warning: Cannot modify header information - headers already sent
Posted: Tue Jun 05, 2007 10:18 am
by superdezign
For simple form use, you shouldn't need redirection.
When $_POST is empty, it's just empty. They are automatically sent to the page you're posting to. No redirection is needed there.