1

now i made JavaScript code (jquery code) and when i click ok it return true if i want true and false if i want false

now the problem is php not consider true as php keyword true its just consider it a word like any other word and i must make it like this

if($post == 'true')

and i want make it like this

if($post) // retuen true if $post true

how i can do that and i use jquery function is() to send true or false to php

4
  • please provide your jquery code. Commented Mar 9, 2010 at 13:01
  • its not important my dear its general problem Commented Mar 9, 2010 at 13:02
  • send 0 for false and 1 for true Commented Mar 9, 2010 at 13:02
  • i mean how to convert java script true to php true Commented Mar 9, 2010 at 13:02

2 Answers 2

6

Javascript can only send values to serverside PHP via POST or GET. The data is always of type string - even numbers, although PHP being a typeless language, the difference is hardly noticeable. You should return 0 or 1 and typecast it to bool if you really need it. One way to force a value to bool is boolVariable = !! variable;

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

1 Comment

An alternative - you could return it as JSON using json_encode, I suppose, but that's a bit overkill.
2

Like Raveren said, you can't send integer, or boolean to PHP. All sent data is string, always. If you still want to use if ($post) and not if ($post == 'true') then use switch

switch($post)
{
    case "true":
        $post = true;
        break;
    case "false":
        $post = false;
        break;
}

if ($post) {
    ...
}

no other way to do it

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.