Forum for discussing general topics related to Couch.
4 posts Page 1 of 1
Hi

Sorry me again

am so close now with the website I am working on for my client, got the mobile version sorted and working

Issue I got now is the contact form on the contact-us.php page

In the root I got the following coding

Code: Select all
<?php require_once( 'cms/cms.php' ); ?>

<cms:template title='Contact Us'>
<cms:editable name='page_title' label='title' type='text' />
</cms:template>

<cms:php>
    include 'Mobile_Detect.php';
    $detect = new Mobile_Detect();
    if ($detect->isMobile()) {
        // Any mobile device.
        global $CTX;
        $CTX->set( 'is_mobile', '1' );
    }
</cms:php>

<title><cms:show page_title/></title>

<!--CONTENT-->

<cms:if is_mobile >
    <cms:embed 'm/includes/header.php' />
    <cms:embed 'm/contact-us.php' />
    <cms:embed 'm/includes/footer.php' />
<cms:else />
   <cms:embed 'desktop/includes/header.php' />
    <cms:embed 'desktop/contact-us.php' />
    <cms:embed 'desktop/includes/footer.php' />
</cms:if>

<!--CONTENT-->

<?php COUCH::invoke(); ?>


In the snippets/desktop folder I got contact-us.php with the following coding

Code: Select all
<?php require_once( 'cms/cms.php' ); ?>

<cms:template title='Contact Us'>
<cms:editable name='page_title' label='title' type='text' />
</cms:template>

<title><cms:show page_title/></title>

<?php
$title = "Contact Us";

$pgDera="";

$pgKeywords="";

include ( 'includes/header.php' );
?>

<?php
$your_email ='yourname@your-website.com';// <<=== update to your email address

session_start();
$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';

if(isset($_POST['submit']))
{
   
   $name = $_POST['name'];
   $visitor_email = $_POST['email'];
   $user_message = $_POST['message'];
   ///------------Do Validations-------------
   if(empty($name)||empty($visitor_email))
   {
      $errors .= "\n Name and Email are required fields. ";   
   }
   if(IsInjected($visitor_email))
   {
      $errors .= "\n Bad email value!";
   }
   if(empty($_SESSION['6_letters_code'] ) ||
     strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
   {
   //Note: the captcha code is compared case insensitively.
   //if you want case sensitive match, update the check above to
   // strcmp()
      $errors .= "\n The captcha code does not match!";
   }
   
   if(empty($errors))
   {
      //send the email
      $to = $your_email;
      $subject="New form submission";
      $from = $your_email;
      $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
      
      $body = "A user  $name submitted the contact form:\n".
      "Name: $name\n".
      "Email: $visitor_email \n".
      "Message: \n ".
      "$user_message\n".
      "IP: $ip\n";   
      
      $headers = "From: $from \r\n";
      $headers .= "Reply-To: $visitor_email \r\n";
      
      mail($to, $subject, $body,$headers);
      
      header('Location: thank-you.php');
   }
}

// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}
?>

<!--CONTENT-->

   <div class="clear-products"></div>

   <div id="wrapper">

   <div id="column-left-products-box">
    <div class="column-left-contact-text">
   
   
    <div id="contact-social-media">
   
   
    </div>
    </div>
    </div>

   <div id="column-right-contact">
    <div class="column-right-contact-text">
    <h1>Contact Us</h1>
   
       <?php
      if(!empty($errors)){
      echo "<p class='err'>".nl2br($errors)."</p>";
      }
      ?>
      <div id='contact_form_errorloc' class='err'></div>
       <form method="POST" name="contact_form"
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<p>
<label for='name'>Name: </label><br>
<input type="text" name="name" value='<?php echo htmlentities($name) ?>'>
</p>
<p>
<label for='email'>Email: </label><br>
<input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea>
</p>
<p>
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Enter the code above here :</label><br>
<input id="6_letters_code" name="6_letters_code" type="text"><br>
<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
</p>
<input type="submit" value="Submit" name='submit'>
</form>
   
    <script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator  = new Validator("contact_form");
//remove the following two lines if you like error message box popups
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();

frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
</script>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
{
   var img = document.images['captchaimg'];
   img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>
   
   
    </div>
    </div>
   
    </div>
   
    <div id="column-whole-contact">
    <div id="wrapper">
    <div id="box-container-contact">
    <div class="box1">
    <img src="images/services-bottom-image-1.jpg" alt="" title="" />
    </div>
    <div class="box2">
    <img src="images/services-bottom-image-2.jpg" alt="" title="" />
    </div>
    <div class="box3">
    <img src="images/services-bottom-image-3.jpg" alt="" title="" />
    </div>
    </div>
    </div>
   
      <div id="gallery">
   
    </div>
   
    </div>

<!--CONTENT-->

<?php include( 'includes/footer.php' ); ?>

<?php COUCH::invoke(); ?>


The issue I got is, the input fields are outputting the php tags, see screenshot attached

I can't work out why it is outputting them

Any ideas?

Thank you in advance

Kind regards

Ian

Attachments

I think by placing the php code in the form input tag only works when this is looking like this;

<input type="text" name="name" value='</cms:php> ?php echo htmlentities($name) ?<cms:php>'>

I'm not sure tough.
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Ian,

To begin with - embeds don't need the
<?php require_once( 'cms/cms.php' ); ?> and <?php COUCH::invoke(); ?> statements (those are already present in the parent template and embeds become part of those, remember?

The second point is that raw PHP statements won't work in embeds.
You'll have to tweak them a little e.g.
Code: Select all
<?php echo "hello"; ?>

would become
Code: Select all
<cms:php> echo "hello"; </cms:php>

Try making this change and see if things work.

That said, no guarantees if Couch will work with existing PHP code - it claims to work only with static HTML/CSS/JS.
it'd be better if you simply convert the FORM to use Couch tags - not a difficult procedure at all and it'd work in exactly the same manner.

Hope this helps.
Hi KK

Finally got it working, so sorry to be a pain, am loving working with couch cms just getting my head around it
4 posts Page 1 of 1