tomkilbourn
New Members-
Posts
7 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
tomkilbourn's Achievements
Newbie (1/5)
0
Reputation
-
Hello, I have just started to use WordPress to build a site, and have adding a php contact form which incorporates Re-Captcha security. The Re-Captcha it is working fine, but the error message which is displayed when the Re-Captcha is typed incorrectly is displaying at the very top of the page and I would like the error message "The reCAPTCHA failed with this message:...." to be displayed next to the Re-Captcha box itself at the bottom of the form. How would I go about achieving this? I admit I am no good with PHP and have been away from all this for some time!! <?php /* Template Name: Contact */ ?> <?php // require_once('recaptchalib.php'); $publickey = "xxxxxxxx"; // you got this from the signup page $privatekey = "xxxxxxxxx"; // if(isset($_POST['submitted'])) { if(trim($_POST['contactName']) === '') { $nameError = 'Please enter your name.'; $hasError = true; } else { $name = trim($_POST['contactName']); } if(trim($_POST['email']) === '') { $emailError = 'Please enter your email address.'; $hasError = true; } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) { $emailError = 'You entered an invalid email address.'; $hasError = true; } else { $email = trim($_POST['email']); } if(trim($_POST['comments']) === '') { $commentError = 'Please enter a message.'; $hasError = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['comments'])); } else { $comments = trim($_POST['comments']); } } $response = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if( ! $response->is_valid ) { echo '<div id="recaptcha_error_box">The reCAPTCHA failed with this message: '.$response->error.'<br />Please try again.</div>'; // by default now, let the flow-of-control fall back into the <form> below so the user can try again } else { if(!isset($hasError)) { $emailTo = get_option('tz_email'); if (!isset($emailTo) || ($emailTo == '') ){ $emailTo = get_option('admin_email'); } $subject = '[PHP Snippets] From '.$name; $body = "Name: $name \n\nEmail: $email \n\nComments: $comments"; $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; wp_mail($emailTo, $subject, $body, $headers); $emailSent = true; } } } ?> <?php get_header(); ?> <div id="container"> <div id="content"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div <?php post_class() ?> id="post-<?php the_ID(); ?>"> <h1 class="entry-title"><?php the_title(); ?></h1> <div class="entry-content"> <?php if(isset($emailSent) && $emailSent == true) { ?> <div class="thanks"> <p>Thanks, your email was sent successfully.</p> </div> <?php } else { ?> <?php the_content(); ?> <?php if(isset($hasError) || isset($captchaError)) { ?> <p class="error">Sorry, an error occured.<p> <?php } ?> <form action="<?php the_permalink(); ?>" id="contactForm" method="post"> <ul class="contactform"> <li> <label for="contactName">Name:</label> <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="required requiredField" /> <?php if($nameError != '') { ?> <span class="error"><?=$nameError;?></span> <?php } ?> </li> <li> <label for="email">Email</label> <input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="required requiredField email" /> <?php if($emailError != '') { ?> <span class="error"><?=$emailError;?></span> <?php } ?> </li> <li><label for="commentsText">Message:</label> <textarea name="comments" id="commentsText" rows="20" cols="30" class="required requiredField"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea> <?php if($commentError != '') { ?> <span class="error"><?=$commentError;?></span> <?php } ?> </li> <li> <?php echo recaptcha_get_html($publickey, $errors); ?> </li> <li> <input type="submit">Send email</input> </li> </ul> <input type="hidden" name="submitted" id="submitted" value="true" /> </form> <?php } ?> </div><!-- .entry-content --> </div><!-- .post --> <?php endwhile; endif; ?> </div><!-- #content --> </div><!-- #container --> <?php get_sidebar(); ?> <?php get_footer(); ?>
-
Need to add Columns option to my code - help!
tomkilbourn replied to tomkilbourn's topic in PHP Coding Help
Is there anyone who can help me add the option of a third column to the code? -
Hello forum I need some help modifying a secton of PHP code which is used in a module for displaying news article headlines. The code snippet allows for either a single-column or a two-column layout. What I would love to do is add a THIRD column to produce a 3 column layout if desired. The single-column layout class is called "singleColumn", and the two-column layout class is called "firstColumn" and "secondColumn". I have this snippet from my default.php module code, but I don't really know how to add the option for a third column, can anyone help, I would be very greatful <?php // no direct access defined('_JEXEC') or die('Restricted access'); $centreColumn = ''; $rightColumn = $leftColumn = ''; for ($b = 0; (($this->news_amount - ($b * $this->news_column)) > 0); $b++) { for ($c = 0; $c < $this->news_column; $c++) { if ($this->news_column == 1) { $div_class = 'centre_column_class'; } elseif ($this->news_column == 2) { $div_class = ($c == 0) ? 'left_column_class' : 'right_column_class'; } $column = ($b * $this->news_column) + $c; //Start Centre Column here { //Start Centre Column Rounded Flexable Corners option if ($this->centrerounded) { $centreColumn .= '<div class="roundedflexable"><div><div><div>'."\n"; if (isset($news_code_html_tab[$column])) { $centreColumn .= $news_code_html_tab[$column]; } } //Start Centre Column Rounded Fixed Corners option elseif ($this->centreroundedfixed) { $centreColumn .= '<div class="gk_round_fixed"><div>'."\n"; if (isset($news_code_html_tab[$column])) { $centreColumn .= $news_code_html_tab[$column]; } } //Start Centre Column Squared Corners option elseif ($this->centresquaredcorners) { $centreColumn .= '<div class="squared">'."\n"; if (isset($news_code_html_tab[$column])) { $centreColumn .= $news_code_html_tab[$column]; } } //End Centre Column Squared Corners option if ($this->centresquaredcorners) { $centreColumn .= '</div>'."\n"; } //End Centre Column Rounded Fixed Corners option elseif ($this->centreroundedfixed) { $centreColumn .= '</div></div>'."\n"; } //End Centre Column Rounded Flexable Corners option elseif ($this->centrerounded) { $centreColumn .= '</div></div></div></div>'."\n"; } } //End Centre Column here //Start Left Column here if ($c == 0 && $this->news_column > 1) { //Start Left Column Rounded Corners option if ($this->leftrounded) { $leftColumn .= '<div class="roundedflexable"><div><div><div>'."\n"; if (isset($news_code_html_tab[$column])) { $leftColumn .= $news_code_html_tab[$column]; } } //Start Left Column Squared Corners option elseif ($this->leftsquaredcorners) { $leftColumn .= '<div class="squared">'."\n"; if (isset($news_code_html_tab[$column])) { $leftColumn .= $news_code_html_tab[$column]; } } //End Left Column Rounded Corners option if ($this->leftrounded) { $leftColumn .= '</div></div></div></div>'."\n"; } //End Left Column Squared Corners option elseif ($this->leftsquaredcorners) { $leftColumn .= '</div>'."\n"; } } //End Left Column here ///////////////////////////////////////////// //Start Right Column here if ($c != 0){ //Start Right Column Rounded Corners option if ($this->rightrounded) { $rightColumn .= '<div class="roundedflexable"><div><div><div>'."\n"; if (isset($news_code_html_tab[$column])) { $rightColumn .= $news_code_html_tab[$column]; } } //Start Right Column Squared Corners option elseif ($this->rightsquaredcorners) { $rightColumn .= '<div class="squared">'."\n"; if (isset($news_code_html_tab[$column])) { $rightColumn .= $news_code_html_tab[$column]; } } //End Right Column Rounded Corners option if ($this->rightrounded) { $rightColumn .= '</div></div></div></div>'."\n"; } //End Right Column Squared Corners option elseif ($this->rightsquaredcorners) { $rightColumn .= '</div>'."\n"; } } //End Right Column here } } //Display Output from Left Column here if (!empty($leftColumn)) { echo '<div id="'.$this->left_module_id.'">'."\n"; echo $leftColumn; echo '</div>'; } //End Left Column //Display Output from Right Column here if (!empty($rightColumn)) { echo '<div id="'.$this->right_module_id.'">'."\n"; echo $rightColumn; echo '</div>'."\n"; } //End Right Column //Display Output from Centre Column here if (!empty($centreColumn)) { echo '<div id="'.$this->centre_module_id.'">'."\n"; echo $centreColumn; echo '</div>'."\n"; } //End Centre Column ?>
-
Need to add an extra column class to my php code
tomkilbourn replied to tomkilbourn's topic in PHP Coding Help
Would you be able to give me an example of how incorporating a thirdColumn into the code? Im very new to php and am struggling -
Need to add an extra column class to my php code
tomkilbourn replied to tomkilbourn's topic in PHP Coding Help
I will give it a go, but wouldn't I have to declare the thirdColum variable first? E.g. - $thirdColumn = ''; or maybe $firstColumn = $secondColumn = thirdColumn = ''; Ive been trying to add a line something like this - elseif ($this->news_column == 3) { $div_class = 'first_column_class : second_column_class : third_column_class'; } But the code isn't right and gives an error, it doesnt like the 3 classes together. If this is any help, here is the full script including the code for outputting the columns and classes - <?php // no direct access defined('_JEXEC') or die('Restricted access'); $singleColumn = ''; $secondColumn = $firstColumn = ''; $firstColumn = $secondColumn = $thirdColumn = ''; for ($b = 0; (($this->news_amount - ($b * $this->news_column)) > 0); $b++) { for ($c = 0; $c < $this->news_column; $c++) { if ($this->news_column == 1) { $div_class = 'single_column_class'; } elseif ($this->news_column == 2) { $div_class = ($c == 0) ? 'second_column_class' : 'first_column_class'; } $column = ($b * $this->news_column) + $c; //Start Single Column here { //Start SingleColumn Rounded Flexable Corners option if ($this->singlerounded) { $singleColumn .= '<div class="roundedflexable"><div><div><div>'."\n"; if (isset($news_code_html_tab[$column])) { $singleColumn .= $news_code_html_tab[$column]; } } //Start SingleColumn Rounded Fixed Corners option elseif ($this->singleroundedfixed) { $singleColumn .= '<div class="gk_round_fixed"><div>'."\n"; if (isset($news_code_html_tab[$column])) { $singleColumn .= $news_code_html_tab[$column]; } } //Start SingleColumn Squared Corners option elseif ($this->singleesquaredcorners) { $singleColumn .= '<div class="squared">'."\n"; if (isset($news_code_html_tab[$column])) { $singleColumn .= $news_code_html_tab[$column]; } } //End SingleColumn Squared Corners option if ($this->singlesquaredcorners) { $singleColumn .= '</div>'."\n"; } //End SingleColumn Rounded Fixed Corners option elseif ($this->singleroundedfixed) { $singleColumn .= '</div></div>'."\n"; } //End Single Column Rounded Flexable Corners option elseif ($this->singlerounded) { $singleColumn .= '</div></div></div></div>'."\n"; } } //End SingleColumn here //Start First Column here if ($c == 0 && $this->news_column > 1) { //Start First Column Rounded Corners option if ($this->firstrounded) { $firstColumn .= '<div class="roundedflexable"><div><div><div>'."\n"; if (isset($news_code_html_tab[$column])) { $firstColumn .= $news_code_html_tab[$column]; } } //Start first Column Squared Corners option elseif ($this->firstsquaredcorners) { $firstColumn .= '<div class="squared">'."\n"; if (isset($news_code_html_tab[$column])) { $firstColumn .= $news_code_html_tab[$column]; } } //End First Column Rounded Corners option if ($this->firstrounded) { $firstColumn .= '</div></div></div></div>'."\n"; } //End first Column Squared Corners option elseif ($this->firstsquaredcorners) { $firstColumn .= '</div>'."\n"; } } //End first Column here ///////////////////////////////////////////// //Start Second Column here if ($c != 0){ //Start Second Column Rounded Corners option if ($this->secondrounded) { $secondColumn .= '<div class="roundedflexable"><div><div><div>'."\n"; if (isset($news_code_html_tab[$column])) { $secondColumn .= $news_code_html_tab[$column]; } } //Start second Column Squared Corners option elseif ($this->secondsquaredcorners) { $secondColumn .= '<div class="squared">'."\n"; if (isset($news_code_html_tab[$column])) { $secondColumn .= $news_code_html_tab[$column]; } } //End Second Column Rounded Corners option if ($this->secondrounded) { $secondColumn .= '</div></div></div></div>'."\n"; } //End Second Column Squared Corners option elseif ($this->secondsquaredcorners) { $secondColumn .= '</div>'."\n"; } } //End Second Column here } } //Display Output from First Column here if (!empty($firstColumn)) { echo '<div id="'.$this->first_module_id.'">'."\n"; echo $firstColumn; echo '</div>'; } //End First Column //Display Output from Second Column here if (!empty($secondColumn)) { echo '<div id="'.$this->second_module_id.'">'."\n"; echo $secondColumn; echo '</div>'."\n"; } //End Second Column //Display Output from Single Column here if (!empty($singleColumn)) { echo '<div id="'.$this->single_module_id.'">'."\n"; echo $singleColumn; echo '</div>'."\n"; } //End Single Column ?> -
Hello forum I need some help modifying a secton of PHP code which is used in a module for displaying news article headlines. The code snippet allows for either a single-column or a two-column layout. What I would love to do is add a THIRD column to produce a 3 column layout if desired. The single-column layout class is called "singleColumn", and the two-column layout class is called "firstColumn" and "secondColumn". I have this snippet from my default.php module code, but I don't really know how to add the option for a third column, can anyone help, I would be very greatful $singleColumn = ''; $firstColumn = $secondColumn = ''; for ($b = 0; (($this->news_amount - ($b * $this->news_column)) > 0); $b++) { for ($c = 0; $c < $this->news_column; $c++) { if ($this->news_column == 1) { $div_class = 'single_column_class'; } elseif ($this->news_column == 2) { $div_class = ($c == 0) ? 'first_column_class' : 'second_column_class'; } $column = ($b * $this->news_column) + $c; Im not sure how to code to allow for a third column, could anyone help me out?
-
Hello Forum this is my first post here I am using a php script (view.default.php) in a Joomla module to display headings which to link to the full articles in my site. Using the Joomla Module Manager, I can select either a one or two-column layout, choose the number of links to display from a category or section, select squared or rounded corners. The problem which Iām having is that the html output for displaying the columns isn't quite right. My php code is outputting HTML with every article link inside a left and right column - <div id="left-column"></div> <div id="right-column"></div> <div id="left-column"></div> <div id="right-column"></div> <div id="left-column"></div> <div id="right-column"></div> I would like the HTML outputted as a single left and a single right column with the article links inside each column as shown here.. <div id="left-column"> article link1 article link2 article link3 </div> <div id="right-column"> article link4 article link5 </div> This is the php module code I have been using - <?php // no direct access defined('_JEXEC') or die('Restricted access'); for ($b = 0; (($this->news_amount - ($b * $this->news_column)) > 0); $b++) { for ($c = 0; $c < $this->news_column; $c++) { if ($this->news_column == 1) { $div_class = 'center_column_class'; } elseif ($this->news_column == 2) { $div_class = ($c == 0) ? 'left_column_class' : 'right_column_class'; } $column = ($b * $this->news_column) + $c; //Start Left Column if ($c == 0 && $this->news_column > 1) { echo '<div id="'.$this->left_module_id.'">'."\n"; if ($this->leftrounded) { echo '<div class="roundedflexable">'."\n"; echo '<div>'."\n"; echo '<div>'."\n"; echo '<div>'."\n"; if (isset($news_code_html_tab[$column])) { echo $news_code_html_tab[$column]; } } if ($this->leftrounded) { echo '</div></div></div></div>'; } echo '</div>'; } //End Left Column //Start Right Column if ($c != 0){ echo '<div id="'.$this->right_module_id.'">'."\n"; if ($this->rightrounded) { echo '<div class="roundedflexable">'."\n"; echo '<div>'."\n"; echo '<div>'."\n"; echo '<div>'."\n"; if (isset($news_code_html_tab[$column])) { echo $news_code_html_tab[$column]; } } if ($this->rightrounded) { echo '</div></div></div></div>'."\n"; } echo '</div>'."\n"; } //End Right Column } } ?> The link to my site displaying the columns in question is ā http://www.tomsspecialreserve.co.uk/joomla Could anybody possibly help me out, I am a total novice when it comes to php and it quickly goes over my head! Thank you The link to my site displaying the columns in question is ā http://www.tomsspecialreserve.co.uk/joomla There is also a helper.php file and an xml file used in the module. Could anybody possibly help me out, I am a total novice when it comes to php and it quickly goes over my head! Thank you