How do I validate a form then site to remote URL
Posted: Wed Dec 28, 2011 5:16 pm
Hi - My question: Using the following form and included validation script, how do I send a form to a remote URL. If I include the code in the head of the <Form> tag it send without validation. I need to validate then send. The code works fine otherwise. (My opinion LOL)
I'd also like to know how to validate both a drop down and one check box in the validation code. Your help is appreciated thank you.
The Form
<?php include('form_verify.php'); ?>
<form action="a website for processing" method="post" id="form">
<div>
<label for="first_name">First Name<em>*</em></label>
<input type="text" id="first_name" name="first_name" value="<?= $_POST['first_name']; ?>" maxlength="60" required tabindex="10">
<?php if(isset($firstNameError)) echo '<span class="error">'.$firstNameError.'</span>'; ?>
</div>
<div>
<label for="last_name">Last Name<em>*</em></label>
<input type="text" id="last_name" name="last_name" value="<?= $_POST['last_name']; ?>" maxlength="60" required tabindex="20">
<?php if(isset($lastNameError)) echo '<span class="error">'.$lastNameError.'</span>'; ?>
</div>
<div>
<label for="phone">Email Address<em>*</em></label>
<input type="text" id="email" name="email" value="<?= $_POST['email']; ?>" maxlength="60" required tabindex="30">
<?php if(isset($emailError)) echo '<span class="error">'.$emailError.'</span>'; ?>
</div>
<div>
<label for="email2">Email Address Confirm<em>*</em></label>
<input type="text" id="email2" name="email2" value="<?= $_POST['email2']; ?>" maxlength="120" required tabindex="40">
<?php if(isset($email2Error)) echo '<span class="error">'.$email2Error.'</span>'; ?>
</div>
<div>
<label for="phone">Phone<em>*</em></label>
<input type="text" id="phone" name="phone" value="<?= $_POST['phone']; ?>" maxlength="20" required tabindex="40">
<?php if(isset($phoneError)) echo '<span class="error">'.$phoneError.'</span>'; ?>
</div>
<div>
<label for="title">Job Title<em>*</em></label>
<input type="text" id="title" name="title" value="<?= $_POST['title']; ?>" maxlength="60" required tabindex="50">
<?php if(isset($jobTitleError)) echo '<span class="error">'.$jobTitleError.'</span>'; ?>
</div>
<div>
<label for="company">Company<em>*</em></label>
<input class="wide" type="text" id="company" name="company" value="<?= $_POST['company']; ?>" maxlength="60" required tabindex="60">
<?php if(isset($companyError)) echo '<span class="error">'.$companyError.'</span>'; ?>
</div>
<div>
<label for="platform">Platform</label>
<div class="select-box">
<select id="platform" name="platform" tabindex="70"> <!--Add Validation-->
<option value="">Please select one</option>
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="w">w</option>
</select>
</div>
</div>
<div>
<input id="checkit" name="checkit" type="checkbox" value="1" tabindex="70" style="margin-top: 20px"> Check it.<!--Add Validation-->
</div>
<div>
<p class="buttons">
<button type="submit" id="submit" name="submit">Submit</button>
<input name="submitted" id="submitted" value="true" type="hidden">
</p></div>
</form>
The PHP
<?php
if(isset($_POST['submitted'])) {
if($_POST['first_name'] == '') {
$firstNameError = 'Please enter your first name.';
}
if($_POST['last_name'] == '') {
$lastNameError = 'Please enter your last name.';
}
if($_POST['email'] == '') {
$emailError = 'Please enter your email address.';
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", $_POST['email'])) {
$emailError = 'Please enter a valid email address.';
}
if($_POST['email2'] == '') {
$email2Error = 'Please enter your email address.';
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", $_POST['email2'])) {
$email2Error = 'Please enter a valid confirmation email address.';
}
if($_POST['phone'] == '') {
$phoneError = 'Please enter your phone number.';
}
if($_POST['title'] == '') {
$jobTitleError = 'Please enter your job title.';
}
if($_POST['company'] == '') {
$companyError = 'Please enter your company name.';
}
//Problem how to validate dropdown and checkbox as checked
//Problem: How to get form to action to external web server
}
?>
Thanks again!
I'd also like to know how to validate both a drop down and one check box in the validation code. Your help is appreciated thank you.
The Form
<?php include('form_verify.php'); ?>
<form action="a website for processing" method="post" id="form">
<div>
<label for="first_name">First Name<em>*</em></label>
<input type="text" id="first_name" name="first_name" value="<?= $_POST['first_name']; ?>" maxlength="60" required tabindex="10">
<?php if(isset($firstNameError)) echo '<span class="error">'.$firstNameError.'</span>'; ?>
</div>
<div>
<label for="last_name">Last Name<em>*</em></label>
<input type="text" id="last_name" name="last_name" value="<?= $_POST['last_name']; ?>" maxlength="60" required tabindex="20">
<?php if(isset($lastNameError)) echo '<span class="error">'.$lastNameError.'</span>'; ?>
</div>
<div>
<label for="phone">Email Address<em>*</em></label>
<input type="text" id="email" name="email" value="<?= $_POST['email']; ?>" maxlength="60" required tabindex="30">
<?php if(isset($emailError)) echo '<span class="error">'.$emailError.'</span>'; ?>
</div>
<div>
<label for="email2">Email Address Confirm<em>*</em></label>
<input type="text" id="email2" name="email2" value="<?= $_POST['email2']; ?>" maxlength="120" required tabindex="40">
<?php if(isset($email2Error)) echo '<span class="error">'.$email2Error.'</span>'; ?>
</div>
<div>
<label for="phone">Phone<em>*</em></label>
<input type="text" id="phone" name="phone" value="<?= $_POST['phone']; ?>" maxlength="20" required tabindex="40">
<?php if(isset($phoneError)) echo '<span class="error">'.$phoneError.'</span>'; ?>
</div>
<div>
<label for="title">Job Title<em>*</em></label>
<input type="text" id="title" name="title" value="<?= $_POST['title']; ?>" maxlength="60" required tabindex="50">
<?php if(isset($jobTitleError)) echo '<span class="error">'.$jobTitleError.'</span>'; ?>
</div>
<div>
<label for="company">Company<em>*</em></label>
<input class="wide" type="text" id="company" name="company" value="<?= $_POST['company']; ?>" maxlength="60" required tabindex="60">
<?php if(isset($companyError)) echo '<span class="error">'.$companyError.'</span>'; ?>
</div>
<div>
<label for="platform">Platform</label>
<div class="select-box">
<select id="platform" name="platform" tabindex="70"> <!--Add Validation-->
<option value="">Please select one</option>
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="w">w</option>
</select>
</div>
</div>
<div>
<input id="checkit" name="checkit" type="checkbox" value="1" tabindex="70" style="margin-top: 20px"> Check it.<!--Add Validation-->
</div>
<div>
<p class="buttons">
<button type="submit" id="submit" name="submit">Submit</button>
<input name="submitted" id="submitted" value="true" type="hidden">
</p></div>
</form>
The PHP
<?php
if(isset($_POST['submitted'])) {
if($_POST['first_name'] == '') {
$firstNameError = 'Please enter your first name.';
}
if($_POST['last_name'] == '') {
$lastNameError = 'Please enter your last name.';
}
if($_POST['email'] == '') {
$emailError = 'Please enter your email address.';
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", $_POST['email'])) {
$emailError = 'Please enter a valid email address.';
}
if($_POST['email2'] == '') {
$email2Error = 'Please enter your email address.';
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", $_POST['email2'])) {
$email2Error = 'Please enter a valid confirmation email address.';
}
if($_POST['phone'] == '') {
$phoneError = 'Please enter your phone number.';
}
if($_POST['title'] == '') {
$jobTitleError = 'Please enter your job title.';
}
if($_POST['company'] == '') {
$companyError = 'Please enter your company name.';
}
//Problem how to validate dropdown and checkbox as checked
//Problem: How to get form to action to external web server
}
?>
Thanks again!