Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hello couchies again,

I've a problem with a contact-form - nearly the same like: viewtopic.php?f=4&t=7841&p=12897&hilit=contact+form#p12897

Ive tried it on localhost and on my webserver, but problems are both the same: i just got messages that are out of <cms:if k_success > ...</cms:if> or <cms:if k_error > ...</cms:if>

I've tried to dumb everything, but nothing happend. The inputs seem to have no values nor they are even checked.

Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<div id="form">

<cms:form method="post">
    <cms:if k_success >
        <h3>Thanks for your submission. We'll get back to you.</h3>
        <cms:send_mail from=k_email_from to=k_email_to subject='Feedback from your site'>
            The following is an email sent by a visitor to your site:
            <cms:show k_success />
        </cms:send_mail>
    </cms:if>
   
    <cms:send_mail from=k_email_from to=k_email_to subject='Feedback from your site' debug='1'>
            The following is an email sent by a visitor to your site:
    </cms:send_mail>
       
    <cms:if k_error >
        <h3>Failed to submit form</h3>
        <cms:each k_error >
            <cms:show item /><br>
        </cms:each>
    </cms:if>

    Name: <cms:input type="text" size="10" maxlength="40" name="name" required='1' /> <br />
    Email: <cms:input type="text" size="10" name="email" required='1' validator='email' /> <br />
   
    <cms:input name="submit" type="submit" value="Send" />
</cms:form>
   
</div>
<?php COUCH::invoke(); ?>


This is what I've tried after the original one wasn't working ... it's part of the tutorial.

But there is also no Error messages whatever i fill in - it's just sending:

Code: Select all
<cms:send_mail from=k_email_from to=k_email_to subject='Feedback from your site'>
            The following is an email sent by a visitor to your site:
    </cms:send_mail>


Any advices?
When i'am executing it as a standalone .php it's working. So it doesn't depend on the code - sorry for that.

Maybe the problem is inside my page-structure ... all of the subpages are included per jQuery inside of the main content div. If someone hits submit, page is reloading and it redirects to the index.php where no form is located.

I should try to fetch the response of the submit per ajax, right?

My standard form output-ajax looks like this:

Code: Select all
$(document).on('submit', 'form', function() {
      $.ajax({
         data: $(this).serialize(),
         type: $(this).attr('method'),
         url: $(this).attr('action'),
         success: function(response) {
             $('#contentWrapper').html(response);
         }
      });
      return false;
});


success is called and afterwards it redirects to index.php - because of reloading, i think.

This code works just fine with another form, but not with the contact form. :|

How can i prevent reloading?
Hi,

Replying to your first post -
If the code you posted is the exact one you are using in your template, it'll send an email everytime the page loads.

The reason being that the cms:send_mail tag is being used twice in it. The first instance (shown in green) is fine i.e. used within the k_success block. The second instance (shown in red) is outside the k_success check.
<cms:form method="post">
<cms:if k_success >
<h3>Thanks for your submission. We'll get back to you.</h3>
<cms:send_mail from=k_email_from to=k_email_to subject='Feedback from your site'>
The following is an email sent by a visitor to your site:
<cms:show k_success />
</cms:send_mail>

</cms:if>

<cms:send_mail from=k_email_from to=k_email_to subject='Feedback from your site' debug='1'>
The following is an email sent by a visitor to your site:
</cms:send_mail>


<cms:if k_error >
<h3>Failed to submit form</h3>
<cms:each k_error >
<cms:show item /><br>
</cms:each>
</cms:if>


Please take a look at your code and remove the duplication.

Hope this helps.
3 posts Page 1 of 1