Jump to content

Landing page after contact form post


rushy
 Share

Recommended Posts

Hi. I have a contact page form that collects user queries in the usual manner and when validation is ok it does a method = post with action = contact-form.php to execute the sending of mail from the server.

This is all fine and works well, but when the sending is done, I would like a landing page in my project to be displayed. How would i do that? I've tried adding PW code to the contact-form.php to invoke my landing page but I think this is not in scope as nothing happens.

Many thanks for any guidance.

Paul

 

Link to comment
Share on other sites

hi rushy and welcome to the forum!

18 minutes ago, rushy said:

method = post with action = contact-form.php

that does not sound good in the pw world ;) you should avoid creating your own custom php files in the root of processwire. it's better to stay with the intended way of displaying pages, meaning you have a page in the backend and a related template.

in your case you dont even need another template or another page. you can submit the form to the page itself.

lets say you have a tempalte "contact" and in that template you display your form like this:

<?php
// /site/templates/contact.php

...
<form ...>
  ...
</form>

just change your forms action to itself and add some additional php code to the top of your file:

<?php
// /site/templates/contact.php

if($input->post->yoursubmit) {
  // do some checks and sanitization, eg spam-check
  // log this request
  echo 'Thanks for your message!';
}
else {
  <form action="./">
    <input type="submit" name="yoursubmit" ...>
  </form>
}

pseudocode ;)

  • Like 4
Link to comment
Share on other sites

Hi bernhard thanks for your help!  Great so can I do away with the separate php file completely and do my server mail sending all in my contact file? If so, I can just check if the send was successful or not and display an appropriate message. I'm thinking it would be nice to have a dedicated page after sending the mail with a few other bits of info. on it - if I did want that, how can I invoke another PW page from this point in the contact page?

Many thanks - RuShy

  • Like 1
Link to comment
Share on other sites

if you want or need another page (for analytics that could be nice to have) you can just create a new template eg, "contact-success", create a page with that template eg /contact-success and set your form action to that page ( action="/contact-success" )

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...