Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: help!!!

  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation help!!!

    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!!!


    PHP Code:
    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");

    ?>
    Last edited by Spookster; 02-11-2006 at 03:33 AM.

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,073
    Thanks
    2
    Thanked 22 Times in 22 Posts
    You have several if statements with problems. The syntax for an if statement is as follows:

    PHP Code:
    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.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    The Netherlands, Baarn, Ut.
    Posts
    4,253
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Allowed, but...

    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).
    Regards,
    Ronald.
    ronaldvanderwijden.com

  • #5
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •