1
Peekay
Add Javascript Alert to XoopsFormButton?
  • 2010/5/8 22:40

  • Peekay

  • XOOPS is my life!

  • Posts: 2335

  • Since: 2004/11/20


I want to add some simple form validation with a javascript alert. I know how to do this with a conventional submit button, e.g.

onsubmit="javascript:return validate_my_form();"


however, the form I am editing uses the Xoops form-button object. This particular form submits to another file and simply making the fields required (true) does not seem to work.

The button code looks like this.

$search_form->addElement(new XoopsFormButton("""submit"_SEARCH"submit"), true);


I am no wiser about hacking the 'form' tag either

$search_form = new XoopsThemeForm(_MD_SEARCH"search""search.php?search=1");


Can anyone put me out of my misery and tell me how to trigger a JS alert for an empty field when the submit button is pressed?
A thread is for life. Not just for Christmas.

2
iHackCode
Re: Add Javascript Alert to XoopsFormButton?

try using setExtra.

ex:
$search_form->setExtra('onsubmit="javascript:return validate_my_form();"');


Quote:
Can anyone put me out of my misery and tell me how to trigger a JS alert for an empty field when the submit button is pressed?


i thought there was an option for each element if they are to be required or not when you enter them into the form object..
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

3
Peekay
Re: Add Javascript Alert to XoopsFormButton?
  • 2010/5/9 12:26

  • Peekay

  • XOOPS is my life!

  • Posts: 2335

  • Since: 2004/11/20


Thx for responding Bandit-X. Much appreciated.

I have discovered that the form I was working on had been given the same name as another search form in a block that was also visible on the page.

It appears that the name conflict stopped the button class validation from triggering.

I changed the names and it works now.
A thread is for life. Not just for Christmas.

Login

Who's Online

391 user(s) are online (265 user(s) are browsing Support Forums)


Members: 0


Guests: 391


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits