Wanda Embar Wanda Embar - 7 months ago 19
PHP Question

Dynamically changing form action

I'm trying to change the form action on the fly, but think I'm having a syntax problem, that I just can't figure out.

This works:

<?php
echo "<input type='submit' id='answerbutton' name='$buttonname'
value='$buttonvalue' onclick=\"this.form.action='linktogoto.php'\">";
?>


This doesn't work:

<?php
$variable = "linktogoto.php";
echo "<input type='submit' id='answerbutton' name='$buttonname'
value='$buttonvalue' onclick=\"this.form.action=$variable\">";
?>


I need to eventually change $variable depending on the situation, so need to get this to work.

Answer
<?php
$variable = "linktogoto.php";
echo "<input type='submit' id='answerbutton' name='$buttonname' 
value='$buttonvalue' onclick=\"this.form.action=$variable\">";
?>

Should be:

<?php
$variable = "linktogoto.php";
echo "<input type='submit' id='answerbutton' name='$buttonname' 
value='$buttonvalue' onclick=\"this.form.action='$variable'\">";
?>

Notice the ' around $variable.