Jump to content

Add Extra Line In Php Code


yrstruly

Recommended Posts

HiI would like to add a extra entry into the following code called "cell". The code is a message (contact) form and it contains 4 rows of entry boxed. I would like to add an editional one. Can you please tell me how would i do that?<?php defined('_JEXEC') or die(); $option = JRequest::getCmd('option'); function getContactUsVar($id) { $db =& JFactory::getDBO(); $db->setQuery("SELECT `value` FROM #__contactus_vars where `id`='" . addslashes($id) . "' LIMIT 1"); if(!$db->query()) { JError::raiseWarning( 500, $db->getError() ); return ""; } $rows = $db->loadObjectList(); if(sizeof($rows) > 0) { return $rows[0]->value; } return ""; }?><?php echo getContactUsVar("TOPHTML");?><form method="post" action="index.php"><input type="hidden" name="option" value="<?php echo $option; ?>" /><div id="contact_form"><?php $name = JRequest::getString('name');$name = JRequest::getString('cell'); $email = JRequest::getString('email'); $phone = JRequest::getString('phone'); $message = JRequest::getString('message'); $recaptcha_pub = getContactUsVar('RECAPTCHA_PUB'); $recaptcha_pri = getContactUsVar('RECAPTCHA_PRI'); $errMsg = ""; if(strlen($name) < 1) $errMsg .= "You must provide a name.<br>"; if(strlen($email) < 1) $errMsg .= "You must provide an e-mail address.<br>"; if(strlen($message) < 1) $errMsg .= "You must provide a message.<br>"; if(strlen($errMsg) > 0 || (empty($name) && empty($email) && empty($phone) && empty($message))) { if((empty($name) && empty($email) && empty($phone) && empty($cell) && empty($message))) $errMsg = "";?> <div style="text-align: center; font-weight: bold; color: #FF0000; padding: 8px;"><?php echo $errMsg;?></div> <b><?php echo JText::_('NAME');?></b><br> <input type="text" style="width: 100%;" name="name"><p> <b><?php echo JText::_('EMAIL');?></b><br> <input type="text" style="width: 100%;" name="email"><p> <b><?php echo JText::_('PHONE');?></b><br> <input type="text" style="width: 100%;" name="phone"><p> <b><?php echo JText::_('cell');?></b><br> <input type="text" style="width: 100%;" name="phone"><p> <b><?php echo JText::_('MESSAGE');?></b><br> <textarstyle="width: 100%; height: 100px;" name="message"></textarea><p><?php if(strlen($recaptcha_pub) > 0) { require_once 'recaptchalib.php'; echo recaptcha_get_html($recaptcha_pub); }?> <div style="margin: auto;"><input type="submit" value="Send"></div><?php } else { $valid = true; if(strlen($recaptcha_pri) > 0) { require_once 'recaptchalib.php'; $resp = recaptcha_check_answer ($recaptcha_pri, $_SERVER["REMOTE_ADDR"], JRequest::getString("recaptcha_challenge_field"), JRequest::getString("recaptcha_response_field")); if (!$resp->is_valid) {?> <div style="text-align: center; font-weight: bold; color: #EE0000;">You failed to answer the reCaptcha correctly.<br>Response was <?php echo $resp->error;?><p>Please go back and try again.</div><?php $valid = false; } } include "class.phpmailer.php"; $type = getContactUsVar("TYPE"); $mailer = new PHPMailer(); if($type == "SMTP") { $mailer->IsSMTP(); $mailer->SMTPAuth = false; $mailer->Host = getContactUsVar("SERVER"); $mailer->IsHTML(false); } if($type == "Sendmail") { $mailer->IsSendmail(); $mailer->IsHTML(false); } $mailer->From = $email; $mailer->FromName = $name; $mailer->AddAddress(getContactUsVar("EMAIL"), getContactUsVar("EMAIL")); $mailer->Subject = getContactUsVar("SUBJECT"); $mailer->Body = "Name: " . $name . "\n" . "Phone: " . $phone . "\n" . "E-Mail: " . $email . "\n\n" . $message; if($valid) { $sent = $mailer->Send(); if($sent) {?> <div style="text-align: center; font-weight: bold;">Your message has been sent.</div><?php } else {?> <div style="text-align: center; font-weight: bold; color: #FF0000;">An error occurred whilst sending your message.</div><?php } } }?></div></form><?php echo getContactUsVar("BOTTOMHTML");?>

Link to comment
Share on other sites

<b><?php echo JText::_('cell');?></b><br><input type="text" style="width: 100%;" name="phone"><p>

looks like you already have the input, except you are calling it "phone", change to name="cell"

$name = JRequest::getString('cell');

then here you'll obviously not want to save CELL under $name... it would just replace the name that was in $name with the cell info... change $name to $cell on that linethen its a matter of what you want to do with the info stored in $cell?

Link to comment
Share on other sites

  • 3 weeks later...
<b><?php echo JText::_('cell');?></b><br><input type="text" style="width: 100%;" name="phone"><p>

looks like you already have the input, except you are calling it "phone", change to name="cell"

$name = JRequest::getString('cell');

then here you'll obviously not want to save CELL under $name... it would just replace the name that was in $name with the cell info... change $name to $cell on that linethen its a matter of what you want to do with the info stored in $cell?

Hi i have done what you asked, and the cell box is added, but then my message bos dissapears, what am i doing wrong?<?phpdefined('_JEXEC') or die();$option = JRequest::getCmd('option');function getContactUsVar($id) {$db =& JFactory::getDBO();$db->setQuery("SELECT `value` FROM #__contactus_vars where `id`='" . addslashes($id) . "' LIMIT 1");if(!$db->query()) {JError::raiseWarning( 500, $db->getError() );return "";}$rows = $db->loadObjectList();if(sizeof($rows) > 0) {return $rows[0]->value;}return "";}?><?php echo getContactUsVar("TOPHTML");?><form method="post" action="index.php"><input type="hidden" name="option" value="<?php echo $option; ?>" /><div id="contact_form"><?php$name = JRequest::getString('name');$cell = JRequest::getString('cell');$email = JRequest::getString('email');$phone = JRequest::getString('phone');$message = JRequest::getString('message');$recaptcha_pub = getContactUsVar('RECAPTCHA_PUB');$recaptcha_pri = getContactUsVar('RECAPTCHA_PRI');$errMsg = "";if(strlen($name) < 1) $errMsg .= "You must provide a name.<br>";if(strlen($email) < 1) $errMsg .= "You must provide an e-mail address.<br>";if(strlen($message) < 1) $errMsg .= "You must provide a message.<br>";if(strlen($errMsg) > 0 || (empty($name) && empty($email) && empty($phone) && empty($message))) {if((empty($name) && empty($email) && empty($phone) && empty($cell) && empty($message))) $errMsg = "";?><div style="text-align: center; font-weight: bold; color: #FF0000; padding: 8px;"><?php echo $errMsg;?></div><b><?php echo JText::_('NAME');?></b><br><input type="text" style="width: 100%;" name="name"><p><b><?php echo JText::_('EMAIL');?></b><br><input type="text" style="width: 100%;" name="email"><p><b><?php echo JText::_('PHONE');?></b><br><input type="text" style="width: 100%;" name="phone"><p><b><?php echo JText::_('cell');?></b><br><input type="text" style="width: 100%;" name="cell"><p><b><?php echo JText::_('MESSAGE');?></b><br><textarstyle="width: 100%; height: 100px;" name="message"></textarea><p><?phpif(strlen($recaptcha_pub) > 0) {require_once 'recaptchalib.php';echo recaptcha_get_html($recaptcha_pub);}?><div style="margin: auto;"><input type="submit" value="Send"></div><?php} else {$valid = true;if(strlen($recaptcha_pri) > 0) {require_once 'recaptchalib.php';$resp = recaptcha_check_answer ($recaptcha_pri,$_SERVER["REMOTE_ADDR"],JRequest::getString("recaptcha_challenge_field"),JRequest::getString("recaptcha_response_field"));if (!$resp->is_valid) {?><div style="text-align: center; font-weight: bold; color: #EE0000;">You failed to answer the reCaptcha correctly.<br>Response was <?php echo $resp->error;?><p>Please go back and try again.</div><?php$valid = false;}}include "class.phpmailer.php";$type = getContactUsVar("TYPE");$mailer = new PHPMailer();if($type == "SMTP") {$mailer->IsSMTP();$mailer->SMTPAuth = false;$mailer->Host = getContactUsVar("SERVER");$mailer->IsHTML(false);}if($type == "Sendmail") {$mailer->IsSendmail();$mailer->IsHTML(false);}$mailer->From = $email;$mailer->FromName = $name;$mailer->AddAddress(getContactUsVar("EMAIL"), getContactUsVar("EMAIL"));$mailer->Subject = getContactUsVar("SUBJECT");$mailer->Body = "Name: " . $name . "\n" . "Phone: " . $phone . "\n" . "E-Mail: " . $email . "\n\n" . $message;if($valid) {$sent = $mailer->Send();if($sent) {?><div style="text-align: center; font-weight: bold;">Your message has been sent.</div><?php} else {?><div style="text-align: center; font-weight: bold; color: #FF0000;">An error occurred whilst sending your message.</div><?php}}}?></div></form><?php echo getContactUsVar("BOTTOMHTML");?>
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...