Forum Moderators: open

Message Too Old, No Replies

Help please with some php/javascript

         

neverett

7:20 am on Jun 6, 2007 (gmt 0)

10+ Year Member



I'm having some issues with the following file. My checkForm() won't work, and I'm wondering if anyone can point me in the correct direction. Thanks in advance for your help!

NE


<?
// processapplicant.php

include("header.php");

/*if($isadminuser!= '1'){
send_restricted_error();
include("footer.php");
exit;
}*/

$applicant = new Applicant();
$applicant->get($_REQUEST['id']);
$pilot = new Pilot();
$next_id = sprintf("%04d", $pilot->getAllAsNum() + 1);
$generated_password = genpassword(8);

?>

<script language="javascript" type="text/javascript">
function checkForm(){
var msg = "";
if(this.process_applicant.pilot_id.value == ""){
msg += "Reject this application... this pilot was not assigned an ID (auto index)\n";
}
if(this.process_applicant.pilot_flightversion.value == ""){
msg += "Reject this application... this pilot did not give a flight sim version\n";
}
if(this.process_applicant.pilot_country.value == ""){
msg += "Reject this application... this pilot did not supply their country\n";
}
if(this.process_applicant.pilot_vatsim.value == ""){
msg += "Reject this application... this pilot did not supply a VATSIM ID#\n";
}
if(this.process_applicant.pilotname.value == ""){
msg += "Please enter a name\n";
}
if(this.process_applicant.vusafid.value == ""){
msg += "Please enter a vUSAF ID# (vUSAF0001)\n";
}
if(this.process_applicant.pilotlogin.value == ""){
msg += "Please enter a login (vUSAF0001)\n";
}
if(this.process_applicant.password.value!= this.process_applicant.password_confirm.value ¦¦ this.process_applicant.password.value == ""){

msg += "Passwords do not match\n";
}
if(this.process_applicant.pilotemail.value == ""){
msg += "Please enter an email address\n";
}
if(this.process_applicant.pilotrank.value == ""){
msg += "Please select a rank to assign\n";
}
if(this.process_applicant.acceptance_text.value == ""){
msg += "Please type the acceptance text for the email to the pilot\n";
}
if(msg == ""){
return true;
}else{
alert(msg);
return false;
}
}
</script>

<div class="content2">
<div class="content2-pagetitle">Applicants</div>
<div class="content-txtbox-noshade">
<div class="content-title-noshade-size2">Process applicant</div>

<form method="post" name="process_applicant" action="do_addpilotapplication.php" onsubmit="return checkForm(this);">
<input type="hidden" name="pilot_id" value="<? echo $applicant->id?>">
<input type="hidden" name="pilot_flightversion" value="<? echo $applicant->flightversion?>">
<input type="hidden" name="pilot_country" value="<? echo $applicant->country?>">
<input type="hidden" name="pilot_vatsim" value="<? echo $applicant->vatsim?>">
<table>
<tr>
<td>Name</td>
<td><input type="text" size="20" name="pilotname" value="<? echo $applicant->applicant_name?>"></td>
</tr>
<tr>
<td><? echo $vusaf_id_prefix." ID"?></td>
<td><input type ="text" size="20" id="name" name="vusafid" value="<? echo $vusaf_id_prefix . $next_id?>"></td>
</tr>
<tr>
<td>Login</td>
<td><input type="text" size ="20" id="name" name="pilotlogin" value="<? echo $vusaf_id_prefix . $next_id?>"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" size="20" id="password" name="password" value="<? echo $generated_password?>"></td>
</tr>
<tr>
<td>Confirm Password</td>
<td><input type="text" size="20" id="password_confirm" name="password_confirm" value="<? echo $generated_password?>"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" size="20" id="email" name="pilotemail" value="<? echo $applicant->applicant_email?>"></td>
</tr>
<tr>
<td>Assign Rank</td>
<td><select name="pilotrank">
<OPTION VALUE="1">Second Lieutenant
<OPTION VALUE="2">First Lieutenant
<OPTION VALUE="3">Captain
<OPTION VALUE="4">Major
<OPTION VALUE="5">Lieutenant Colonel
<OPTION VALUE="6">Colonel
<OPTION VALUE="7">Brigadier General
<OPTION VALUE="8">Major General
<OPTION VALUE="9">Lieutenant General
<OPTION VALUE="10">General
<OPTION VALUE="11">General of the vUSAF
</></td>
</tr>
<tr>
<td>Acceptance Text</td>
<td><textarea rows="5" cols ="50" name="acceptance_text"><? echo $acceptance_text?></textarea></td>
</tr>
<tr>
<td></td><td><input type="checkbox" name="sendemail" id="sendemail" />Send email?</td>
</tr>
<tr></tr><tr>
<td><input type="submit" value="Create Pilot"></td>
</tr>
</table>
</form>
</div>
</div>

<?
include("footer.php");
?>

Arno_Adams

7:41 am on Jun 6, 2007 (gmt 0)

10+ Year Member



Hi,

I edited only the js:

<script type="text/javascript">
function checkForm(o){
var msg = "";
if(o.pilot_id.value == ""){
msg += "Reject this application... this pilot was not assigned an ID (auto index)\n";
}
if(o.pilot_flightversion.value == ""){
msg += "Reject this application... this pilot did not give a flight sim version\n";
}
if(o.pilot_country.value == ""){
msg += "Reject this application... this pilot did not supply their country\n";
}
if(o.pilot_vatsim.value == ""){
msg += "Reject this application... this pilot did not supply a VATSIM ID#\n";
}
if(o.pilotname.value == ""){
msg += "Please enter a name\n";
}
if(o.vusafid.value == ""){
msg += "Please enter a vUSAF ID# (vUSAF0001)\n";
}
if(o.pilotlogin.value == ""){
msg += "Please enter a login (vUSAF0001)\n";
}
if(o.password.value!= o.password_confirm.value ¦¦ o.password.value == ""){

msg += "Passwords do not match\n";
}
if(o.pilotemail.value == ""){
msg += "Please enter an email address\n";
}
if(o.pilotrank.value == ""){
msg += "Please select a rank to assign\n";
}
if(o.acceptance_text.value == ""){
msg += "Please type the acceptance text for the email to the pilot\n";
}
if(msg == ""){
return true;
}else{
alert(msg);
return false;
}
}
</script>

It still won't validate your form because the value from the selectbox will never be an empty string.
But I'm sure you can fix that yourself.

HTH, AA