Jump to content

[SOLVED] self processing form field won't keep it's value


carlpj51

Recommended Posts

    When a user makes an error in one of my self processing forms and the form is returned back to them for corrections, one of the fields won't remember the posted value. 

    The form is written as a function and is called by the processing page.

When I upload the script, the form field displays properly but on resubmit (with errors) it remains unselected.

 

The part of the form I'm having a problem with is highlighted in red:

 

]<html>

<!-- step222222222222222222222222222222222222222222222222222222 -->

    <p><sub><img src="/tt_image/step2.gif" alt="step 2" />

    </sub>&#160;&#160;Select Asset ID/Location:

 

    <?php

 

    //

    //GENERATE & EXECUTE QUERY

 

    $asloc_sql = "SELECT worklocation_id, worklocation_description FROM

    work_location_info ORDER BY worklocation_id DESC";

    $asloc_result = mysql_query($asloc_sql) or die (mysql_error());

    if (!$asloc_result) {

echo "An Error occurred connecting to Database!";

    } else {

echo "<SELECT name=\"assetlocation[]\">

 

<OPTION

value=\"\"> --- Select Asset ID/Location --- </OPTION>";

 

while ($row = mysql_fetch_array($asloc_result)) {

    $wl_id = $row["worklocation_id"];

    $wl_des = $row["worklocation_description"];

   

    if ($row == $_POST['assetlocation'])  {

        echo "<OPTION value=\"$wl_id-$wl_des\"

selected>$wl_id-$wl_desc</OPTION>";

    } else {

echo "<OPTION value=\"$wl_id-$wl_des\">

$wl_id-$wl_des</OPTION>";

    }

}

 

echo "</SELECT>";

    }

    ?>

    </p>

</html>

 

[/color]

 

 

Thank you for helping!!!

Link to comment
Share on other sites

I took out the [] in the html as you suggested also placed the echo in as follows:

 

 

 

 

echo "<SELECT name=\"assetlocation\">

<OPTION

value=\"\"> --- Select Asset ID/Location --- </OPTION>";

while ($row = mysql_fetch_array($asloc_result)) {

    $wl_id = $row["worklocation_id"];

    $wl_des = $row["worklocation_description"];

 

echo "$wl_id-$wl_des | {$_POST['assetlocation']}";    

    if (("$wl_des-$wl_id") == $_POST['assetlocation'])  {

        echo "<OPTION value=\"$wl_id-$wl_des\"

selected>$wl_id-$wl_desc</OPTION>";

    } else {

echo "<OPTION value=\"$wl_id-$wl_des\">

$wl_id-$wl_des</OPTION>";

    }

}

 

....and still no luck

Link to comment
Share on other sites

I got field to partially work by taking out the [] in the SELECT statement, also made sure the variables $wl_id-$wl_des were in the correct order.  So now on resubmit with errors, I get the drop down menu to show the location id but still no location description.....Still working on it.  Thanks for the help!

Link to comment
Share on other sites

I thank you DarkWater for all your help!  I found another small error which was preventing the location description from printing on the error resubmit page.  Thanks Again!

 

 

if (("$wl_des-$wl_id") == $_POST['assetlocation'])  {

          echo "<OPTION value=\"$wl_id-$wl_des\"

      selected>$wl_id-$wl_desc</OPTION>";

      } else {

      echo "<OPTION value=\"$wl_id-$wl_des\">

      $wl_id-$wl_des</OPTION>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.