2

Okay, so the issue is that I created a one page html website with multiple sections that represent all the pages. The problem that I am having is that the FormIt contact form works, but I can't get it to redirect to the right id. So, once I submit the form, it takes me back to the top of the page. Any ideas? Check out my FormIt call below:

[[!FormIt?
    &hooks=`email`
    &emailFrom=`info@brickhousetitle.com`
    &emailTpl=`emailChunk`
    &emailTo=`[[+email]]`
    &redirectTo=`http://myurl/index.php#contact`
    &emailSubject=`BHT Website Inquiry`
    &validate=`name:required,
    email:email:required,
    comment:required:stripTags`
    &successMessage=`
    <div class="alert alert-success marginTop25">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <h4>Thank you! Your inquiry has been submitted successfully.</h4>
    </div>
    `
    &validationErrorMessage=`
    <div class="alert alert-error">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <ul>
            [[!+fi.error.name:!empty=`
            <li><a href="[[~[[*id]]]]#name">Name is a required field</a></li>
            `]]
            [[!+fi.error.email:!empty=`
            <li><a href="[[~[[*id]]]]#email">Email is a required field</a></li>
            `]]
            [[!+fi.error.comment:!empty=`
            <li><a href="[[~[[*id]]]]#comment">Comment is a required field</a></li>
            `]]
        </ul>
    </div>
    `
]]

[[!+fi.validation_error_message:!empty=`
    <div class="alert alert-error marginTop25">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <ul>
            [[!+fi.error.name:!empty=`
            <li><a href="[[~[[*id]]]]#name">Name is a required field</a></li>
            `]]
            [[!+fi.error.email:!empty=`
            <li><a href="[[~[[*id]]]]#email">Email is a required field</a></li>
            `]]
            [[!+fi.error.comment:!empty=`
            <li><a href="[[~[[*id]]]]#comment">Comment is a required field</a></li>
            `]]
        </ul>
    </div>
`]]

[[!+fi.successMessage]]
<form action="[[~[[*id]]]]" method="post">
    <div class="[[!+fi.error.name:notempty=`control-group error`]]" id="name">
        <label for="name">Name:

            <div class="controls">
                <input type="text" name="name" value="[[!+fi.name]]" class="input-block-level">
            </div>
        </label>
    </div>

    <div class="[[!+fi.error.email:notempty=`control-group error`]]" id="email">
        <label for="email">Email:

            <div class="controls">
                <input type="text" name="email" value="[[!+fi.email]]" class="input-block-level">
            </div>
        </label>
    </div>

    <div class="[[!+fi.error.comment:notempty=`control-group error`]]" id="comment">
        <label for="comment">Comment: </label>

        <div class="controls">
            <textarea name="comment" cols="30" rows="10" value="[[!+fi.comment]]" class="input-block-level"></textarea>
        </div>
    </div>

    <input type="submit" value="Submit" class="btn btn-primary">
</form>
curveball
  • 4,320
  • 15
  • 39
  • 49
Mike
  • 1,590
  • 8
  • 27
  • 41

3 Answers3

1

you need to specify the redirect hook as well as I don't think formit will take a url, the docs say you need a page id that being said, if you need to add a query string to the url, you might have to write a little post hook that makes use of makeUrl &/or sendRedirect.

http://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/class-reference/modx/modx.makeurl

Though you might not be able to make a url with the #contact bit on it....

http://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/class-reference/modx/modx.sendredirect

something like:

$url = 'http://myurl/index.php#contact';
$modx->sendRedirect($url);
Sean Kimball
  • 4,506
  • 9
  • 42
  • 73
  • First and foremost, thank you. Secondly, I have tried your suggestion, which I believe will work; however, I cant even get the regular redirect to work with just a number. I have added the 'redirect' into the hook like you said and I cant get it to redirect to another page at all. I think once I figure out why that is not working the customRedirect hook with the snippet will work out ok. Thanks for pointing me in the right direction! – Mike Apr 19 '14 at 22:25
1

http://rtfm.modx.com/extras/revo/formit/formit.hooks/formit.hooks.redirect - this is what you need. Just edit your snippet call to this:

&hooks=`email,redirect`
&redirectTo=`http://myurl/index.php#contact`
Vasis
  • 2,281
  • 1
  • 16
  • 23
  • Tried that yesterday and it didnt work form me. The redirectTo param only takes id numbers(: – Mike Apr 20 '14 at 20:15
  • How about this: create a resource-link with url `http://myurl/index.php#contact` and specify id of this resource in `redirectTo`. – Vasis Apr 21 '14 at 09:21
0

Found the answer. In order to get the FormIT plugin to return to a specific id on a page we just have to include the # tag in the form action call like this:

@Sean Kimball: Thanks for you help yesterday.

Mike
  • 1,590
  • 8
  • 27
  • 41