0

I have a some.php with some php processing which also has:

<form action="" method="post">
<input type="text" name="name" value="bleh" />
<input type="submit" name="submit" value="submit" />
</form>

I also have other.php with some jquery script:

<h1>form goes here</h1>
<script>
$("h1").replaceWith(" <?php include ('some.php'); ?> ");
</script>

The thing is... the replaceWith function is not working because apparently the include is replaced with the form with its spaces and line breaks which has in the some.php file. I tried trim before the include but it did not work.

How can I solve it if I want to keep the form in some.php with that format and line breaks (as opposed to making it one-liner)?

PeterC
  • 1

1 Answers1

0

You could write the include to a hidden textarea and read it from there:

<textarea id="formhtml" style="display:none;"><?php include ('some.php'); ?></textarea>

And then replace the h1:

$("h1").replaceWith($("#formhtml").html());
roberkules
  • 6,557
  • 2
  • 44
  • 52