Zend Framework: How to add custom html to Form Element? - zend-framework

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.

Related

Polymer: manually submitting a form

In polymer I'm trying to manually submit a form. My form looks like this:
<form id="myForm" on-submit="{{ submitForm }}">
<input class="text" value="{{ someValue}}">
<button type="submit">Submit</button>
</form>
And in the polymer object I have:
submitForm: function(e) {
e.preventDefault();
}
Whenever I try to do the following:
document.getElementById('myForm').submit();
the form totally ignores the on-submit attribute and posts the form to a new page.
I'm building a on-screen keyboard for anyone wondering why I would want to do this. I need to submit the form whenever someone hits the enter key on the on-screen keyboard.
Does anyone know why this happens?
A JSBin example to show you the exact problem (see the alerts): http://jsbin.com/wadihija/2/
From the MDN page about submit:
The form's onsubmit event handler will not be triggered when invoking this
method ... it is not guaranteed to be invoked by HTML user agents.
However, calling click on a submit type button seems to work. See here:
http://jsbin.com/tuxac/2/edit
Here is a modification of your jsbin that I believe does what you want:
http://jsbin.com/wadihija/6/edit
Is this along the lines of what you're trying to do? This is a result of a key feature of Shadow DOM: Encapsulation. The elements in your polymer-element's template are not in the main document, and as such, are not available via document.getElementById() and the like.
You could instead call this.shadowRoot.getElementById() and it would work because this inside of your polymer-element's prototype is linked to the host element. Or even better, take advantage of the amazing features Polymer gives you for free. Polymer exposes this.$ to polymer-elements, which contains a key for every element in your template that has an ID! No method call needed, just use this.$.myForm.submit(). Here's the final jsbin.

How to reset form after form submitting?

I have one search form with search button and some field, when I put value in form field and click on search button then come back on form by clicking on link(modify search form) then form value does not reset...Please check it here(http://dev.viawebgroup.com/search/)
Thanks
Try this:
<script>
function test(){
var input = document.getElementById('search');
input.value = '';
};
</script>
Add onload to the body:
<button onclick="test()">Clear</button>
Add id to input field:
<input type="text" id="search">
Fatal flaw rests form befor data is sent
The simplest way I found is
onsubmit="this.reset()"
Just put this in the form tag and all's well, simple yet efective.
I someone wanted a button excluesivly for form reset I would use onclick and write the reset in a function like this.
function clform()
{
documentgetElementById('myform').reset();
}
The first is tried and true, the second I just wrote but should work.
The function works well used in a onbeforeunload event in the body.
I have been working on this problem my self because the page I wrote is dynamically updated and was keeping form data when back button of browser was used. I also used PHP to reload the page after submission and onfocus to reload the page when form is selected so input is on a fresh page and not the dynamically updated page.

How to add a basic signup form to a Concrete5 page template

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();

nyroModal v2: How to validate form opened in iframe?

I'm trying to figure out how to validate a form opened using nyroModal.
The page is being opened as below on click of a button:
$(function() {
$('.btnedit').click(function() {
$.nmManual('form_page.php);
});
});
On the form that opens up, I have a few fields that are mandatory and a cancel & submit button.
<a class="nyroModalClose button" href="#" id="btn_submit">Submit</a>
On clicking of the submit button, I want to make sure the mandatory fields have value. If no, an error message should be displayed & the modal window should not close.
I'm trying to use the jquery validation plugin, but without success. The modal window always closes irrespective of the validation scripts.
I haven't found much info regarding form validation in a modal window. Is this not a preferred approach?
Thanks in advance.
I'm not able to help you about the jquery validation plugin in a modal window, but I know that using the instruction $.nmManual in that way, the form will not be placed inside the iframe tag, and if I remember correctly the content of new page will be added without header and body tags, so in a word incorrectly. I guess this can produce no validation.
To successfully open an iframe you need to use filters as described here:
Open iframe manually in nyroModal?
I hope this can help you.

MVC submit form to different controllers

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.