...

View Full Version : help!!!



shru
02-10-2006, 07:42 AM
hi every1...im having a crazy time with an error in php code...that basically is a form that is vlidated and mailed...heres my code ...the error i get is parse erroe, Unexpected T_ELSEIF...any ideas?>.....thanks itll be highly appreciated!!!




if ($_POST["submitted"])
$valid = validated();
else
$valid = true;

if ( !$_POST["submitted"] || !$valid ) :

?>
<h1>Installers Report<?php if (!$valid):?> &mdash; please revise<?php endif;?></h1>

<p>
Please provide the installation report in the form below.The Link Quality Section will have values that have been implemented on the Client's Unit.
</p>

<?php if (!$valid):?>
<p style="color: red;">
The form that you submitted contained invalid entries. Please
make sure that you provide all mandatory information.
</p>
<?php endif;?>

<form action="<?=$self?>" method="post" name="Installers_report" id="Installers_report">
<?php

foreach($FormFields as $fieldset => $fieldsetcontent)
{

echo " <fieldset>\n <legend>" . $fieldset . "</legend>\n <table>\n";

foreach($fieldsetcontent as $fieldid => $fieldcontent)
{

echo " <tr>\n";
echo " <th>" . $fieldcontent["label"] . "</th>\n";

if ($fieldcontent["type"] == "text")
{

if ($valid)
$contstr = "";
else
$contstr = "value=\"" . htmlentities($_POST[$fieldid]) . "\" ";

echo " <td><input type=\"text\" name=\"" . $fieldid . "\" id=\"" .
$fieldid . "\" " . $contstr . "/></td>\n";

}

else if ($fieldcontent["type"] == "select")
{

echo " <td>\n <select name=\"" . $fieldid . "\" id=\"" .
$fieldid . "\">\n";

foreach ($fieldcontent["valuemap"] as $val => $label)
{

if ($val == "selected")
continue;

if ($valid && $val == $fieldcontent["valuemap"]["selected"])
$selstr = " selected=\"selected\"";
else if (!$valid && $val == $_POST[$fieldid])
$selstr = " selected=\"selected\"";
else
$selstr = "";

echo " <option value=\"" . $val . "\"" . $selstr . ">" . $label . "</option>\n";
}

echo " </select>\n </td>\n";

}

else if ($fieldcontent["type"] == "textarea")
{

if ($valid)
$contstr = "";
else
$contstr = htmlentities($_POST[$fieldid]);


echo " <td><textarea name=\"" . $fieldid . "\" id=\"" .
$fieldid . "\">" . $contstr . "</textarea></td>\n";

}

?>
<td id="<?=$fieldid ?>_Valid" class="off">
<span class="valid">OK!</span>
<span class="invalid">Entry invalid!</span>
</td>
<?php
echo " </tr>\n";

}

echo " </table>\n </fieldset>\n";

}

?>

<p>
<input type="submit" value="Submit!" />

<input type="hidden" name="submitted" id="submitted" value="true" />
</p>

</form>
<?php


/* The second branch is the preview of a submitted, valid form,
which is then offered for actual submission:
*/

elseif ( !$_POST["committed"] ) :

?>
<h1>Installation Report received and validated tentatively.</h1>

<p>
Please review the data and submit it if it is correct,
otherwise use the &ldquo;back&rdquo;-button of your
browser to return to the form.
</p>

<table>
<tbody>
<?php

foreach($FormFields as $fieldset => $fieldsetcontent)
foreach($fieldsetcontent as $fieldid => $fieldcontent)
{
echo " <tr>\n";
echo " <th>" . $fieldcontent["label"] . "</th>\n";
echo " <td>" . htmlentities($_POST[$fieldid]) . "</td>\n";
echo " </tr>\n";
}
?>
</tbody>
</table>

<form method="post" action="<?=$self ?>">
<p>
<?php
foreach($FormFields as $fieldset => $fieldsetcontent)
foreach($fieldsetcontent as $fieldid => $fieldcontent)
{
echo " <input type=\"hidden\" name=\"" . $fieldid .
"\" id=\"" . $k . "\" value=\"" . htmlentities($_POST[$fieldid]) . "\" />\n";
}
?>
<input type="hidden" name="submitted" id="submitted" value="true" />
<input type="hidden" name="committed" id="committed" value="true" />
<input type="submit" value="Submit" />
</p>
</form>
<?php


/* Lastly, the final branch takes a valid form that has been
confirmed for submission and emails it away.
*/

else:

/* We must still check that the form is valid! */
if (!validated()) die("Invalid form committed!");

foreach($FormFields as $fieldset => $fieldsetcontent)
foreach($fieldsetcontent as $fieldid => $fieldcontent)
$output .= $fieldid . "\t" . $fieldcontent["label"] . "\t" . $_POST[$fieldid] . "\n";

?>
<h1>Report received and stored!</h1>
<p>Thank you and goodbye.</p>
<pre><?=htmlentities($output)?></pre>
<?php

$message[1]["content_type"] = "text/plain; charset=iso-8859-1";
$message[1]["filename"] = "";
$message[1]["no_base64"] = true;
$message[1]["data"] = "Dear KDN operator, please find attached a submitted Installation Report.";

$message[2]["content_type"] = "text/plain; charset=iso-8859-1";
$message[2]["filename"] = "InstallationReport_plain.txt";
$message[2]["data"] = $output;

$message[3]["content_type"] = "text/plain; charset=iso-8859-1";
$message[3]["filename"] = "InstallationReport_texed.tex";
$message[3]["data"] = $output;

$mailout = mp_new_message($message);
mail($mailrecipient, "[Installation Report]",
$mailout[0],
"From: KDN Installation Report Interface <nomail@noserver.null>\n" . $mailout[1]);
echo " <p>The above data was sent to KDN.</p>\n";

endif;



/* It's over! */

@require_once("footer.inc");

?>

raf
02-10-2006, 07:44 AM
Welcome here!

please read are postingguidelines regarding titles --> http://www.codingforums.com/postguide.htm
please help us help you by enclosing your code in php-tags and by specifying the linenumber for the error + higlighting that line.

vinyl-junkie
02-10-2006, 12:17 PM
You have several if statements with problems. The syntax for an if statement is as follows:


if (some condition) {
// do something here
} else {
// do something else here
}
Note the opening and closing curly brackets. Fix that and you should be quite a bit further down the road. Also, please do what raf said and wrap your code in the appropriate tags, as I have done here. :)

ronaldb66
02-10-2006, 01:17 PM
The bracket-less form is allowed when there are only one-line statements, but the bracket form in my opinion is much clearer, certainly when if...else's are nested.

Indentation also helps a lot in finding nesting errors (which you seem to encounter).

MRMAN
02-10-2006, 01:25 PM
Ok.
I'd do two things to your code. If you do these then you might be able to find the problem yourself.
the first thing i would to is use one format and stick to it. For example you have three different ways you write your if statments. you use { } : and none.
Now there is no problem in this it just makes it harder to see what is happening and where it is happening. I user { } all the time as i have been brought up on it.
The second thing i would to is indent your code. I know when you paste it in here the indentation goes crazy so i don't know if you do. But indentation will help you see if you have one to many open or close braces
example:



if($name == "MRMAN")
{
print "your great have $500";
}
else
{
print "Smile the day is nearly over";
}

if($drink == "booze")
{
if($booze == "vodka")
{
$drink = "all of it";
}
else
{
$drink = "Some of it";
}
}



Another thing i think you maight have done (but its hard to tell) is put the else statments in the wrong order.
it should go
if
ifelse
else

and i think you might have
if
else
elseif

hope this helps
MRMAN

edit: bugger my post got beaten by ronaldb66. i did start typing before the messge above got posted. honest



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum