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

I have slightly modified the tutorial form but I haven't been able to get it to work.
It doesn't validate properly or submit.

The following is the code for the form. Any help would be greatly appreciated.

Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
        <cms:embed 'header.php' />
        <cms:template title='Contact'>
                <cms:editable name='contact' type='richtext' />
                <cms:editable name='meta_desc' type='text' maxlength='160' />
        </cms:template>
<div class="container lesson-container">
    <cms:show contact />

<cms:if k_error_name || k_error_email || k_error_subject || k_error_message >
<div class="alert alert-danger" role="alert">
    <h4>Error!</h4>
        <cms:if k_error_name>
            <p>Please enter a name!</p>
        </cms:if>
        <cms:if k_error_email>
            <p>Please enter a valid e-mail address!</p>
        </cms:if>
        <cms:if k_error_subject>
            <p>Please enter a message subject!</p>
        </cms:if>
        <cms:if k_error_message>
            <p>Please enter a message!</p>
        </cms:if>
    </div>
</cms:if>

<cms:if k_success>
    <div class="alert alert-success" role="alert">
    <h4>Thank you for your submission!</h4>
    </div>
    <cms:send_mail from=k_email_from to=k_email_to subject='Feedback from your site'>
        <cms:show k_success />
    </cms:send_mail>
</cms:if>

<cms:form action='' method='post' id='contact_form'>
    <div class="form-group">
        <label for="exampleInputName">Name</label>
        <cms:input class='form-control' type='text' name='name' required='1' />
        </div>
    <div class="form-group">
        <label for="exampleInputEmail1">Email address</label>
        <cms:input class='form-control' type='text' name='email' id='email' required='1' validator='email' />
        <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
    </div>
    <div class="form-group">
        <label for="exampleInputSubject1">Subject</label>
        <cms:input class='form-control' type='text' name='subject' id='subject' required='1' />
        </div>
    <div class="form-group">
    <label for="exampleInputMessage1">Message</label>
        <cms:input class='form-control' type='textarea' name='message' id='message' required='1' rows="7" cols="30" />
    </div>
    <div id="button">
            <input type='submit' id='send_message' class="btn btn-primary btn-block" value='Submit' />
    </div>
    </div>
</cms:form>

</div>

<cms:embed 'footer.php' />
<?php COUCH::invoke(); ?>
Hi,

The error in your code is that the k_success and k_error blocks are not nested within the <cms:form> block, which is a requirement for the form to function properly.

Other than that, I have two suggestions -
1. Please use a single all-encompassing <cms:if k_error> block (instead of the current <cms:if k_error_name || k_error_email || k_error_subject || k_error_message >)
2. In the success condition, after sending the mail (or doing other processing), it is recommended to redirect to the same page - this prevents multiple submissions).

You may use the following bare-bones form as a guide to port your code -
Code: Select all
<cms:set submit_success="<cms:get_flash 'submit_success' />" />
<cms:if submit_success >
    <h4>Thank you for your submission!</h4>
</cms:if>

<cms:form method='post' anchor='0'>

    <cms:if k_success >
        .. send mail or do other processing here ..
       
        <cms:set_flash name='submit_success' value='1' />
        <cms:redirect k_page_link />
    </cms:if>

    <cms:if k_error >
        <div class="error">
            <cms:each k_error >
                <br><cms:show item />
            </cms:each>
        </div>
    </cms:if>

    <label>First Name</label>
    <cms:input name="first_name" type="text" />
    <br />

    <label>Last Name</label>
    <cms:input name="last_name" type="text" />
    <br />

    ..
   
    <cms:if "<cms:not submit_success />" >
        <button type="submit">Submit Application</button>
    </cms:if>

</cms:form> 

Hope this helps.
2 posts Page 1 of 1