View Full Version : PHP Form Help

04-11-2012, 02:02 PM
Hi there,

Been having an issue with a form that I have been using from a tutorial, I want the form to validate (which it does perfectly at the minute, but on submit (if it is validated) I want it to redirect to another page...anyone any ideas?

My code is
<div id="contact_form">
<form method="post" action="assets/php/send.php" id="contactForm">
<div class="error" id="error">An error occurer and the message can't be sent!</div>
<div class="success" id="success">Email sent successfully!<br />Thank you for contacting us.</div>

<span class="input">
<label for="title"><b>Title:</b> </label>
<input type="text" id="title" name="title" />
<div class="warning" id="titleError">This field can't stay empty</div>

<span class="input">
<label for="name"><b>Name:</b> </label>
<input type="text" id="name" name="name" />
<div class="warning" id="nameError">This field can't stay empty</div>

<span class="input">
<label for="surname"><b>Surname:</b> </label>
<input type="text" id="surname" name="surname" />
<div class="warning" id="surnameError">This field can't stay empty</div>

<span class="input">
<label for="email"><b>Email:</b> </label>
<input type="text" id="email" name="email" />
<div class="warning" id="emailError">Enter with a valid email!</div>

<span class="input">
<label for="phone"><b>Phone:</b> </label>
<input type="text" id="phone" name="phone" />
<div class="warning" id="phoneError">Only digits are accepted!</div>

<span class="input">
<label for="sales"><b>Sales:</b> </label>
<select id="sales" name="sales">
<option value="Support">Support</option>
<option value="Sales">Sales</option>
<option value="Other">Other</option>

<span class="input">
<label for="message"><b>Message:</b> </label>
<textarea id="message" name="message">Hello,
<div class="warning" id="messageError">This field can't stay empty</div>

<span class="input">
<label for="security_code"><b>Security Code:</b> </label>
<input class="noicon" type="text" id="security_code" name="security_code" style="width:100px" />
<img src="assets/php/security/1/sec.php" style="vertical-align:middle;" />
<div class="warning" id="security_codeError">The security code is wrong!</div>
<span id="submit" class="input">
<label for="submit"></label>
<p id="ajax_loader" style="text-align:center;"><img src="assets/img/contact/ajax-loader.gif" /></p>
<input id="send" type="submit" value="SEND" />



I am guessing I need to chnage the code withing the first few lines I am just not sure what too.


04-11-2012, 02:20 PM
This is just the HTML, you need to show us the PHP.

In your 'send.php' you need to write an IF statement whereby the user will be forwarded if the validation is passed.

04-11-2012, 02:20 PM
The redirect will happen on the script that processes the form.

Right now, the method used looks like AJAX, where it makes the "success"
<div> visible if validation is correct, but that appears on the same page
as the form.

To redirect would involve modifying the script that "unhides, or makes visible"
the <div class>. Not sure whether that happens in a .js script? But you'll need
to make several modifications to make it work.

04-11-2012, 02:24 PM
So my send.php has the following in it:

if(getenv('REQUEST_METHOD') != 'POST')
exit('Opss! Only POST requests are accepted');

include_once 'config.class.php';
include_once 'protector.class.php';
include_once 'email.class.php';


$email = new Email($_POST);


where would i need to create the IF statement?

04-11-2012, 03:00 PM
Ok, there's more going on with this than I thought. It's the problem with pulling a tutorial script and trying to modify it.

04-11-2012, 03:16 PM
Ahh ok, im not great with php but unfortuantely it is a must. Thanks for your help anyway :)

04-11-2012, 03:50 PM
Lee ...
Give us the source where you found the tutorial (or example scripts).