Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Custom Forms In Vanilla

2

Comments

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    By the way: I would name it "Suggest Category" and maybe add something like $Sender->InformMessage(T('Thanks for your submission!')); so that your user gets a feedback and doesn't send the form multiple times.

    Maybe it would be even better to only render the contact form if (!$Sender->Form->IsPostBack())

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited October 2014

    getting the validation messages to show up... because they just don't,

    That could be because the message should be enclosed in double quotes I think , also the message only shows if they don't fill it in and try to send.

    $Validation->ApplyRule('SubCategory', 'Required',"You must enter a Sub Category. This must be a new category that is not already available.");

  • Options
    peregrineperegrine MVP
    edited October 2014
     $Session = Gdn::Session();
    if ($Session->IsValid() ) {
    $Name = $Session->User->Name;
    $EmailAddress = $Session->User->Email;
    } else {
    return; // exit if not a valid user.
    }
    

    should be at the top of method, exit before you even begin doing things - if user not logged in

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    and don't put styles in your php.
    <li style="float: none;"><?php echo $this->Form->Label('Additional Info', 'Message').$this->Form->TextBox('Message', array('Multiline' => True))?></li>

    use css and classes.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    peregrineperegrine MVP
    edited October 2014

    put the contact.css in a Contact/design/contact.css folder in plugin.

    change the li sizes in contact.css

    various js removed, and simplified.

    just exit immediately. no need to test for valid session again in method,

    class ContactPlugin extends Gdn_Plugin{
    
        public function PluginController_Contact_Create($Sender){
    
                    $Session = Gdn::Session();
                   if (!$Session->IsValid() ) {
                    return;
                    }
    
                   $Name = $Session->User->Name;
                   $EmailAddress = $Session->User->Email;
    
                   $Sender->ClearCssFiles();
                   $Sender->AddCssFile('style.css');
                   $Sender->AddCssFile('contact.css', 'plugins/Contact');
                    // render a normal vanilla page
                       $Sender->MasterView = 'default';
    
    
                    $Sender->Form = Gdn::Factory('Form');
            $Email = new Gdn_Email();
    
    
            if($Sender->Form->IsPostBack() != False){
    

    ....

    change the render to

            $Sender->Render($this->GetView('contact.php'));
    }
    

    single vs double quotes in your addrules make absolutely no difference in your context.

    move contact.php into Contact/views/contact.php

    contact.php

        <?php if(!defined('APPLICATION')) die();?>
    
        <div class="ContactForm">
        <?php echo $this->Form->Open()?>
        <?php echo $this->Form->Errors()?>
        <h1><?php echo T('Contact')?></h1>
    
        <ul class="formtext" >
         <li><?php echo $this->Form->Label('Main Category (This may be a new or already existing main category)', 'MainCategory').$this->Form->TextBox('MainCategory')?></li>
        <li><?php echo $this->Form->Label('Sub Category (This must be a new category that is not already available)', 'SubCategory').$this->Form->TextBox('SubCategory')?></li>
        <li><?php echo $this->Form->Label('Additional Info', 'Message').$this->Form->TextBox('Message', array('Multiline' => True))?></li>
        </ul>
    
        <!--<div class="Center"></div>-->
        <?php echo $this->Form->Button('Send Message')?>
        <?php echo $this->Form->Close()?>
        </div>
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    You really should call the plugin something else and if it works , then upload it to the addons as

    CatChoice

  • Options
    peregrineperegrine MVP
    edited October 2014

    @vrijvlinder said:
    You really should call the plugin something else and if it works , then upload it to the addons as

    uploading a one-off plugin to add-ons, that is so esoteric, might be beyond the need. but it would be certainly be better to rename you self-made plugin for your own use. A generic suggestion form e-mail with a sample dropdown, checkbox, radiobutton, and text input might be more suitable, with definitions and translations for each form input.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited October 2014

    @peregrine said:
    uploading a one-off plugin to add-ons, that is so esoteric

    Guitar players generally are ....and unless that is George Benson in his avatar.... ;)

    A generic suggestion form e-mail to admin might be more suitable

    That is what Contact plugin is :D

    You can say this CatChoice is an extension of it...

  • Options

    @R_J said:
    Do you have something like that in your contact.php?

        <?= $Sender->Form->Open() ?>
        <?= $Sender->Form->Errors() ?>
    ...
        <?= $Sender->Form->Close() ?>
    

    You have to echo the forms errors.

    hey @R_J‌ I don't have this piece of code in my file... it's not in the original file either... where should I put this??

  • Options

    "Guitar players generally are" @vrijvlinder‌... LOL!!!

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    @AudioElements said:
    hey R_J‌ I don't have this piece of code in my file... it's not in the original file either... where should I put this??

    That is because it is in the contact.php the original file

    <?php if(!defined('APPLICATION')) die();
    // if div has class "AjaxForm" and there is a form in this div, the form will be ajax-posted
    $this->AddCssFile('contact.css', 'plugins/Contact');
    $this->AddJsFile('jquery.gardenhandleajaxform.js');
    ?>
    
    
    
    <div class="ContactForm AjaxForm">
    <?php echo $this->Form->Open()?>
    <?php echo $this->Form->Errors()?>
    <h1><?php echo T('Contact')?></h1>
    
    <ul>
        <li><?php echo $this->Form->Label('Your Name', 'YourName').$this->Form->TextBox('YourName')?></li>
        <li><?php echo $this->Form->Label('Your Email', 'YourEmail').$this->Form->TextBox('YourEmail')?></li>
        <li><?php echo $this->Form->Label('Message', 'Message').$this->Form->TextBox('Message', array('Multiline' => True)).$this->Form->Label('Check this if You Are Not a Bot').$this->Form->Radio('Checkbox')?></li>
    
    </ul>
    
    <!--<div class="Center"></div>-->
    <?php echo $this->Form->Button('Send Message')?>
    <?php echo $this->Form->Close()?>
    </div>
    
  • Options
    <?php echo $this->Form->Open()?>
    <?php echo $this->Form->Errors()?>
    

    yea i've got that... thought that was it for a sec... oops

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    Yes thats ok RJ is not familiar with the plugin an since we only posted the relevant code maybe he thought something was missing... no harm

  • Options

    Hi guys... I switched to the embed friendly theme to see if it was the theme that was the issue... doesn't seem so... when I hit the submit button, the ajax loading image shows up but it just keeps going on and never moves onto the error messages...

    i'm thinking that there might be an issue in this part the code... causing an infinite loop

    try{
                        $Email->Send();
                    }catch(Exception $Exception){
    
                        $Sender->Form->AddError(strip_tags($Exception->GetMessage()));
                    }
    
                    if($Sender->Form->ErrorCount() == 0){
                        $Sender->StatusMessage = T('Thank you for your feedback.');
                        $Sender->RedirectUrl = Url("/");
                    }
                }
    

    tell me what you think...

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited October 2014

    Did you add the email address in the dashboard ? remember this is sent to the support email you designate.
    This should go in the config.php

    $Configuration['Garden']['Email']['SupportAddress'] = 'Your email';

    $Configuration['Garden']['Email']['SupportName']= 'Name you want email to be addressed to';

    might as well add this too if you want html in emails to work

    $Configuration['Garden']['Email']['MimeType'] = 'text/html';

  • Options

    yes... i did set that email address.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    Well I know the plugin works because I use it. Is the email google gmail ? I heard that does not play well...

    The error message is only for the fields. Not to let you know something is wrong. If it sends, then you see a message that your email was sent. If no message that email was sent then that is the error. This has to do with your email set up I believe...

  • Options

    hmm... ok... it's actually an @outlook.com address... i'll try changing it

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    You should be able to use the email service from your host provider.

    So your email looks like this contact@yoursite.com Just create a special email for this that is sent from inside. Using external mail services does not always work because they block it and don't like to be used as a mail service for websites.

Sign In or Register to comment.