I have a basic PHP form here that sends an email when submitted:
<div id="contact">
<form id="contact_form" action="<?=base_url()?>contact/email_form" method="post" name="contact">
<h4>Questions? Comments?</h4>
<p>
<label>Name</label>
<input name="name" id="name" type="text" class="text" />
</p>
<p>
<label>Email</label>
<input name="email" id="email" type="text" class="text" />
</p>
<p class="message">
<label>Question</label>
<textarea name="message" id="message" rows="5" cols="5"></textarea>
</p>
<p class="alt">
<input value="Send Info" id="submitbutton" type="submit">
</p>
</form>
This form works well but I currently have no validation so if the form is submitted even when the fields are blank. Isn't it possible to do validation with jquery?
Once the form is submitted it POSTS to a controller file in codeigniter which does the emailing logic using an email helper in codeigniter. See here:
if($this->email->send())
{
echo 'Message has been sent';
}
else
{
show_error($this->email->print_debugger());
}
As you can see this redirects to the email_form view and echos the results. Is it possible to just stay on the same contact page that has the form and have the results of the post show there instead of redirecting to the <?=base_url()?>contact/email_form
view? I was thinking of having the Text of the SUBMIT button change to "Message Sent" or something like that and then clearing the form fields. This way they stay on the contact page.
Is all of this possible with jquery? Thanks!