10390 Posts in 2201 Topics by 1712 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1168 Views |
-
Adding attributes to a form

23 November 2009 at 10:50pm
Hi! I'm a newbie in silverstripe and I would just like to ask if how can i add an attribute in a form? For example i want to add onsubmit=''return false;" and class="myClass". Here is the function that I'm using:
public function NewsletterForm() {
$fields = new FieldSet(
new EmailField('Email','')
);$actions = new FieldSet(
new FormAction('NewsletterSubmit', 'Ok!')
);$validator = new RequiredFields('Email','onsubmit');
return new Form($this, 'NewsletterSubmit', $fields, $actions,$validator);
}/**
* Inserts a submitted email to database
* @param <type> $form
*/
public function NewsletterSubmit($form) {
$newsletter = new Newsletter();
$newsletter->Email=$_POST['Email'];
$newsletter->write();
return Director::redirectBack();//Director::redirect(Director::currentURLSegment()."?msg=Thank+you+for+signing+up!");
}Any help will be much appreciated. Thanks!
-
Re: Adding attributes to a form

24 November 2009 at 3:39pm Last edited: 24 November 2009 3:44pm
hello?is there anyone who knows the answer to my simple question?
it's like having this in form tag:
<form name="frmName" method="post" action="home/newsletterSubmit" class="myClass" onsubmit="return false;">
i just want to add class and onsubmit attributes in this form.
-
Re: Adding attributes to a form

24 November 2009 at 4:19pm
You should never mix javascript and HTML. Assign your event handlers unobtrusively in a javascript file.
$('#my-form').submit(function() {
// do stuff
return false;
}); -
Re: Adding attributes to a form

24 November 2009 at 4:34pm
If you need to customize your form, there's nothing forcing you to use the default form markup. That's just for quick rendering and prototyping, IMO.
<% control MyForm %>
<form $FormAttributes>
<div class="customStuff">
<% control Fields %>
$FieldHolder
<% end_control %>
</div><% control Actions %>
$FormHolder
<% end_control %>
</form>
| 1168 Views | ||
|
Page:
1
|
Go to Top |

