Note that there are some explanatory texts on larger screens.

plurals
  1. PORoute for sending back an error / success message on form submission
    primarykey
    data
    text
    <p>I'm trying to make my contact form submission process work equally well whether the client has javascipt enabled or not.</p> <p>If javascript is enabled, then validation will be handled client-side when an onsubmit event is triggered which calls my validateContactForm() function:</p> <pre><code>&lt;form method="POST" action="email_processing.php" onsubmit="return validateContactForm();"&gt; </code></pre> <p>If false is returned, then the form isn't submitted and the client is directed to correct what he has done wrong.</p> <p>The form is submitted to the email_processing.php script on if true is returned by validateContactForm() or if javascript is disabled. The php script then revalidates the data and if everything is OK, it sends an email.</p> <p>If I were relying on javascript, I could have made this process asynchronous and just have the php script return a message which would get handled by a callback function client-side. This would either be an error message or a success message.</p> <p>But because I want to make this work for people with javascript disabled, I can't do that. </p> <p>If there's an error, I need to return the contact form page with error messages displayed in the contact form and if it's been a success I should maybe get rid of the contact form and just display a "thanks" message where the form used to be.</p> <p>I'd be interested to know whether stackoverflow users would:</p> <ol> <li><p>Submit the form to a php script which would then redirect to a different php / html page.</p></li> <li><p>Have the validation / email sending functions at the top of the contact us php page itself and each time the contact us page is loaded we check to see if certains variables have been set and if so then we know that we need to validate and send the emails and display the correct format / message.</p></li> <li><p>If I should be thinking about this differently. This must be a very common situation to handle and I have done it many times in lttle applications for myself where I knew that I would have javascript enabled, but I need to do this for a client and I want to make sure that it's done right.</p></li> </ol> <p>Many thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload