Forum Moderators: coopster

Message Too Old, No Replies

Problem with the Submit Button

         

Gian04

3:23 pm on Oct 11, 2007 (gmt 0)

10+ Year Member



I have a submit button that when clicked will open a different page (at the same time passing some hidden values).

The field value that will be pass to another page is retrieved from table and the value could be an HTML code.

But instead of just storing the value to the field (and just display only the button), it display the HTML output.

How can I solve this?

whoisgregg

3:50 pm on Oct 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think we'd need to see some sample code to be sure, but I think your problem is trying to pass html in the value="" of a hidden input? If so, you'll need to htmlentities [php.net] that html code when you echo it out then html_entity_decode [php.net] it when you need it.

echo '<input type="hidden" name="html" value="'. htmlentities($html, ENT_QUOTES) .'" />';

Gian04

3:55 pm on Oct 11, 2007 (gmt 0)

10+ Year Member



Here is the code

echo "<form action='anotherpage.php' method='post'>";
echo "<INPUT type='hidden' name='field1' value='$row[0]'>";
echo "<INPUT type='hidden' name='field2' value='$row[1]'>";
echo "</form>";

whoisgregg

4:44 pm on Oct 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yup, so you definitely need to run htmlentities. Otherwise, you could be putting <, >, =, ", and ' marks inside your value="" attribute and that's just gonna confuse any browser and server.

echo '<form action="anotherpage.php" method="post">'; 
echo '<INPUT type="hidden" name="field1" value="'.htmlentities($row[0], ENT_QUOTES).'">';
echo '<INPUT type="hidden" name="field2" value="'.htmlentities($row[1], ENT_QUOTES).'">';
echo '</form>';

That code should do the trick. On your next PHP script, you might need to run html_entity_decode on the $_POST['field1'] and $_POST['field2'] values.