Tutorial: Creating multiple objects on Customer registration

Michael_S
Senior Member
Beiträge: 160
Registriert: Mi 4. Feb 2004, 02:39
Wohnort: London / UK
Kontaktdaten:

Tutorial: Creating multiple objects on Customer registration

Beitragvon Michael_S » Mo 5. Jul 2010, 22:38

I'm not sure if this is the best place but this may be helpful for people looking at the DB/Object Module. I'm working on a project where I wanted to create multiple objects at the same time when a customer registers. Each customer would have a single object for each class. This sound relatively easy however the documentation is lean and the interesting forum posts are in German so it makes it hard work, also if you are not careful the script could generate multiple objects of the same class which is exactly what I'm avoiding.

The following code will allow you to create 2 objects of different classes at the same time a customer registers, to allow the template to work you will need to create 2 classes each with a field named 'WebUserID'. Your registration page must be dynamic (php).

Code: Alles auswählen

<?php // Start the web user session ?>
<we:sessionStart />
<?php // Save the web user on sign-up ?>
<we:saveRegisteredUser />

<?php // If the sign-up was successful execute the following code  ?>
<we:ifRegisteredUser>

<?php // Create a condition to compare the web users ID with a field in the database object ?> 
<we:condition name="condition">
	<we:conditionAdd field="WebUserID" compare="=" var="ID" type="sessionfield" />
</we:condition>

<?php // Check to see if a database object already exists for the web user ?>
<we:listview type="object" name="Profile1" rows="1" classid="16" condition="\$condition">
<we:ifNotFound>
<?php // If not found create the database object ?>
<we:write type="object" formname="signup" publish="true" classid="16" userid="WebUserID" />
</we:ifNotFound>
</we:listview>

<?php // Check to see if a database object already exists for the web user ?>
<we:listview type="object" name="Profile2" rows="1" classid="17" condition="\$condition">
<we:ifNotFound>
<?php // If not found create the database object ?>
<we:write type="object" formname="signup" publish="true" classid="17" userid="WebUserID" />
</we:ifNotFound>
</we:listview>

</we:ifRegisteredUser>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<we:title></we:title>
	<we:description/>
	<we:keywords/>
	<we:charset defined="UTF-8">UTF-8</we:charset>
	<style type="text/css">
		body { font-family: sans-serif; }
	</style>
</head>
<body>

<we:ifNotRegisteredUser>

<?php // Registration form ?>
<we:form type="object" id="self" name="signup" method="post" classid="16" enctype="multipart/form-data">
	<we:sessionField type="hidden" name="ID" />
	<p><label for="Username">User name:</label><br />
	<we:sessionField name="Username" id="Username" type="textinput" xml="true" /></p>
	<p><label for="Password">Password:</label><br />
	<we:sessionField name="Password" id="Password" type="password" xml="true" /></p>
	<p><input type="submit" value="Sign-up" /></p>
</we:form>

<hr />

<?php // Login form ?>
<we:form name="login" id="self" method="post" xml="true">
	<we:ifLoginFailed>
	<p><strong>The login has failed. Please try again.</strong></p>
	</we:ifLoginFailed>
	<p><label for="Username">User name:</label><br />
	<we:sessionField name="Username" id="Username" type="textinput" xml="true" /></p>
	<p><label for="Password">Password:</label><br />
	<we:sessionField name="Password" id="Password" type="password" xml="true" /></p>
	<p><input type="submit" value="Login" /></p>
</we:form>

<hr />

</we:ifNotRegisteredUser>

<we:ifRegisteredUser>

<p><we:sessionField type="print" name="Username" /> | 
<we:sessionField type="print" name="ID" /> | 
<we:sessionLogout id="self">Logout</we:sessionLogout></p>

<?php // Test to see if the database object has been created ?>
<we:listview type="object" name="Profile1" rows="1" classid="16" condition="\$condition">
<we:ifNotFound>
<p>Object 1 not found</p>
<we:else />
<p>Object 1 found</p>
</we:ifNotFound>
</we:listview>

<?php // Test to see if the database object has been created ?>
<we:listview type="object" name="Profile1" rows="1" classid="17" condition="\$condition">
<we:ifNotFound>
<p>Object 2 not found</p>
<we:else />
<p>Object 2 found</p>
</we:ifNotFound>
</we:listview>

</we:ifRegisteredUser>

</body>
</html>
Good luck, and if there's a better way of doing this please let me know.

Michael.
Production Area
London, UK
http://productionarea.com

Zurück zu „DB / Object Module“

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 7 Gäste