4

How I can set button type as input tag in symfony2?

<input type="submit" id="id_submit" name="click to go next" class="submit"></input>

using symfony2 formType as public function buildForm(FormBuilderInterface $builder, array $options) {

    $builder

    ->add('submit', 'button',array('attr' => array('class'=>'submit','type'=>'input')))
    ;
}

As it shows

<button type="submit" id="ponemonSurvey_submit" name="click here to go" class="submit"></input>
1
  • I want this behavior <input type="submit" id="id_submit" name="click to go next" class="submit"></input> rathen than <button type="submit" id="ponemonSurvey_submit" name="click here to go" class="submit"></input> Commented Jan 30, 2014 at 9:15

2 Answers 2

1

If you want to add button to your forms, you can use the inputType submit (symfony2.3 and more) Documentation

$builder->add('save', 'submit', array(
    'attr' => array('class' => 'submit'),
    'label' => "click to go next"
));

You have also the reset and button inputType.

button html tag is more recommended than input tag, it's more flexible (you can use an image as a button for example).

If you really want a <input type="submit" rather than <button type="submit", you can add your own inputType to symfony as descripted there in the cookbook

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

5 Comments

I want this behavior <input type="submit" id="id_submit" name="click to go next" class="submit"></input> rathen than <button type="submit" id="ponemonSurvey_submit" name="click here to go" class="submit"></input>
Thanks for your response, but your tag also showing me <button> tag in html, not <input> tag
Check my link to see the difference between the two of them. The button tag is more recommended than the input one, button is more flexible. stackoverflow.com/questions/3543615/…
You are correct, but still I need to define input tag as submit in formtype. I dont want to show button tag as submit.
Kindly help me if you know how I can define <input type="submit"> in my formType.
1

From Symfony 2.3 and so on (doesn't work on earlier versions):

$builder->add('save', 'submit', array(
                'label' => 'Click to go next',
                'attr' => array(
                    'class' => 'the_class_you_want',
                )));

The Submit button has an additional method isClicked() that lets you check whether this button was used to submit the form. This is especially useful when a form has multiple submit buttons:

if ($form->get('save')->isClicked()) {
    // ...
}

Tip: you shouldn't put "click to go next" in the name attribute. This attribute is not aimed to receive human readable text. Use the 'label' option instead, like I wrote above.

Note: you can't change the css id attribute of an input in the FormBuilder. To do that, you have to use the template.

4 Comments

I want this behavior <input type="submit" id="id_submit" name="click to go next" class="submit"></input> rathen than <button type="submit" id="ponemonSurvey_submit" name="click here to go" class="submit"></input>
See my edit. The first code area indicates what you want to do. And you can't change an id attribute in the FormBuilder (see last note in my answer).
Kindly help me if you know how I can define <input type="submit"> in my formType.
@AliHassan well this is just what I did, dude... If you can't read it's not my fault.

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.