Link to home
Create AccountLog in
Avatar of i3d

asked on

How do I get PHP and wForms Switch to maintain field data when using history to navigate back?

I am using wForms in PHP with a form to display a field when someone picks a certain option from a pull-down select box.  Once the user hits "Submit" the browser is redirected to a new page.  Under certain circumstances, an alert message it generated with a Javascript command (window.history.go(-1); to return them to the previous page with the form.

Problem is, if anything was in the field following the wForms switch field, it is not retained in the form in history if the field driving the wForms field is set to anything other than the switch enabled choice.  Also, if the switch enabled choice was selected, when history navigates back to the form page, the enabled display box from the switch command is no longer enabled.

Does anyone know any way to keep the field data intact when using wForms switch and navigating back with history?

Here are code samples for the form page and the alert/back history page that demonstrate this.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" href="../style/wforms-jsonly.css" rel="alternate stylesheet" title="stylesheet activated by javascript" />
<script type="text/javascript" src="../modules/wforms_core.js" ></script>
<script type="text/javascript" src="../modules/wforms_switch.js" ></script>
// This is the page to generate the form
  echo "
    <form action=\"misc.php\" method=\"post\" name=\"formname\">
      Input A: <input size=\"25\" type=\"text\" name=\"inputa\" /><br />
      Input B: <select name=\"choice\">
        <option selected value=\"\">Select Option or Other</option>\n 
        <option value=\"other\" class=\"switch-a\" >Other</option>\n 
        <option value=\"optiona\">Option A</option>\n 
        <option value=\"optionb\">Option B</option>\n 
        <option value=\"optionc\">Option C</option>\n 
      <div class=\"offstate-a\">
        Other Option: <input size=\"25\" type=\"text\" name=\"option_other\"><br />
      </div><br />
      General Information<br />
        <textarea cols=\"50\" rows=\"4\" name=\"gen_desc\"></textarea><br /><br />
      <input type=\"Submit\" name=\"Submit\" value=\"Submit Form\">
// This is the page to generate the alert and cause the back history
    echo "<script language=\"javascript\" type=\"text/javascript\">
      alert(\"Return to previous page\");

Open in new window

Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account