Jump to content

How do I get this PHP code to show up in a .tpl file form


A1SURF.us

Recommended Posts

The input value is already preset with a flat file language designation to set the referral in the database. I don't know if that will cause issues?

 

<tr>
<td><span class="field_title">{language:referer}</span></td>
<td><input type="text" name="referer" value="{referer}" /></td>
</tr>

 

 

But the class I'm using requires this code to render inside the occupied value. The referral name is pulled from their affiliate link, http://domain.com/?r=johndoe, while the PHP code inside the form grabs the r= and post's the johndoe inside the form value that is sitting inside a .tpl file.

 

How do I place this PHP code into a occupied .tpl form value:

<? if($_POST["referer"]) { print $_POST["referer"]; } else { echo securedata($_GET["r"]); } if($_POST['referer'] or $_GET['r']) { print ""; } ?>"><? if($_POST["referer"]) { print $_POST["referer"]; } else { echo securedata($_GET["r"]); } if($_POST['referer'] or $_GET['r']) { print ""; } ?>

 

This does not work: (Unless I did it wrong..)

{php}your code here{/php}

 

Thanks! If I can get this solved all of my hashing troubles, in other post, would be null.

Link to comment
Share on other sites

it looks like you are using smarty or similar. if so, the correct syntax would be:

 

<tr>
<td><span class="field_title">{$referer}</span></td>
<td><input type="text" name="referer" value="{$referer}" /></td>
</tr>

 

and

 

{php}echo "your code here";{/php}

 

 

Typically the value is assigned to smarty, and then smarty puts it into the template. if you haven't assigned the value for smarty, smarty won't know the value and your values won't show in the template.

Link to comment
Share on other sites

This is what I have so far but it's not working:

 

<?php
error_reporting(E_ALL);
session_start();


include_once './admin/inc/config.php';
include_once './admin/inc/globals.php';
include_once './admin/inc/database.class.php';
include_once './admin/inc/validation.func.php';
include_once './admin/inc/template.class.php';
include_once './admin/language/'._BannerAdManagement_DEFAULT_LANGUAGE.'.language.php';

header("Content-type: text/html; charset="._BannerAdManagement_Charset);

$db = new mysqlconnection();
$tpl = new template();
$tpl->set_language($_language);

// input validation
if(isset($_GET['action']) && $_GET['action'] == 'save')
{
$validation_error = true;

if(isset($_POST['username']))
{
	$sql_username = 'SELECT username FROM {prefix}banner_user WHERE username="'.$db->escape($_POST['username']).'"';
	$result_username = $db->query($sql_username);
	$num_rows = mysql_num_rows($result_username);
}

if(isset($_POST['username'], $_POST['password'],$_POST['email'], $_POST['language']) && $num_rows == 0
&& ((isset($_POST['generate_password']) && $_POST['generate_password'] == 1) || $_POST['password'] != '')
&& check_email($_POST['email']) && $_POST['language'] != '')
	$validation_error = false;

if($validation_error == true)
{
	$_GET['action'] = '';
}
}
// end of validation

if(isset($_GET['action']) && $_GET['action'] == 'save')
{
include_once './admin/inc/mail.php';

if(isset($_POST['generate_password']) && $_POST['generate_password'] == '1')
{
	$password = '';
	if($_POST['generate_password'] == true)
	{
		// thank you abraxax 
		$chars    = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
		$char_num = strlen($chars)-1;
		for ($i=0;$i<rand("6","6");++$i)
			$password.= $chars[rand(0,$char_num)];
		// end of my thanks 
	}
	$_POST['password'] = $password;
}


//add referral
if($_POST['r'] and !$_SESSION['r']) { $_SESSION['r'] = $_POST['r']; }
if(($_SESSION['r'] and !$_POST['r']) or (($_SESSION['r'] and $_POST['r']) and $_POST['r'] != $_SESSION['r'])) { $_POST['r'] = $_SESSION['r']; }
if($_POST["referer_name"]) { print $_POST["referer_name"]; } else { echo securedata($_GET["r"]); } if($_POST['referer_name'] or $_GET['r']) { print "$referer_name"; }  

if($_POST['r'])
{
$_SESSION['r'] = $_POST['r'];
{
$checkuser = mysql_query("SELECT username FROM banner_user WHERE username='$username'");

$username_exist = mysql_num_rows($checkuser);


$referer_name = securedata($_POST["referer_name"]);
$referer_name=limit_text($referer,15);
$checkref = mysql_query("SELECT username FROM banner_user WHERE username='$referer_name'");
$referer_exist = mysql_num_rows($checkref);
}
}
  
$sql_language = 'SELECT language FROM {prefix}banner_languages WHERE language_id="'.$db->escape($_POST['language']).'"';
$result_language = $db->query($sql_language);
$row_language = mysql_fetch_array($result_language);

$message = $_language['customer_registered_message']."<br><br>";
$message .= $_language['referer'].': '.$_POST['referer']."<br>";
$message .= $_language['referer_name'].': '.$_POST['referer_name']."<br>";
$message .= $_language['username'].': '.$_POST['username']."<br>";
$message .= $_language['password'].': '.$_POST['password']."<br>";
$message .= $_language['email'].': '.$_POST['email']."<br>";
$message .= $_language['language'].': '.$row_language['language']."<br>";
$message .= $_language['firm'].': '.$_POST['firm']."<br>";
$message .= $_language['lastname'].': '.$_POST['lastname']."<br>";
$message .= $_language['firstname'].': '.$_POST['firstname']."<br>";
$message .= $_language['street'].': '.$_POST['street']."<br>";
$message .= $_language['zipcode'].': '.$_POST['zipcode']."<br>";
$message .= $_language['city'].': '.$_POST['city']."<br>";
$message .= $_language['phone'].': '.$_POST['phone']."<br>";
$message .= $_language['fax'].': '.$_POST['fax']."<br>";
$message .= $_language['mobilephone'].': '.$_POST['mobilephone']."<br>";




send_mail(_BannerAdManagement_MailFrom, $_POST['email'], $_language['customer_registered_subject'], $message);
$tpl->replace_all('info', $_language['customer_registered_confirmation']);

$sql = 'INSERT INTO {prefix}banner_user (referer, username, password, email, userlevel, language_id, firm, lastname, firstname, street, zipcode, city, phone, fax, mobilephone, activate) VALUES (
"'.$db->escape($_POST['referer']).'",
"'.$db->escape($_POST['referer_name']).'",
"'.$db->escape($_POST['username']).'",
"'.md5($_POST['password']).'",
"'.$db->escape($_POST['email']).'",
"1",
"'.$db->escape($_POST['language']).'",
"'.$db->escape($_POST['firm']).'",
"'.$db->escape($_POST['lastname']).'",
"'.$db->escape($_POST['firstname']).'",
"'.$db->escape($_POST['street']).'",
"'.$db->escape($_POST['zipcode']).'",
"'.$db->escape($_POST['city']).'",
"'.$db->escape($_POST['phone']).'",
"'.$db->escape($_POST['fax']).'",
"'.$db->escape($_POST['mobilephone']).'",
"1")';
$db->query($sql);

echo $tpl->display('./admin/templates/customer_register_confirmation.tpl');
}
else
{
$sql = 'SELECT language_id, language FROM {prefix}banner_languages ORDER BY language ASC';
$result = $db->query($sql);
$language_list = '';
while($row = mysql_fetch_array($result))
{
	if(isset($_POST['language']) && $_POST['language'] == $row['language_id'])
		$language_list .= '<option value="'.$row['language_id'].'" selected="selected">'.validate_print_form($row['language'], _BannerAdManagement_Charset).'</option>';
	else
		$language_list .= '<option value="'.$row['language_id'].'">'.validate_print_form($row['language'], _BannerAdManagement_Charset).'</option>';
}

if(isset($validation_error) && $validation_error == true)
{
	// set error
	!isset($_POST['username']) || ($_POST['username'] == '' || $num_rows != 0) ? $tpl->replace('username', 'error', ' style="color: #ff0000;"') : $tpl->replace('username', 'error', '');
	!isset($_POST['password']) || ($_POST['password'] == '' && (!isset($_POST['generate_password']) || $_POST['generate_password'] != 1)) ? $tpl->replace('password', 'error', ' style="color: #ff0000;"') : $tpl->replace('password', 'error', '');
	!isset($_POST['email']) || !check_email($_POST['email']) ? $tpl->replace('email', 'error', ' style="color: #ff0000;"') : $tpl->replace('email', 'error', '');
	!isset($_POST['language']) || $_POST['language'] == '' ? $tpl->replace('language', 'error', ' style="color: #ff0000;"') : $tpl->replace('language', 'error', '');

	$tpl->replace_all('language_list', $language_list);
	$tpl->replace_all('referer_name', validate_print_form($_POST['referer_name'], _BannerAdManagement_Charset));
	$tpl->replace_all('referer', validate_print_form($_POST['referer'], _BannerAdManagement_Charset));
	$tpl->replace_all('username', validate_print_form($_POST['username'], _BannerAdManagement_Charset));
	$tpl->replace_all('password', validate_print_form($_POST['password'], _BannerAdManagement_Charset));
	$tpl->replace_all('email', validate_print_form($_POST['email'], _BannerAdManagement_Charset));
	$tpl->replace_all('firm', validate_print_form($_POST['firm'], _BannerAdManagement_Charset));
	$tpl->replace_all('lastname', validate_print_form($_POST['lastname'], _BannerAdManagement_Charset));
	$tpl->replace_all('firstname', validate_print_form($_POST['firstname'], _BannerAdManagement_Charset));
	$tpl->replace_all('street', validate_print_form($_POST['street'], _BannerAdManagement_Charset));
	$tpl->replace_all('zipcode', validate_print_form($_POST['zipcode'], _BannerAdManagement_Charset));
	$tpl->replace_all('city', validate_print_form($_POST['city'], _BannerAdManagement_Charset));
	$tpl->replace_all('phone', validate_print_form($_POST['phone'], _BannerAdManagement_Charset));
	$tpl->replace_all('fax', validate_print_form($_POST['fax'], _BannerAdManagement_Charset));
	$tpl->replace_all('mobilephone', validate_print_form($_POST['mobilephone'], _BannerAdManagement_Charset));

}
else
{
	$tpl->replace('username', 'error', '');
	$tpl->replace('password', 'error', '');
	$tpl->replace('email', 'error', '');
	$tpl->replace('language', 'error', '');

	$tpl->replace_all('language_list', $language_list);
	$tpl->replace_all('referer', '');
	$tpl->replace_all('referer_name', '');
	$tpl->replace_all('username', '');
	$tpl->replace_all('password', '');
	$tpl->replace_all('email', '');
	$tpl->replace_all('firm', '');
	$tpl->replace_all('lastname', '');
	$tpl->replace_all('firstname', '');
	$tpl->replace_all('street', '');
	$tpl->replace_all('zipcode', '');
	$tpl->replace_all('city', '');
	$tpl->replace_all('phone', '');
	$tpl->replace_all('fax', '');
	$tpl->replace_all('mobilephone', '');


}
echo $tpl->display('./admin/templates/customer_register_form.tpl');
}

 

This is the .tpl form:

<form action="advertise.php?action=save" name="customer_register" method="post">
	 <p style="font-size:small;font-weight:bold;">*Required</p>

	<table style="border:2px green thick;">
		<tr>
			<td width="170px"><span class="field_title"{error:username}><span style="font-size:small;font-weight:bold;">*</span>{language:username}</span></td>
			<td><input type="text" name="username" value="{username}" /></td>
		</tr>
		<tr>
			<td><span class="field_title"{error:password}><span style="font-size:small;font-weight:bold;">*</span>{language:password}</span></td>
			<td><input type="text" name="password" value="{password}" /> <input type="checkbox" name="generate_password" value="1" /> {language:generate_password}</td>
		</tr>
		<tr>
			<td><span class="field_title"{error:email}><span style="font-size:small;font-weight:bold;">*</span>{language:email}</span></td>
			<td><input type="text" name="email" value="{email}" /></td>
		</tr>
		<tr>
			<td><span class="field_title"{error:language}><span style="font-size:small;font-weight:bold;">*</span>{language:language}</span></td>
			<td><select name="language">
						{language_list}
						</select></td>
		</tr>
		<tr>
			<td><span class="field_title">{language:firm}</span></td>
			<td><input type="text" name="firm" value="{firm}" /></td>
		</tr>
		<tr>
			<td><span class="field_title">{language:lastname}</span></td>
			<td><input type="text" name="lastname" value="{lastname}" /></td>
		</tr>
		<tr>
			<td><span class="field_title">{language:firstname}</span></td>
			<td><input type="text" name="firstname" value="{firstname}" /></td>
		</tr>
		<tr>
			<td><span class="field_title">{language:street}</span></td>
			<td><input type="text" name="street" value="{street}" /></td>
		</tr>
		<tr>
			<td><span class="field_title">{language:zipcode}</span></td>
			<td><input type="text" name="zipcode" value="{zipcode}" /></td>
		</tr>
		<tr>
			<td><span class="field_title">{language:city}</span></td>
			<td><input type="text" name="city" value="{city}" /></td>
		</tr>
		<tr>
			<td><span class="field_title">{language:phone}</span></td>
			<td><input type="text" name="phone" value="{phone}" /></td>
		</tr>
		<tr>
			<td><span class="field_title">{language:fax}</span></td>
			<td><input type="text" name="fax" value="{fax}" /></td>
		</tr>
		<tr>
			<td><span class="field_title">{language:mobilephone}</span></td>
			<td><input type="text" name="mobilephone" value="{mobilephone}" /></td>
		</tr>
			<tr>
			<td><span class="field_title">{language:referer}</span></td>
			<td><input type="text" name="referer" value="{referer}{referer_name}" /></td>
		</tr>
	</table>
	<br />
	<input class="button" type="submit" value="{language:registerbutton}" />
	</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.