Probably getting boring, but I’m developing a site for a friend (www.ututor.com.au)
I am using a PHP file (MailHandler) and a forms.JS and HTML
I am TRYING to get the select drop down menu to work (ID of “days”, but no luck.
Basically, I want it to accept a choice of day of week and preferred time for students to book a session
HTML is:
We will be in touch soon.
Preferred Tutoring Day
Monday Tuesday Wednesday Thursday Friday Saturday SundayPlease provide a detailed description of course topics and questions that you would like some help with. The more specific you are, the better your assigned tutor is able to prepare for your session.
Message must be a minimum of 20 characters: *The message is too short. Must be a minimum of 20 characters. *This field is required. [b] PHP:[/b] <?php $owner_email = $_POST["owner_email"]; $headers = 'From:' . $_POST["email"]; $subject = 'A message from your site visitor ' . $_POST["name"]; $days = $POST['days']; $messageBody = "";if($_POST['name']!='nope'){
$messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['email']!='nope'){
$messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['state']!='nope'){
$messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['phone']!='nope'){
$messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['subject']!='nope'){
$messageBody .= '<p>Subject of study: ' . $_POST["subject"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['days']!='nope'){
$messageBody .= '<p>Preferred day: ' . $_POST["days"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['fax']!='nope'){
$messageBody .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['message']!='nope'){
$messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
}
if($_POST["stripHTML"] == 'true'){
$messageBody = strip_tags($messageBody);
}
try{
if(!mail($owner_email, $subject, $messageBody, $headers)){
throw new Exception('mail failed');
}else{
echo 'mail sent';
}
}catch(Exception $e){
echo $e->getMessage() ."\n";
}
?>
JS
(function($){
$.fn.extend({
forms:function(opt){
if(opt===undefined)
opt={}
this.each(function(){
var th=$(this),
data=th.data(‘forms’),
={
errorCl:‘error’,
emptyCl:‘empty’,
invalidCl:‘invalid’,
successCl:‘success’,
successShow:‘4000’,
mailHandlerURL:‘bin/MailHandler.php’,
ownerEmail:‘[email protected]’,
stripHTML:true,
smtpMailServer:‘localhost’,
targets:‘input,textarea’,
controls:‘a[data-type=reset],a[data-type=submit]’,
validate:true,
rx:{
“.name”:{rx:/^[a-zA-Z’][a-zA-Z-’ ]+[a-zA-Z’]?$/,target:‘input’},
“.state”:{rx:/^[a-zA-Z’][a-zA-Z-’ ]+[a-zA-Z’]?$/,target:‘input’},
“.email”:{rx:/^(("[\w-\s]+")|([\w-]+(?:.[\w-]+))|("[\w-\s]+")([\w-]+(?:.[\w-]+)))(@((?:[\w-]+.)*\w[\w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$)|(@[?((25[0-5].|2[0-4][0-9].|1[0-9]{2}.|[0-9]{1,2}.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2}).){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})]?$)/i,target:‘input’},
“.phone”:{rx:/^+?(\d[\d-+() ]{5,}\d$)/,target:‘input’},
“.subject”:{rx:/^[a-zA-Z’][a-zA-Z-’ ]+[a-zA-Z’]?$/,target:‘input’},
“.days”:{rx:/^[a-zA-Z’][a-zA-Z-’ ]+[a-zA-Z’]?$/,target:‘input’},
“.fax”:{rx:/^+?(\d[\d-+() ]{5,}\d$)/,target:‘input’},
“.message”:{rx:/.{20}/,target:‘textarea’}
},
preFu:function(){
.labels.each(function(){
var label=$(this),
inp=$(.targets,this),
defVal=inp.val(),
trueVal=(function(){
var tmp=inp.is(‘input’)?(tmp=label.html().match(/value=’"[’"].+/),!!tmp&&!!tmp[1]&&tmp[1]):inp.html()
return defVal==’’?defVal:tmp
})()
trueVal!=defVal
&&inp.val(defVal=trueVal||defVal)
label.data({defVal:defVal})
inp
.bind(‘focus’,function(){
inp.val()==defVal
&&(inp.val(’’),.hideEmptyFu(label),label.removeClass(.invalidCl))
})
.bind(‘blur’,function(){
!inp.val()
?inp.val(defVal)
.isValid(label)
?.showErrorFu(label)
:.hideErrorFu(label)),
(.isEmpty(label)
?.showEmptyFu(label)
:.hideEmptyFu(label))
})
.bind(‘keyup’,function(){
label.hasClass(.invalidCl)
&&.isValid(label)
?.showErrorFu(label)
:.hideErrorFu(label)
})
label.find(’.’+.errorCl+’,.’+.emptyCl).css({display:‘block’}).hide()
})
.success=$(’.’+.successCl,.form).hide()
},
isValid:function(el){
var ret=true,
empt=.isEmpty(el)
if(empt)
ret=false,
el.addClass(.invalidCl)
else
$.each(.rx,function(k,d){
if(el.is(k))
d.rx.test(el.find(d.target).val())
?(el.removeClass(.invalidCl),ret=false)
:el.addClass(.invalidCl)
})
return ret
},
isEmpty:function(el){
var tmp
return (tmp=el.find(.targets).val())==’’||tmp==el.data(‘defVal’)
},
validateFu:function(){
.labels.each(function(){
var th=$(this)
.isEmpty(th)
?.showEmptyFu(th)
:.hideEmptyFu(th)
.isValid(th)
?.showErrorFu(th)
:.hideErrorFu(th)
})
},
submitFu:function(){
.validateFu()
if(!.form.has(’.’+.invalidCl).length)
$.ajax({
type: “POST”,
url:.mailHandlerURL,
data:{
name:$(’.name input’,.form).val()||‘nope’,
email:$(’.email input’,.form).val()||‘nope’,
phone:$(’.phone input’,.form).val()||‘nope’,
subject:$(’.subject input’,.form).val()||‘nope’,
days:$(’.days input’,.form).val()||‘nope’,
fax:$(’.fax input’,.form).val()||‘nope’,
state:$(’.state input’,.form).val()||‘nope’,
message:$(’.message textarea’,.form).val()||‘nope’,
owner_email:.ownerEmail,
stripHTML:.stripHTML
},
success: function(){
.showFu()
}
})
},
showFu:function(){
.success.slideDown(function(){
setTimeout(function(){
.success.slideUp()
.form.trigger(‘reset’)
},.successShow)
})
},
controlsFu:function(){
$(.controls,.form).each(function(){
var th=$(this)
th
.bind(‘click’,function(){
.form.trigger(th.data(‘type’))
return false
})
})
},
showErrorFu:function(label){
label.find(’.’+.errorCl).slideDown()
},
hideErrorFu:function(label){
label.find(’.’+.errorCl).slideUp()
},
showEmptyFu:function(label){
label.find(’.’+.emptyCl).slideDown()
.hideErrorFu(label)
},
hideEmptyFu:function(label){
label.find(’.’+.emptyCl).slideUp()
},
init:function(){
_.form=this
.labels=$(‘label’,.form)
_.preFu()
_.controlsFu()
_.form
.bind('submit',function(){
if(_.validate)
_.submitFu()
else
_.form[0].submit()
return false
})
.bind('reset',function(){
_.labels.removeClass(_.invalidCl)
_.labels.each(function(){
var th=$(this)
_.hideErrorFu(th)
_.hideEmptyFu(th)
})
})
_.form.trigger('reset')
}
}
if(!data)
(typeof opt=='object'?$.extend(_,opt):_).init.call(th),
th.data({cScroll:_}),
data=_
else
_=typeof opt=='object'?$.extend(data,opt):data
})
return this
}
})
})(jQuery)
$(function(){
$(’#contact-form’).forms({
ownerEmail:‘[email protected]’
})
})
QUESTION:
How to get the drop down menu to work in the php and JS - PLUS - I need to be able to have a drop down that will allow students to select a time slot (10:am to 11:00am).
Thanks
B