How To Add PHP Function as UDT?

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
FCazabon
Forum Members
Forum Members
Posts: 165
Joined: Fri Nov 07, 2008 5:28 pm

How To Add PHP Function as UDT?

Post by FCazabon »

Hi,

I'm adding a form to a page like this:



So I want to include the checkForm function in the page so I have created a UDF called CheckForm and defined it like this:

function checkForm(RememberMeForm)
{
    //For First Name
    if (!(RememberMeForm.rem_firstname.value))
    {
        alert("Please enter a First Name")
        RememberMeForm.rem_firstname.focus()
        return false
    }//End Of First Name

    //For Surname
    if (!(RememberMeForm.rem_surname.value))
    {
        alert("Please enter a Surname")
        RememberMeForm.rem_surname.focus()
        return false
    }//End Of First Name

}//End Of Function

But when I submit this for saving I get this error message:

Invalid code entered.
Parse error: syntax error, unexpected ')', expecting '&' or T_VARIABLE in /home/www/arrivealivett.com/admin/adduserplugin.php(100) : eval()'d code on line 1

Basically, I want to validate the input on a form and then run a php script to update a database.  What am I doing wrong here?

Thanks for any help
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: How To Add PHP Function as UDT?

Post by Wishbone »

The example you gave is JavaScript, not PHP.
FCazabon
Forum Members
Forum Members
Posts: 165
Joined: Fri Nov 07, 2008 5:28 pm

Re: How To Add PHP Function as UDT?

Post by FCazabon »

Of course! I just assumed it was PHP because it was in a PHP file.  So how can I include this javascript code in my CMSMS page?
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: How To Add PHP Function as UDT?

Post by Wishbone »

Put it in your template, usually in the . Wrap {literal} {/literal} around your JavaScript code so that the curly braces doesn't interfere with Smarty processing.
FCazabon
Forum Members
Forum Members
Posts: 165
Joined: Fri Nov 07, 2008 5:28 pm

Re: How To Add PHP Function as UDT?

Post by FCazabon »

Thanks, I've actually just been putting it in the "Smarty data or logic that is specific to this page:" for the specific page and it appears to work that way.  Is this way OK as the code is only specific to this one page?
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: How To Add PHP Function as UDT?

Post by jmcgin51 »

yes, that is fine (at least it's always worked for me)

You could also put it in your template, but surrounded by a conditional so that it only runs if the template is rendering with a certain page_alias.
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: How To Add PHP Function as UDT?

Post by Wishbone »

How does putting JavaScript in the Smarty Data field work?
Post Reply

Return to “The Lounge”