Viewed   113 times

When I use

<form method="post" enctype="text/plain" action="proc.php"> 

form data can not be sent to proc.php file properly. Why? What is the problem? Why I can't use text/plain encoding with post but I can use it with get method?

 Answers

1

[Revised]

The answer is, because PHP doesn't handle it (and it is not a bug):

https://bugs.php.net/bug.php?id=33741

Valid values for enctype in <form> tag are:

application/x-www-form-urlencoded
multipart/form-data

The first is the default, the second one you need only when you upload files.

@Alohci provided explanation why PHP doesn't populate $_POST array, but store the value inside a variable $HTTP_RAW_POST_DATA.

Example of what can go wrong with text/plain enctype:

file1.php:

<form method="post" enctype="text/plain" action="file2.php">
<textarea name="input1">abc
input2=def</textarea>
<input name="input2" value="ghi" />
<input type="submit">
</form>

file2.php:

<?php
print($HTTP_RAW_POST_DATA);
?>

Result:

input1=abc
input2=def
input2=ghi

No way to distinguish what is the value of input1 and input2 variables. It can be

  • input1=abcrninput2=def, input2=ghi, as well as
  • input1=abc, input2=defrninput2=ghi

No such problem when using the other two encodings mentioned before.

The difference between GET and POST:

  • in GET, the variables are part of URL and are present in URL as query string, therefore they must be URL-encoded (and they are, even if you write enctype="text/plain" - it just gets ignored by the browser; you can test it using Wireshark to sniff the request packets),
  • when sending POST, the variables are not part of URL, but are sent as the last header in HTTP request (POSTDATA), and you can choose whether you want to send them as text/plain or application/x-www-form-urlencoded, but the second one is the only non-ambiguous solution.
Tuesday, October 4, 2022
1

The good news is that PHP and JavaScript have a similar idea about what values are true and false.

  • An empty string will be false on both sides. A string with something in it (except 0 in PHP) will be true on both sides.
  • The number 0 will be false on both sides. All other numbers will be true on both sides.

Since the values of a form will always be strings, as Quentin pointed out in his answer, a good practice might be to use an empty string as false value and something else (e.g. 'true') as true value. But I think your way of using 0 and 1 and testing the numerical values is the safest approach because it isn't misleading. (When someone sees 'true' they might think 'false' would also be usable for a false value.

Saturday, August 20, 2022
1

This code is working. You need to add some condition, that checks, if $username is posted or not.

Something like that:

if(count($_POST)){
    $username ='';
    if(isset($_POST['user'])){
        $username = $_POST['user'];
    if ($username==null || !$username)
         echo 'username is null';
     echo strlen($username);
     echo $username;
   }

 }
Thursday, August 18, 2022
 
adnaan
 
5

Seems to be working just fine now:

https://jsfiddle.net/jphellemons/0ukbtgs4/

  • jQuery 3.1.1
  • jQuery ui 1.12.1

with your code:

<input type="email" id="tags" placeholder="Any Criteria">
<script type="text/javascript" src="external/jquery/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="external/jquery-ui/js/jquery-ui-1.12.1.min.js"></script>
<script>
  $(function() {
    var availableTags = ["ActionScript", "AppleScript", "Asp", "BASIC", "C", "C++", "Clojure", 
      "COBOL", "ColdFusion", "Erlang", "Fortran", "Groovy", "Haskell", "Java", "JavaScript",
      "Lisp", "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme"
    ];
    $("#tags").autocomplete({
      source: availableTags
    });
  });
</script>
Monday, October 17, 2022
 
ygalbel
 
3

Matlab matrices with more than 1 dimesion must have same number of elements for each value in one of the dimensions.

In your case, when fi is declared its dimension is 1x1. And you are trying to add 6 elements on the 2nd position of the first dimension. So, if that worked, you would end up with something like this: [[1],[a1 a2 a3 a4 a5 a6]]. But that is not allowed.

If you still want to do that, you may want to use a cell array. Which allows you to add different elements.

Here you have an example:

fi = {1}
fi{end+1} = 0.8*(V./T)

Notice that some functions like sum won't work on a cell array and you would have to do some conversions.

On the other hand if you expected to have a different output like this: [1 a1 a2 a3 a4 a5 a6] (like sugested on another answer). You may have different options including horzcat:

fi = horzcat([1],0.8*(V./T))
Friday, December 16, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :