1

I've searched the web and have come up with nothing. (Multiple search engines too - I have looked!)

I'm trying to have a text link as the 'form submit' button. Any ideas if this is possible in CakePHP?

Current view code below!

<?php
        echo $this->Form->create('trainees', array(
                'action' => 'reassign'
        ));
        echo $this->Form->input('emailaddress', array(
                'value' => 'scott@something',
                'type' => 'hidden',
        ));
        echo $this->Form->submit('Re-Assign Mentor', array(
                'class' => 'submit mid',
                'before' => '<p>',
                'after' => '</p>'
        ));
        echo $this->Form->end();
?>
2
  • Why are you trying to do this? Can't you just use CSS to make the button look like a link? It's not possible to submit a form using a link without some JavaScript. Commented May 17, 2013 at 18:09
  • CakePHP is still just PHP (which boils down to HTML/Javascript/CSS...etc). Should rephrase your question to "how to submit an HTML form with an anchor tag" or something like that. Commented May 17, 2013 at 18:19

1 Answer 1

2

You need to use the HtmlHelper to output a link. In it's simplest form you use the text you want displayed with the URL that it should link to. In this case it will be JavaScript:

$this->Html->link('Submit Form', 'javascript:document.forms["myform"].submit();');

There are two additional parameters (a $options array and $confirmMessage boolean), but they along with the URL are optional.

You can also call your own JavaScript function if you need to do client side verification and call the submit function from there (also verify on the server as clients can lie).

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::link

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.