TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,911
  • Total Topics: 21,307
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 818
  • Total: 818

Prepopulating a form with variables in a phpbox.

Started by Sunbringer, January 07, 2008, 05:27:24 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Sunbringer

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.

JPDeni

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.

Sunbringer

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 :)

JPDeni

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>
';

Sunbringer

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.

JPDeni

No problem. Glad I could help. I've made similar errors myself. :-)

This website is proudly hosted on Crocweb Cloud Website Hosting.