Forum Moderators: coopster

Message Too Old, No Replies

php radio buttons

parsing using $HTTP_POST_VARS

         

ben_j

12:02 pm on Apr 16, 2003 (gmt 0)

10+ Year Member



I'm creating a code generator for WAP content. To test locally, the code needs to use the WAP Document Type Declaration at the top of the page, whereas to test on the server (that's running PHP) the code needs the PHP/WAP Document Type Declaration. I'd like to have the two options as radio buttons, but can't seem to get the values parsed from the input page to the output page because the DTD's contain characters used in php already.

I've tried using the alternative charcters generated by dreamweaver but to no avail.

any other ideas?

jatar_k

6:29 pm on Apr 16, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld ben_j,

What is happening with the script? Is it giving you an error? or is it just not getting the value from the radio button?

are you passing the whole DTD as the radio value?

ben_j

7:14 pm on Apr 16, 2003 (gmt 0)

10+ Year Member



I'd like to pass the whole dtd, but the code confuses itself by mistaking the 'value' for more bits of code. The net result is that nothing at all is shown when the WAP dtd is called and only a couple of slashes and qoutes and the word echo appear when the PHP/WAP dtd is called.

I guess what I'm asking is how do you parse php and/or xml code as a radio button value?

jatar_k

7:34 pm on Apr 16, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



There is a discussion here about displayinging HTML DTD [webmasterworld.com].

It may help you, not sure. I guess you can't just pass a value to the script and then the script can display the proper DTD based on that?

ben_j

10:53 am on Apr 17, 2003 (gmt 0)

10+ Year Member



thanks for that.

Oaf357 is basically trying to do what I am just with a different dtd. However, he didn't seem to find a working solution.

Coming back to what you said though, do you mean I could associate a value to the radio button (say value="wap") that would call an external script that would display the dtd?

and if so, how?

dmorison

11:19 am on Apr 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Ben,

I'd like to try and help but I can't really figure out from this thread or the one linked above what the problem is...!

When you call an external file with include(), the file is not interpretted by PHP unless it encounters the opening tag, such as <?php

I get the impression that you want to offer a way to select from a form which DTD the server should use for the response page. This should be straight forward:

On your form:

<select name='whichDTD'>
<option value='1'>DTD A</option>
<option value='2'>DTD B</option>
</select>

And then at the top of your handler script:

<?php

switch($whichDTD)
{
case '1':
include("dtdA.inc");
break;

case '2':
include("dtdB.inc");
break;
}

Where the files dtdA.inc and dtdB.inc are simple text files that contain nothing but the appropriate type declarations.

You could always just echo the DTD, there's no need to call an external file.

Have I missed the point?

Cheers

ben_j

12:49 pm on Apr 17, 2003 (gmt 0)

10+ Year Member



thanks dmorison,

I've tried your suggestion using the 2 code fragments you offered and recieved the following error messages:

When trying to submit with the WAP dtd it says:

Parse error: parse error in ../dtdA.inc on line 1

and when submitting using the WAP/PHP dtd it says:

Warning: Cannot add header information - headers already sent by (output started at ../testdisplay.php:12) in ../dtdB.inc on line 1

I believe this is still due to the fact that the text within the include is based in either xml or xml/php. I've tried setting the body of the include to 'test' to confirm that the call code is working and that all seems fine.

The problem is still that I am calling php code that is meant for pure display. How do I stop my response page from trying to interpret this data as more instruction?

ben_j

12:54 pm on Apr 17, 2003 (gmt 0)

10+ Year Member



Sorry, I've just worked it through again.

When I was adding the includes, I used the actual dtd as opposed to the alternative character versions. This meant that the include started with < as opposed to &lt; (which was exactly what you told me not to do).

I've now changed the include txt and it all works fine.

Many thanks to both of you, I am now a full convert to the power of webmasterworld!

Birdman

12:59 pm on Apr 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Moot point now :)

Hello,

Just had an idea for you to try. This way may work since you include the file while being out of PHP [php.net] parsing mode.

<?php
switch( [php.net]$whichDTD)
{
case '1':
?>
<!--#include virtual="dtdA.inc" -->
<?php
break;

case '2':
?>
<!--#include virtual="dtdB.inc" -->
<?php
break;
}
?>

dmorison

3:06 pm on Apr 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Ben,

Great! Glad that's sorted - and if it's working, don't touch it...

However, i'm still surprised that you have had to entity encode the characters in your include file.

From:

[php.net...]

I quote:

"When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags."

So i've got no idea what your PHP installation is doing! I fink it broke.

ben_j

5:34 pm on Apr 17, 2003 (gmt 0)

10+ Year Member



As the manual says "any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags."

My problem was I needed the target file to be display only and not executed at all. The idea being that when users see the response page they can copy and paste the results into a seperate document which will then be executed itself.

The ability to execute code from multiple include files gets me thinking though...

Many thanks for your help, Webmasterworld is now well in truly in my bookmarks list. I was a bit worried that some of the more educated members might drop on me for my lack of working knowledge, but you know what, you guys are ok.

Cheers all.

jatar_k

6:29 pm on Apr 17, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I was a bit worried that some of the more educated members might drop on me for my lack of working knowledge

It's a good community here and even the educated members need to ask questions. Everyone is very helpful and welcoming which is what gives WebmasterWorld it's charm.

Plus there are moderators to make sure there is no dropping on anyone, it being against TOS and all. ;)