Form HTML > PHP > SQL > Email
709
Here's the HTML Code I have for the form fields.
It needs to be read by the PHP so that a SQL tableidE
reads it and bounces that infomation to an email account. Server connection (connect.php works fine).
I am getting a white blank screen upon submitting the forms with no results.
HTML
<div >
<div >
<form id="dealerform" method="POST" action="../dealerform.php">
<input id="dfr1" type="hidden" name="retailer" value="0" />
<input id="dfex1" type="hidden" name="experience" value="0" />
<input id="dfl1" type="hidden" name="locations" value="0" />
<input id="dfa1" type="hidden" name="assets" value="0" />
<div >
<div >
<label>First Name*</label>
<div ><input id="dffname" name="firstName" type="" /></div>
</div>
<div >
<label>Last Name*</label>
<div ><input id="dflname" name="lastName" type="" /></div>
</div>
</div>
<div >
<div >
<label>E-mail Address*</label>
<div ><input id="dfemail" name="email" type="" /></div>
</div>
<div >
<label>Phone Number</label>
<div ><input name="phoneNumber" type="" /></div>
</div>
</div>
<div >
<div >
<label>Address</label>
<div ><input name="address" type="" /></div>
</div>
<div >
<label>City</label>
<div ><input name="city" type="" /></div>
</div>
</div>
<div >
<div >
<label>State</label>
<div ><input name="state" type="" /></div>
</div>
<div >
<label>Zip</label>
<div ><input name="zip" type="" /></div>
</div>
</div>
<div >
<div >
<label>Company Name</label>
<div ><input name="companyName" type="" /></div>
</div>
<div >
<label>Available Liquid Assets</label>
<div data-id="dfa1" data-form="dealerform" data-value="1" onclick="selectCheckboxSet(jQuery(this))">Yes</div>
<div data-id="dfa1" data-form="dealerform" data-value="0" onclick="selectCheckboxSet(jQuery(this))">No</div>
<div ></div>
</div>
</div>
<div >
<div >
<label>Existing Wireless Retailer?</label>
<div data-id="dfr1" data-form="dealerform" data-value="1" onclick="selectCheckboxSet(jQuery(this))">Yes</div>
<div data-id="dfr1" data-form="dealerform" data-value="0" onclick="selectCheckboxSet(jQuery(this))">No</div>
<div ></div>
</div>
<div >
<label>Years of retail experience</label>
<div data-id="dfex1" data-form="dealerform" data-value="1" onclick="selectCheckboxSet(jQuery(this))">0-2</div>
<div data-id="dfex1" data-form="dealerform" data-value="2" onclick="selectCheckboxSet(jQuery(this))">2-5</div>
<div data-id="dfex1" data-form="dealerform" data-value="3" onclick="selectCheckboxSet(jQuery(this))">5+</div>
<div ></div>
</div>
</div>
<div >
<div >
<label>Types of products you offer:</label>
<div ><input name="typeProducts" type="" /></div>
</div>
<div >
<label>Carrier services you offer:</label>
<div ><input name="carrierServices" type="" /></div>
</div>
</div>
<div >
<div >
<label>Number of retail locations:</label>
<div data-id="dfl1" data-form="dealerform" data-value="1" onclick="selectCheckboxSet(jQuery(this))">0-2</div>
<div data-id="dfl1" data-form="dealerform" data-value="2" onclick="selectCheckboxSet(jQuery(this))">2-5</div>
<div data-id="dfl1" data-form="dealerform" data-value="3" onclick="selectCheckboxSet(jQuery(this))">5+</div>
<div ></div>
</div>
<div >
<label>How did you hear about us?</label>
<div ><input name="howHearAbout" type="" /></div>
</div>
</div>
<div >
<div >
<div onclick="validateSubmitDealer()"><img src="img/form_submit_button.png" /><img src="img/form_submit_button_over.png" /></div>
</div>
</div>
</form>
</div>
</div>
PHP
<?php
mail($recipient, $subject, $headers, $howHearAbout);
if($_POST["submit"]) {
$recipient='[email protected]';
$subject="Become a dealer inquiry";
$headers = 'From: [email protected]';
$dffname=$_POST['firstName'];
$dflname=$_POST['lastName'];
$dfemail=$_POST['email'];
$phoneNumber=$_POST['phoneNumber'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$companyName=$_POST['companyName'];
$dfa1=$_POST['assets'];
$dfr1=$_POST['retailer'];
$dfex1=$_POST['experience'];
$typeProducts=$_POST['typeProducts'];
$carrierServices=$_POST['carrierServices'];
$dfl1=$_POST['locations'];
$howHearAbout=$_POST['howHearAbout'];
}
?>
<?= isset($thankYou) ? $thankYou : 'Did not send' ?>
<?php
if(valid) {
jQuery('#dealerform').append(
jQuery('<input />')
.attr('type', 'hidden')
.attr('name', 'submit')
.attr('value', 'true')
).submit();
}
?>
<?= isset($thankYou) ? $thankYou : 'Did not send' ?>
<?php include("connect.php");
?>
ValidateSubmit() JS
function validateSubmitDealer() {
var valid = true;
// check form values here
var fname = jQuery("#dealerform #df-fname").val();
if( fname === '' ) {
valid = false;
jQuery("#dealerform #df-fname").parent().addClass('error');
}
var lname = jQuery("#dealerform #df-lname").val();
if( lname === '' ) {
valid = false;
jQuery("#dealerform #df-lname").parent().addClass('error');
}
var email = jQuery("#dealerform #df-email").val();
if( email === '' ) {
valid = false;
jQuery("#dealerform #df-email").parent().addClass('error');
}
if( valid ) {
jQuery('#dealerform').submit();
}
Answer
Solution:
It looks like your HTML doesn't actually include any inputs named "submit", so the if-statement in your PHP file will evaluate to false.
You can fix this by adding an input when you submit the form as such:
Additional observations:
It also appears that you are not actually using
$thankYou
; try printing it within your PHP file before/after the include statement.It looks like you're setting many variables, but not using them consistently. Take the following line, for example:
$df
,$senderEmail
and$message
are all undefined variable names. Furthermore, this variable is not used. You should either remove the line or fix it:You seem to have mixed up the
mail
parameters; the message comes before additional headers.