I'm trying to enter a variable as the default value in a form within a phpbox.
I've had a look around and believe something like the following:
<INPUT id="sign_id" name="sign_id" type="hidden" value="<?php $sign_idtemp ?>"/>
should work, however this will not work within a phpbox due to the <?php ?>.
according to some threads I read here I out a ?> as the first line of the box and a <?php as the last and get the code to work, but I'm concerned this might make a mess of the rest of my code.
is there another way of getting this input to accept a variable's value as its default value.
I would use a php box and use
echo statements to output the html form elements. I wouldn't use the <?php and ?> syntax at all.
Quote
according to some threads I read here I out a ?> as the first line of the box and a <?php as the last and get the code to work, but I'm concerned this might make a mess of the rest of my code.
Well, it doesn't work now, so what do you have to lose? If you're concerned about it, copy your code into a text editor. If it messes things up, all you'll have to do is to paste the old code back in.
it is already within an echo statment, removing the rest of the form to just leave this bit it looks like:
echo '
<form action="index.php?page=' . $this_article_id . '" method="post">
<INPUT id="sign_id" name="sign_id" type="hidden" value=$sign_idtemp />
</form>
';
and $_POST['sign_id'] ends up with the its value as $sign_idtemp rather than the value of this variable.
if you can tell me whats wrong with the above I would be very grateful :)
The problem is that you're using ' as the quotation marks in your echo statment. You need to use " instead and escape the "s in your form. Example:
echo "
<form action=\"index.php?page=" . $this_article_id . "/\"method=\"post\">
<INPUT id=\"sign_id\" name=\"sign_id\" type=\"hidden\" value=$sign_idtemp />
</form>
";
Or you could use the same sytax as you use in the first line of your code:
echo '
<form action="index.php?page=' . $this_article_id . '" method="post">
<INPUT id="sign_id" name="sign_id" type="hidden" value=' . $sign_idtemp . '/>
</form>
';
Thank you very much... should have know after spending all this time looking it would be something that simple.
Now you point it out I even remember reading a guide that indicated that, just couldn't see my own error.
Again thanks for pointing it out.
No problem. Glad I could help. I've made similar errors myself. :-)