Question

I am creating a form using Cake PHP. Is there any way to retrieve the basic HTML of the created form. For example,if we use Form Helper, we can create form using PHP itself. But now, I need only the html part of the created form for other use. Is it possible to retrieve it??

For example, say if I give input form like,

<?php
  echo $this->Form->create('User');
  echo $this->Form->input('email');
  echo $this->Form->end('Save');
?>

I need output like this

<form action="index.html">
<input type="email" />
<input type="submit" value="Save" />
</form>

I can even create seperate function for attaining this objective. But I would like to know, if there is any other method for achieving this output

Was it helpful?

Solution

you can store FormHelper output in a string variable

<?php
  $html_string = '';
  $html_string .= $this->Form->create('User');
  $html_string .= $this->Form->input('email');
  $html_string .= $this->Form->end('Save');


?>

and then use your string elsewhere. But I'm not sure this is what you're searching for.

OTHER TIPS

If I understand the question correctly, you want to use the form you created on another part of your site?

If that is the case, I would put the form itself in an Element and then call the Element wherever I wanted the form.

View/Elements/form.ctp
<?php
  echo $this->Form->create('User');
  echo $this->Form->input('email');
  echo $this->Form->end('Save');
?>

Then in any view on your site you can call the Element using:

<?php echo $this->element('form');?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top