I have created a text field. The label of field is "Height" and its name is "field_height". I have written some PHP script for this text field as follows.

<?php
$a
= $_POST['field_height'];
if (
$a = 100) {
  echo
"wowww";
}
else {
  echo
"alasss";
}
?>

But it doesn't show the required results to me. I am new to drupal and I am trying to learn how the code will work for custom created fields. Below are the screenshots of the codes and the output page. In the code it is clearly shown that if the value of the field is "100" print wowww, otherwise print "alasss" but unfortunately the output is only "wowww" regardless of the input in the "Height" field. Please assist me, is there any wrong I am doing?

Only local images are allowed.

Only local images are allowed.

Comments

Yes, you aren't doing a test,

Yes, you aren't doing a test, you are doing an assignment.

<?php
if ($a = 100) {
...
}
?>

The test will always be TRUE because you are giving $a the value of 100 and then testing it for a non-zero value. What you meant was:

<?php
if ($a == 100) {
...
}
?>

thanks for replying and yes I

thanks for replying and yes I knew about test and assignment and this was my mistake, but still it is showing the result of the ELSE block even I put 100 in the text field. Below is the code that I'm using.

<?php
$a
= $_POST['field_height'];
if (
$a == 100) {
  echo
"wowww";
}
else {
  echo
"alasss";
}
?>

It show the following messages.
This message is under the header or above title of article in red background color and borders.
Notice: Undefined index: field_height in eval() (line 2 of /home/a8874647/public_html/modules/php/php.module(80) : eval()'d code).

and this is the statement of ELSE block even I enter 100 in text field.
alasss

OK, well it's not really

OK, well it's not really clear exactly what you are trying to do, except that you are using the PHP module which is almost certainly a bad idea. The PHP you are entering is probably getting executed at some time other than when you expect it to be, hence the error.

If you want to understand how Forms and fields work you should take the time to study the Forms API and the associated examples here. http://api.drupal.org/api/examples/form_example!form_example.module/group/form_example/7

I agree. The code in question

I agree. The code in question is bypassing Drupal APIs altogether, which is why I didn't answer myself.

Though the answer as to why it's not working lies in what you said. Code that is inserted using the PHP module is called separately using eval(), and does not have access to POST values that have been submitted.

Jaypan We build websites

thanks

thanks for your reply, and now I'm reading the form api posts. But please write a PHP code for me (if you can) which works well, I need it now. Reading the form api tutorials will take some time, and I need the code urgently.

There's another place for

There's another place for such requests. http://drupal.org/paid-services

alfaguru!Thank you so much

alfaguru!
Thank you so much for providing me the API Tutorials.
After a 40 hours of research, hard-word and trying again and again, I've successfully found the solution. I used the following code and now it works well for me without any error messages and giving me right conditional results.

<?php
$a
= $_POST['field_height']['und'][0]['value'];
       if (
$a == 100) {
          echo
"wowww";
       }
       else {
          echo
"alasss";
       }
?>