Thanks Jason. I can redirect them to the homepage via the PHP header() function, and that works just fine, but then there is no confirmation alert that the form was successfully submitted.
I suppose I could create a distinct page that is a copy of index with the alert, but I have a contact form on a half dozen pages which means that I would need another half dozen confirmation pages (one for each contact form) which becomes really messy really quick. Ideally, there would be some way for me to redirect to the current page and add the alert <div> since my success alert will be the same for all contact forms. Maybe I can try something with includes() instead of header(). If anyone has any ideas on how to get an alert to appear upon form submission, please let me know! On Sat, Mar 24, 2012 at 11:10 PM, Jason Strimpel <jstrim...@gmail.com>wrote: > Not sure if I am the best person to be answering this, but... > When your form is submitted the user sees lib/hfmail.php not index.php > if you are doing a standard post, i.e., not ajax. If you want the user > to stay on the index.php then you can either submit the form via ajax > or redirect them back to index.php from lib/hfmail.php. The best > choice is dependent upon your architecture. I typically build > front-end driven apps with REST APIs so I would opt for ajax. > Hopefully this information helped. If I can be of anymore help just > hit me up on irc @ freenode #requirejs. My nick is jstrimpel. > > Jason > > On Sat, Mar 24, 2012 at 9:22 PM, Henry Finkelstein > <hfinkelst...@gmail.com> wrote: > > Hey there, > > > > I'm a complete newb trying to teach myself how to build websites, so I > > appreciate your patience and apologize in advance if this topic is > outside > > the scope of this forum or, more globally, I sound like a complete > dimwit. > > > > On my index.php page I have a contact form which is validated by > javascript > > and then sends an email with PHP. When the form is successfully > submitted, > > I want a green alert to appear at the top of the page that lets the user > > know we successfully received their submission. As of now, the alert > > appears on a white screen but I want the user to see the index page with > the > > alert. > > > > Any help is greatly appreciated! > > > > Here is the form in html: > > <form id="homeForm" class="form-horizontal" method="post" > > action="lib/hfmail.php"> > > <h3>Free Expert Consultation</h3> > > <fieldset> > > <div class="control-group"> > > <label class="control-label strong">Name</label> > > <div class="controls"> > > <input type="text" class="span2 required" name="name" > > placeholder="First & Last"> > > </div> > > </div> > > <div class="control-group"> > > <label class="control-label strong">Phone Number</label> > > <div class="controls"> > > <div class="input-prepend"> > > <span class="add-on"><i class="icon-phone"></i></span> > > <input type="text" class="span2 required phoneUS" > > name="number"> > > </div> > > </div> > > </div> > > <div class="control-group"> > > <label class="control-label">Email Address</label> > > <div class="controls"> > > <div class="input-prepend"> > > <span class="add-on"><i > class="icon-envelope"></i></span> > > <input type="text" class="span2 email" name="email"> > > </div> > > </div> > > </div> > > <div class="form-actions"> > > <button type="submit" class="btn-large btn-primary">Get > your > > FREE consultation</button> > > </div> > > </fieldset> > > </form> > > </div> > > > > And here is my PHP: > > <?php > > $name = trim($_POST['name']); > > $number = $_POST['number']; > > $email = trim($_POST['email']); > > $todayis = date("l, F j, Y, g:i a e"); > > $success = " > > <a class=\"close\" data-dismiss=\"alert\">×</a> > > <div class = \"alert alert-success\"> > > Thank you, $name, we will be in touch with you shortly. > > </div>"; > > > > $subject = "Home Page Contact Form"; > > > > $message = " Contacted on: $todayis \n > > Attention: Contact Form \n > > Name: $name \n > > Phone Number: $number\n > > Email: $email \n > > "; > > > > $from = "From: $email\r\n"; > > mail("em...@email.com", $subject, $message, $from); > > echo($success) > > ?> >