[SOLVED] form post

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

Post Reply
vanceibz
Forum Newbie
Posts: 10
Joined: Sat Jan 14, 2006 6:25 pm

[SOLVED] form post

Post by vanceibz »

hello,
I have a problem with my code, I am trying to post a simple registration form to be processed in another page. The function works fine if the form is in a separate page...
What i have is a form called "signup_form_quick.php" and a processing page called register_quick.php. If call the form and submit it works fine, but if i include using <? include("$CFG->wwwroot/users/signup_quick.php");?> the form in another page in my website and then submit the form it takes me to the signup_form_quick.php. How can i get the form to be processed when submitted from another page.. i know the code at fault and i have a feeling its very simple..please need some help

vance

signup_form_quick.php code:

Code: Select all

<P>(!) Note that all fields are mandatory

<form name="entryform" method="post" action="<?=$CFG->wwwroot?>/register_quick.php">
<table style="font-size:12px; ">
<tr>
	<td class="label">Username</td>
	<td><input type="text" name="username" size="20" value="<? pv($frm["username"]) ?>">
		<?err($errors->username)?>
	</td>
</tr>
<tr>
	<td class="label">Password</td>
	<td><input type="password" name="password" size="20">
		<?err($errors->password)?>
	</td>
</tr>
<tr>
	<td class="label">Email</td>
	<td><input type="text" name="email" size="20" value="<? pv($frm["email"]) ?>">
		<?err($errors->email)?>
	</td>
</tr>

<tr>
	<td></td>
	<td align="right"><input type="submit" value="Signup"></td>
</tr>
</table>
</form></P></div>
register_quick.php code:

Code: Select all

<?
include("../application.php");
if (match_referer() && isset($_POST)) {
	$frm = $_POST;
	$errormsg = validate_form($frm, $errors);

	if (empty($errormsg)) {
		insert_user($frm);

		
		
		redirect("$CFG->wwwroot", "<p style=text-align:center;>registration succesfull! redirect in 3 seconds</p>", 3);
		
		die;
	}
}


include("templates/signup_form_quick.php");

/******************************************************************************
 * FUNCTIONS
 *****************************************************************************/

function validate_form(&$frm, &$errors) {

	$errors = new Object;
	$msg = "";

	if (empty($frm["username"])) {
		$errors->username = true;
		$msg .= "You did not specify a username";
		

	} elseif (username_exists($frm["username"])) {
		$errors->username = true;
		$msg .= "The username <b>" . ov($frm["username"]) ."</b> already exists";
		

	} elseif (empty($frm["password"])) {
		$errors->password = true;
		$msg .= "You did not specify a password";

	} elseif (empty($frm["email"])) {
		$errors->email = true;
		$msg .= "You did not specify your email address";
		
	} elseif (email_exists($frm["email"])) {
		$errors->email = true;
		$msg .= "The email address <b>" . ov($frm["email"]) ."</b> already exists";
		

	} 

	return $msg;
}

function insert_user(&$frm) {
/* add the new user into the database */

	$qid = db_query("
	INSERT INTO users (
		priv, username, password, email
	) VALUES (
        'user'  	
		,'$frm[username]'
		,'" . md5($frm["password"]) ."'
		,'$frm[email]'
		
	)");
}

?>
vanceibz
Forum Newbie
Posts: 10
Joined: Sat Jan 14, 2006 6:25 pm

Post by vanceibz »

its sorted ! :)
Post Reply