Jump to content

php / html question


knowram

Recommended Posts

Once again i am trying to do things that most don't do. I am trying to send a php variable from an html page imbedded in a check box value so that when it gets to the next page that is a php page it is read as a variable. Here is the code that i am trying so far.

On the HTML page

<input type="checkbox" name="checkbox5" value="'If no imiprovement in '.$Improve.' hours, you must be re-evaluated'"><input type="text" name="Improve" size="10">

An on the just a simple

echo $checkbox5;

on the php page.

This is what i get:

\'If no imiprovement in \'.$Improve.\' hours, you must be re-evaluated\'

dose anyone have any ideas?

Link to comment
Share on other sites

What do you want? If you need to output a variable outside PHP, you should use this:

[code]value="'If no imiprovement in '<?=$Improve?>' hours, you must be re-evaluated'"[/code]

Then, when retrieving it use stripslashes() to remove the backslashes that were added thanks to Magic Quotes:
[a href=\"http://www.php.net/stripslashes\" target=\"_blank\"]http://www.php.net/stripslashes[/a]
Link to comment
Share on other sites

That is what i was thinking would work but i could not remember the stripslashes() command. However it did not seem to work. now i am getting.

'If no imiprovement in '' hours, you must be re-evaluated'


Would it be better if i was going from a php page to another php page?
Link to comment
Share on other sites

Actually it won't work if you are using a HTML file (with .html or .htm extension) because the PHP doesn't parse it.

You must at least rename the page to something.php

Or edit the .htaccess and make the PHP interpreter go through .html files too.
But this could cause a potential performance hit, so it's not quite recommended.
Link to comment
Share on other sites

are you saying both pages need to be php or just the second page that is reading the variables?

I have tried it with both pages having a .php extension and also with the first page with the check box and text box as a html file and then going to a php file.
Link to comment
Share on other sites

All the pages with PHP should have .php extension.

Also, if you have a html page that just outputs $Improve it won't work if it's not defined.

If $Improve comes from somewhere else, it should be correctly passed to the page that outputs it.

(I hope you can understand what I'm saying).
Link to comment
Share on other sites

yeah that makes sense I know that $Improve is being passed properly because i can echo $Improve and get what I am looking for. I am just trying to imbed that into the checkbox so that all i have to do is echo the checkbox value and get both.

I was asking if there is a php function that allows you to do what I am trying to do. Because if there is I can make the form page a php page because right now it is just a html page.

the problem seems to be when the information is submitted form the html form page to the php page the <?=$Improve?> is not carried over.

dose that make sense at all?
Link to comment
Share on other sites

I replaced <?=$Improve?> with <?php var_dump($Improve); ?> on the html form page. and when I hit submit to get to the php page where I am trying to recall these variables there was still nothing where <?php var_dump($Improve); ?> was.
Link to comment
Share on other sites

So you are saying that both the form and the display page need to have a php extension. Okay I under stand that. The problem with that is that because the variable $Improve is established on the same page as the checkbox. there is nothing for the code <?=$Improve?> that is in the checkbox value to pull in. so it just puts a blank space in. What I am trying to do is put something in the checkbox value that will retrieve that variable $Improve on the next page after it has been established.


dose that make sense.
And I don't know if this is even posible.
Link to comment
Share on other sites

I am not understanding from where $Improve comes from.
If it's created in the same page as it's output, that's fine.
If you want it to be passed, that's fine; it will be passed by the form.
In this case I'd recommend you to use:

<input type="checkbox" name="whatever" value="<?= $variable ?>">

But if you want to retrieve $Improve, which comes from another page, you must pass it properly; by POST, GET, COOKIES, SESSION or whatever you may want to use.
Link to comment
Share on other sites

maybe it will help if i give you more of the code
Here is the relevant code from the form page which is a .php page

[code]
<html>
    <head>
        <title>Discharge</title>
        <form method=post action="../Print.php">
    </head>

<body>
<table width="800" border="1" cellspacing="0" cellpadding="0">
<tr>
    <td width="20"><input type="checkbox" name="checkbox5" value="'If no imiprovement in '<?=$Improve?>' hours, you must be re-evaluated in the Emergency Room or by your primary care doctor.'">
       </td>
    <td>If no imiprovement in <input type="text" name="Improve" size="10"> hours, you must be re-evaluated.</td>
</tr>
</table>
<input type="submit" name="Print" value="Print">
[/code]

This is what i have on the Print.php page

[code]
<?php
echo $checkbox5;
?>
[/code]

And this is what i get on the Print.php page.

'If no imiprovement in '' hours, you must be re-evaluated.'

do you see what i am trying to do? If it is not possible just let me know and I will try to come up with another way of doing it.

Link to comment
Share on other sites

Do you want people to be able to enter the hours?
In this case remove the checkbox:
[code]    <td>If no imiprovement in <input type="text" name="Improve" size="10"> hours, you must be re-evaluated...</td>[/code]

[b]Print.php[/b]

[code]<?php
echo $_REQUEST['Improve'];
?>[/code]

500th post [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
Link to comment
Share on other sites

The problem with that is that then only the hours that are typed into the text box are passed to the second page. And the reason that i am doing it this what is because depending on what happens earlier on the site the check box might be different.

Just tell me that what I am trying to do is impossible and I will give up.
Link to comment
Share on other sites

lets see if i can explain.

On the form page there is a checkbox next to this text.
If no improvement in "Text field" hours, you must be re-evaluated.

there is a check box there because they may not always need to use this line.

when it is read on the print page I have a if statement that checks to see if the checkbox has been checked and if so I would like it to write if no improvement in "what ever they put in the text box on the previous page" hours, you must be re-evaluated.

And I need all that to be stored in variables from the form page.

So if there is a what to splice to variables together at a point that would work or something like that. I don't know I am running out of ideas.

let me know if any of my explanations don't make sense.
Link to comment
Share on other sites

Now that we see some code, this makes even less sense unfortunately.

Firsly in the html code you posted:
You can't have the form opening tag in the HEAD of the file, it has to be in the body of the document (regardless of whether your version 'works').

Secondly in the same document, the $Improve isn't going to be assigned to the checkbox value because:
#1 - php only executes in php files, not html files (unless you're very clever with your server)
#2 - the value of $Improve is never provided to the page, so it couldn't appear anyway.

I guess from your immediately previous post you are relying on register_globals being ON - a poor practice.
Link to comment
Share on other sites

I guess what I trying to do is not possible.

Trying to imbed something into the value of a checkbox so that it will recall a variable on the next page when that checkbox value is recalled.

Anyway unless anyone has a different idea how to do this I will come up with something else. thanks everyone.

jacob
Link to comment
Share on other sites

[!--quoteo(post=379762:date=Jun 3 2006, 05:09 PM:name=knowram)--][div class=\'quotetop\']QUOTE(knowram @ Jun 3 2006, 05:09 PM) [snapback]379762[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I have worked around the problem so while not solved it is not needed any more.

thank you all for your help
[/quote]

Something to think about. What I do in these circumstances is to define the "Value" of my check box outside of the form tag and the call the variable in the Tag. Example:

$Text = "If no improvement in ".$Improve." hours then continue with text description here";

Then in the value section of your form tag use: Value = "<? echo $Text ?>"

Might help you...
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.