1

I just don't see the problem. Need some new eyes to review it. Two files included test.php and test2.php to var_dump. Help!! Cut, Paste and Run - Thanks

test.php:
<?php
ini_set('error_reporting', E_ALL );
ini_set('display_errors', "1");
?>

<style type="text/css">
div.tabcontent{
  visibility: hidden;
  position:absolute;
  left:20px;
}
</style>

<script type="text/javascript">
  function switch_div(){
    val=document.form1.a_type.selectedIndex;
    if (val < 3){
      val="a0";
      data=document.getElementById("data_types").innerHTML+document.getElementById(val).innerHTML;
    }else if (val==3){
      val="a"+document.form1.a_type.selectedIndex;
      data=document.getElementById("data_types").innerHTML+document.getElementById(val).innerHTML;
    }else{
      val="a"+document.form1.a_type.selectedIndex;
      data=document.getElementById(val).innerHTML;
    }
    document.getElementById('anw_wksp').innerHTML=data;
  }
</script>

<html>
<body>
<form name="form1" action="test2.php" method="post" >
<table>
  <th >Enter Anwsers</th>
  <tr>
    <td>Anwser Type</td>
  </tr>
  <tr>
    <td><select name="a_type" onChange="switch_div()"/>
        <option value='radio'>radio</option>
        <option value='checkbox'>checkbox</option>
        <option value='select'>select</option>
        <option value='text'>text</option>
        <option value='textarea'>textarea</option>
      </select>
    </td>
  </tr>

      <div id="anw_wksp" style="border:1px solid gray; margin-bottom: 1em; padding: 10px">
      </div>
        <div id="data_types" class="tabcontent">
          <table>
          <th colspan="3">Data type</th>
            <tr><td>
            <input type="radio" name="a_data_type" value="text" selected>text<br>
            <input type="radio" name="a_data_type" value="int">int </td>
            </td>
          </tr>
          </table>
        </div>
        <div id="a0" class="tabcontent"> <!--radio/checkbox/select button-->
          <table>
            <th>Readable Anwser</th><th>DB Value</th><th>Default</th>
              <? $i=0;
                while($i < 10){
                  echo "<tr><td><input type=\"text\" name=\"a_r_$i\" /></td>
                      <td><input type=\"text\" name=\"a_db_$i\" /></td>
                       <td><input type=\"radio\" name=\"default\" value=\"$i\" /></td></tr>";
                  $i++;
                }
              ?>
          </table>
        </div>

        <div id="a3" class="tabcontent">
          <table>
            <th>Readable Anwser</th><th>DB Value</th><th>Default</th>
            <tr><td><input type="text" name="a_r_text"></td>
              <td><input type="text" name="a_db_text"></td>
              <td><input type="text" name="default_text" ></td></tr>
          </table>
        </div>

        <div id="a4" class="tabcontent">
          <table>
            <th>Readable Anwser</th><th>Default</th>
            <tr><td><input type="text" name="a_r_textarea"></td>
              <td><textarea name="default_textarea"  rows="5" cols="30"></textarea></td></tr>
          </table>
        </div>
    </td>
  </tr>
</td>
</tr>
  <tr>
  <td><input type="submit" value="Enter" name="submit">
  </td>
</table>
</form>
</body>
</html>


<script language="javascript">switch_div();</script>
-------------------------------------------------------------------

test2.php:

<?php

$data = file_get_contents('php://input');

if(empty($_SERVER['CONTENT_TYPE'])){

     $type = "application/x-www-form-urlencoded";

     $_SERVER['CONTENT_TYPE'] = $type;

}

print "_POST = <br />";
var_dump($_POST);
print "<br />";
print " DATA = <br />";
var_dump($data);

?>
2
  • You should only post the relevant code. Commented Jul 6, 2010 at 18:27
  • 4
    Where is your <head>? And why do you have <script> outside of <html>? ...on closer inspection, your document structure is possibly the worst I've ever seen. Commented Jul 6, 2010 at 18:27

3 Answers 3

5
  1. You don't have a <head>
  2. You can't have <script> tags outside of your <html>. Perhaps you want external JS files?
  3. You can't have <style> tags outside of your <html>. Perhaps you want external CSS files?
  4. Your scripts/styles, or their external <link>'s, should probably be inside your <head>
  5. You can't have <th> or <td> outside of a <tr>. Proper example.
  6. You don't declare a doctype.
  7. You can't have <div>'s randomly between table rows.
  8. Your method for echoing <tr>'s is, well, sloppy...

Instead of:

<? $i=0;
            while($i < 10){
              echo "<tr><td><input type=\"text\" name=\"a_r_$i\" /></td>
                  <td><input type=\"text\" name=\"a_db_$i\" /></td>
                   <td><input type=\"radio\" name=\"default\" value=\"$i\" /></td></tr>";
              $i++;
            }
          ?>

Consider something like:

<? for($i = 0; $i < 10; $i++) { ?>
    <tr>
        <td><input type="text" name="a_r_<?=$i?>" /></td>
        <td><input type="text" name="a_db_<?=$i?>" /></td>
        <td><input type="radio" name="default" value="<?=$i?>" /></td>
    </tr>
<? } ?>

Finally, to try debugging your problem, use a tool like Firebug for Chrome/Firefox to ensure you're submitting POST data as expected.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the -1, whoever that was. Feel free to justify.
It does not answer question asked? (It was not me who downvoted this).
@el.pescado: While it doesn't directly answer the question, I think it's useful to narrow the possibilities. +1
@el.pascado, I certainly didn't provide the answer, but IMHO, "answers" are just "helpful responses," which I believe this very much is. At some point I included a link to Firebug to help the OP solve the issue in question.
0

I know this is a lame answer but just want to throw it out there to make sure we aren't looking over the simplest things. Did you check the form tag in the html to make sure it is set to POST?

2 Comments

Now you post the html after I post my lame answer. :P
It was there before, it just wasn't formatted, and the tags were hidden.
0

I would recommend checking that the request method is in fact a post on the test2.php script.

<?php
if (strtolower($_SERVER["REQUEST_METHOD"]) == "post") {
    $data = file_get_contents('php://input');

    if(empty($_SERVER['CONTENT_TYPE'])){
        $type = "application/x-www-form-urlencoded";
        $_SERVER['CONTENT_TYPE'] = $type;
    }

    print "_POST = <br />";
    var_dump($_POST);
    print "<br />";
    print " DATA = <br />";
    var_dump($data);
}
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.