Ahmed-Anas
Ahmed-Anas

Reputation: 5619

Echoing a form from a string

I have an echo statement that is supposed to run a specific amount of times, i.e 'n' times, right now the function abc() is empty, for testing purposes, what I'm trying to to is this:-

echo "
<form  method=\"post\" action=\"<?php abc(); ?>\"  >
<input type='text' name='comment' style='width: 80%;height: 70px; margin-left: 60px' /> <br/>
<input type='submit' value='submit comment' style='margin-left:60px' />
</form>
";

but every time I click the button to submit the form I get the error

Forbidden

You don't have permission to access /< on this server.

If what I am trying to do isn't possible, is there an alternative way?

What I want to do is; create a button which, when clicked, calls a php function (which may or may not reload the page, doesn't really matter). There will be multiple functions created via a loop and for each loop iteration the values passed to the function will be different. By values, I don't mean variable types, I mean variable values will be different. I know there aren't any variables passed to the abc function at the moment, but like I said, abc function is for testing only to try to get past the forbidden error.

What I am actually trying to do is this..

$doubleinverted='"';
echo "
<form action=".$doubleinverted."<?php f_comment(".$row['ScrapId'].",'".$row1['Email']."');?>".$doubleinverted." method='post'>
<input type='text' name='comment' style='width: 80%;height: 70px; margin-left: 60px' /><br/>
<input type='submit' value='submit comment' style='margin-left:60px' />    
</form>
";

I know you can add inverted commas like \", but I just found that out.

Also, this echo statement will be in a loop and for each iteration, the values passed to the function will be different

Upvotes: 0

Views: 97

Answers (3)

pogeybait
pogeybait

Reputation: 3145

While you are at it, get rid of the confusing quote escaping. This reads more clearly...

<?php
    echo '<form  method="post" action="' . abc() . '">
    <input type="text" name="comment" style="width: 80%;height: 70px; margin-left: 60px" /> <br/>

    <input type="submit" value="submit comment" style="margin-left:60px" />

    </form>';
?>

Upvotes: 0

TaZ
TaZ

Reputation: 743

echo "
<form  method=\"post\" action=\"<?php abc(); ?>\"  >
<input type='text' name='comment' style='width: 80%;height: 70px; margin-left: 60px' /> <br/>

<input type='submit' value='submit comment' style='margin-left:60px' />

</form>

";

The action of the form is <?php abc(); ?> while you are already in PHP mode. I'm afraid I can't let you do that Dave!

Change the form to <form method=\"post\" action=\"' . abc() . '\" >

Upvotes: 0

Madara&#39;s Ghost
Madara&#39;s Ghost

Reputation: 174957

You cannot use PHP blocks inside of echo statements.

If f_comment echoes out a string, you should be doing something along the lines of:

echo "blah blah blah";
f_comment(...);
echo "more blah blah";

If it returns a value, store it in a variable or concatenate the string:

$string = "blah blah blah";
$string .= f_comment(...);
$string .= "more blah blah";

echo $string;

Upvotes: 3

Related Questions