Estoy con un fomulario en php que necesito que se presente en diferentes idiomas, según la opción que haya elegido el usuario (es la típica página con banderines de idiomas, pulsas la bandera y te sale todo el sitio en ese idioma). Estoy usando un script para formulario que funciona bien, pero no sé modificarlo para que me cargue un texto u otro según idioma, me viene ya con el texto insertado en el formulario en lugar de estar definido como una variable, que es lo que necesito.
Los textos que he marcado en rojo son los que necesito que se presenten como variables que cargaría de otro archivo, que serían llamados de la siguiente forma: <?php echo JText::_('YOUR_NAME'); ?> siendo YOUR_NAME un valor definido en los diferentes archivos "lang" dependiendo del idioma que la página esté mostrando.
Aquí paso el código, a ver si alquien me hecha una mano porque soy muy nulo en php...
Cita:
Saludos y gracias por anticipado <?php
/**
* @Copyright Copyright (C) 2010- SP
* @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
**/
// no direct access
defined('_JEXEC') or die('Restricted access');
class ModRecommendThisHelper{
function renderForm(){
$content = ' <form class="form-validate" onSubmit="return validate(this);" id="frm_recommend" name="frm_recommend" action="" method="post">
<div class="hiddenDiv">
<div class="spLabel"><label for="txtName">Your Name</label></div>
<div class="spField"><input type="text" id="txtName" name="txtName" class = "required inputField" /> </div>
<div class="spLabel"><label for="txtEmail"> Your Email </label></div>
<div class="spField"><input type="text" id="txtEmail" name="txtEmail" class = "required inputField validate-email" /></div>
<div class="spLabel"><label for="txtMessage"> Message </label></div>
<div class="spField"><textarea id="txtMessage" name="txtMessage" rows="5" class = "required inputField" /></textarea></div>
<div class="spLabel"><label for="txtRecipients"> Recipients Email</label></div>
<div class="spField">
<input type="text" id="txtRecipients[]" name="txtRecipients[]" class="required inputField validate-email" />
<input type="hidden" id="row_count" name="row_count" value="1" />
</div>
<div class="spField">
<input type="hidden" id="counter" name="counter" value="0" />
<input type="submit" id="action" name="action" value="Send" class="actionButton" />
<input type="button" id="addMoreButton" name="addMoreButton" value="Add More.." class="actionButton" />
</div>
</div>
</form>';
return $content;
}
function sendEmail($params){
$sender_name = JRequest::getVar( "txtName" );
$sender_email = JRequest::getVar( "txtEmail" );
$sender_message = JRequest::getVar( "txtMessage" );
$subject = $params->get( "subject" );
$company_info = $params->get( "company_info" );
if (isset($_SERVER['HTTP_REFERER'])){
$referer_url = $_SERVER['HTTP_REFERER'];
}
else {
return;
}
//get mail object
$mailer =& JFactory::getMailer();
//set the sender
$sender = array($sender_email, $sender_name);
$mailer->setSender($sender);
//set recipients
$mailer->addRecipient( JRequest::getVar( "txtRecipients" ) );
//create Subject
$mailer->setSubject( $subject );
//set Body
$body_content = "
<p>Hi,</p>
<p> $sender_name wants you to check this page <a href = \"$referer_url\" > $referer_url </a></p>
<hr />
<p> $sender_name 's message: </p>
<p> $sender_message </p>
";
if (strlen( trim($company_info) ) != 0 ){
$body_content .= "
<hr />
<p> <h2> About the company</h2> </p>
<p> $company_info </p>
";
}
$mailer->setBody( $body_content );
//set html mail
$mailer->isHTML( true );
//now send mail
$send =& $mailer->Send();
if (!$send) {
return 'Error Sending Mail: ' . $send->message;
}
else {
echo '<p class="message">Email Sent.</p>';
}
}
}
/**
* @Copyright Copyright (C) 2010- SP
* @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
**/
// no direct access
defined('_JEXEC') or die('Restricted access');
class ModRecommendThisHelper{
function renderForm(){
$content = ' <form class="form-validate" onSubmit="return validate(this);" id="frm_recommend" name="frm_recommend" action="" method="post">
<div class="hiddenDiv">
<div class="spLabel"><label for="txtName">Your Name</label></div>
<div class="spField"><input type="text" id="txtName" name="txtName" class = "required inputField" /> </div>
<div class="spLabel"><label for="txtEmail"> Your Email </label></div>
<div class="spField"><input type="text" id="txtEmail" name="txtEmail" class = "required inputField validate-email" /></div>
<div class="spLabel"><label for="txtMessage"> Message </label></div>
<div class="spField"><textarea id="txtMessage" name="txtMessage" rows="5" class = "required inputField" /></textarea></div>
<div class="spLabel"><label for="txtRecipients"> Recipients Email</label></div>
<div class="spField">
<input type="text" id="txtRecipients[]" name="txtRecipients[]" class="required inputField validate-email" />
<input type="hidden" id="row_count" name="row_count" value="1" />
</div>
<div class="spField">
<input type="hidden" id="counter" name="counter" value="0" />
<input type="submit" id="action" name="action" value="Send" class="actionButton" />
<input type="button" id="addMoreButton" name="addMoreButton" value="Add More.." class="actionButton" />
</div>
</div>
</form>';
return $content;
}
function sendEmail($params){
$sender_name = JRequest::getVar( "txtName" );
$sender_email = JRequest::getVar( "txtEmail" );
$sender_message = JRequest::getVar( "txtMessage" );
$subject = $params->get( "subject" );
$company_info = $params->get( "company_info" );
if (isset($_SERVER['HTTP_REFERER'])){
$referer_url = $_SERVER['HTTP_REFERER'];
}
else {
return;
}
//get mail object
$mailer =& JFactory::getMailer();
//set the sender
$sender = array($sender_email, $sender_name);
$mailer->setSender($sender);
//set recipients
$mailer->addRecipient( JRequest::getVar( "txtRecipients" ) );
//create Subject
$mailer->setSubject( $subject );
//set Body
$body_content = "
<p>Hi,</p>
<p> $sender_name wants you to check this page <a href = \"$referer_url\" > $referer_url </a></p>
<hr />
<p> $sender_name 's message: </p>
<p> $sender_message </p>
";
if (strlen( trim($company_info) ) != 0 ){
$body_content .= "
<hr />
<p> <h2> About the company</h2> </p>
<p> $company_info </p>
";
}
$mailer->setBody( $body_content );
//set html mail
$mailer->isHTML( true );
//now send mail
$send =& $mailer->Send();
if (!$send) {
return 'Error Sending Mail: ' . $send->message;
}
else {
echo '<p class="message">Email Sent.</p>';
}
}
}