I use the Symfony2 form component to create a registration form and I just want to add a paragraph saying the user must understand terms of service above the submit button.
Should I create a ParagraphType and use it in the controller or override the submit button's block and add the paragraph in the template?
Neither of these suits me. Is there a better solution?
Thanks!
Without breaking the form into separate fields using form_widget for each field so you can inject a paragraph between the later part of the form and the submit button, you are restricted to using only form elements, meaning you can either create a special Form Type or use a form element. So under that logic, you can just make the "I understand the terms of service" a part of the form itself!
$builder->add('tos', 'checkbox', array(
'label' => 'I agree with the Terms of Service',
'required' => true,
));
Easy fix, just don't add submit button as field of form and manually render it in view. This way, you can add also some paragraph before it.
Related
I'm new to Concrete5 and have found a ton of information on adding contact forms, but only to the editable area of the page.
What I need to do is get a form into my page template. It's simply a name+email+submit button form to appear on every page for that template. On submission, a 'thanks' message... that's about it!
I've tried copy/pasting the code outputted into the page content to my default.php template but no luck with that. Thanks in advance for any help.
You should create a (global) editable area in the template, and then add a contact block to it just as you would otherwise.
E.g.:
<?php
$a = new GlobalArea('Contact Form');
$a->display();
?>
I agree with the other answer here... it's not worth the trouble to re-create a "hard-coded" contact form in your theme if you already have all the code working as a block. Here's a third technique you could use to achieve that -- you can hardcode just one block instead of the entire stack, like so:
<?php Block::getByName('My Global Contact Form')->display(); ?>
Put that code in your theme's template, and then add the contact form block to a stack in the dashboard (any stack, doesn't matter -- I usually create one stack of "global content" in my sites that I put all of these "hardcoded" blocks into). Then after you've added the block to the stack, click on the block and choose "Custom Template" from the popup menu. Then enter the block name into the field there (in this example, it would be "My Global Contact Form", without the quotes). Finally, click the "Approve Changes" button at the top of the stack.
You could approach this a couple of ways, but one way is to create a stack that has an contact form in it. Then, take the name of that stack and add it to your template.
So if the stack is called "Global Contact Form", then you could add the following to your template:
$stack = Stack::getByName('Global Contact Form');
if( $stack ) $stack->display();
I want to add Custom HTML ("Login" link near the "Register" button) in Register form with ZF 1.12.
When I do that with:
$submit = new Zend_Form_Element_Submit('register');
$submit->setDescription(" or <a href='auth/login'>Login</a>");
... then the link is placed in the next row, but I need it close to the "Register" button.
How can I implement it as simply as possible?
You have to create a custom form decorator for that. It is not that simple. If you have no other option then its better to create new decorator and add it to the form element. The ZF manual have a good documented section for that Creating Custom Form Markup Using Zend_Form_Decorator. This SO post will help too Insert custom HTML into Zend_Form.
there is also a quick workaround using javascript (if you are using jquery)
$(document).ready(function() {
$('#register').after(' or Login');
});
The description for the submit button, should surely be something more like:
'Activate button, to register.'
Arguably the login link isn't directly related to the form either. So I'd just place that text after the form.
<?php echo $form; ?>
<p>Or <a href='auth/login'>Login</a></p>
If you think the login link should always belong to the form, you could perhaps add it to the form description.
Is it possible to programatically disable form validation in MVC2?
I'm hoping there is some kind of command that I can put in a custom ActionMethodSelectorAttribute, making it possible to prefix ActionResults where I want form validation disabled.
The reason for this is that I have a form with multiple buttons, one button adds a new row to a child object of the model - which consequently creates a new row on the form.
This works fine, but validation is fired for the form each time "add" is pressed, and so the new fields flag up validation errors before the user has a chance to enter data.
I've found an alternative solution to this.
Rather than use multiple form buttons, I've used a custom html helper which produces a "Add" link.
This helper places the current Model in TempData and produces a Link to Add/{id}.
I'm not sure this is the cleanest solution, but it allows child elements to be added without validation firing. To tidy things up a bit, I specified the form as such:
Html.BeginForm(view, controller, new { id = Model.ID })
I am using the Zend Framework and have setup a normal Zend Form, what I want to try to achieve is to have a button (with some javascript) that says add more and it adds another drop down menu same as the one setup in the zend form (a clone of it).
basically when the button is clicked it adds another select box like so:
<select name="type[]"> ...</select>
I can do a copy of the multi select box with a different name and insert it in the DOM and catch the post from the controller outside of the Zend form but what I was wondering if there is a proper way to achieve this and be able to validate and populate the extra fields when editing a current data stored in db if there are any extra.. Any help is appreciated, thanks.
Well remember that in your controller if you have something like:
$this->form = new Form_Someform();
You can always do:
$this->form->addElement(etc...)
Right before using isValid() or populate.
So in your controller when someone submits the form, when creating your form object you could check if any select were created dynamicaly and then create corresponding Zend_Elements and just validate against that.
Also when you reload that form you just create elements depending on whats in your database.
You could also use the forms constructor to pass in an array of selectboxes and create then right there too. Thats what I do.
The important things to remember is that you have control on the constructor and on the form object between its creation and the use of the populate() and isValid() functions.
Hope this helps.
Is it possible to post the same form to different controllers?
Each page could be post only to form action url, but may be some how i may say to button to which url form should go?
e.g i have one form and two submit buttons, one button will post form to one controller/url (eg /action/view) anther button submit form to one to another controller/url (eg /action/anothervew).
You can definitely do this, use JQuery (or just javascript) to attach a function to the onclick event of the button(s). Then use that function to change the URL that the form posts to and then submit the form.
JQuery would be something like:
$('#button1').onclick(function(){ $(this).action = url1; $(document).submit();});
$('#button2').onclick(function(){ $(this).action = url2; $(document).submit();});
You will need to use javascript for this. When the button is clicked have the javascript modify the form's action property to the appropriate controller and then submit the form.
We've done this before using javascript, as mentioned in other answers, and that's probably the correct way to go. An alternative, however, is to post to a single controller method which contains logic to decide where to send the form data off to.
Effectively, you submit the form to the controller, and the resubmit that data based on the text or id of the button clicked using an if statement in the body of the controller action.