Search

What is the best way to add a contact form on Symphony?

If you install the default workspace, there is an example of a contact form on the About page.

Thanks Bauhause

Ok, I've been looking at the example provided and well as the manual which seems abit outdated?

Here is how far I got before getting stuck.

1.) Created new Section called Contact Us with three fields, Name, Email, Contact 2.) Created new Event and chose Contact Us as Source. 3.) Applied the following code that was generrated:

<form method="post" action="" enctype="multipart/form-data">
  <input name="MAX_FILE_SIZE" type="hidden" value="5242880" />
  <label>name
    <input name="fields[name]" type="text" />
  </label>
  <label>email
    <input name="fields[email]" type="text" />
  </label>
  <label>message
    <textarea name="fields[message]" rows="15" cols="50"></textarea>
  </label>
  <input name="action[test]" type="submit" value="Submit" />
</form>

4.) The form does show up but I guess I am confused alittle in how all this works. The form really doesn't work exactly either..

Sorry folks, I know this is basics for some but it's such I am having hard time.

Don,t forget to attach your event to your page....

I did that... But not sure why it's not working.

You might want to add your page url with the ?debug to the end of the form. This way you can see what it's returning after submission. Something like this:

<form method="post" action="/contact?debug" enctype="multipart/form-data">

What is the name of your event? Is the name of the event Test? The name attribute of the submit input or button element must match the name of the event. So, if your contact form event is called Test, then the name attribute of the submit input will need to be action[test], using the Test string converted to the handle test.

But, if your event is called Save Message, the name attribute of the submit input will be action[save-message].

You did say that form was auto-generated, so it should work.

In the manifest/config.php file, you should see the following:

    ###### PUBLIC ######
    'public' => array(
        'display_event_xml_in_source' => 'no',
    ),
    ########

If you change no to yes, then you will be able to see the XML that the event is returning at the bottom of the source code for the page. (The XML is only displayed if you are logged in to the Symphony admin. Otherwise, the event data will not be displayed.)

    ###### PUBLIC ######
    'public' => array(
        'display_event_xml_in_source' => 'yes',
    ),
    ########

The event XML might look something like this, if you leave the fields blank and the fields have validation rules applied to them. (This XML is what is output by the form used by the default workspace.)

<!-- 
<events>
    <save-message result="error">
        <message>Entry encountered errors when saving.</message>
        <name label="Name" type="missing" message="‘Name’ is a required field." />
        <email label="Email" type="missing" message="‘Email’ is a required field." />
        <post-values>
            <subject>General Enquiry</subject>
        </post-values>
    </save-message>
</events>
 -->

As @Sanity11 mentioned, adding ?debug to the action attribute will display the XML with the Debug Devkit extension.

Are you able to view the XML?

thanks for feed back.

Just to be safe, I redid steps:

1.) Created a section called testing that has three required fields. 2.) created event that sources testing. 3.) in aboutus used the event called testing. 4.) testing generated the following:

<form action="" method="post">
    <fieldset>
      <label>Name <input type="text" name="fields[author]" value="" /></label>
      <label>Email <input type="text" name="fields[email]" value="" /></label>
      <label>Message <textarea name="fields[message]" rows="5" cols="21"></textarea></label>
      <input name="send-email[sender-email]" value="fields[email]" type="hidden" />
      <input name="send-email[sender-name]" value="fields[author]" type="hidden" />
      <input name="send-email[reply-to-email]" value="fields[email]" type="hidden" />
      <input name="send-email[reply-to-name]" value="fields[author]" type="hidden" />
      <input name="send-email[subject]" value="You are being contacted" type="hidden" />
      <input name="send-email[body]" value="fields[message]" type="hidden" />
      <input name="send-email[recipient]" value="fred" type="hidden" />
      <input id="submit" type="submit" name="action[save-contact-form]" value="Send" />
    </fieldset>
  </form>

5.) changed name="action[save-contact-form]" to name="action[testing]"

nothing happens when i hit submit on page.

Hmm. How are you testing the XML output? With the display_event_xml_in_source setting in the config.php file or the Debug Devkit? If the XML is not being output, then the event is not firing. If the event is not firing, it is either not attached to the page, or there is a PHP syntax error in the event file.

I think event is no firing... I did both... changed the config as well as did ?debug on the page.

I think I see the problem, you're submit button is named incorrectly, it is:

<input id="submit" type="submit" name="action[save-contact-form]" value="Send" />

It should be:

<input id="submit" type="submit" name="action[name-of-your-event-here]" value="Send" />

I tried both ways.

I'm not sure what else to suggest at this point. It's difficult to know what the problem is without some hands-on debugging. All we know at this point is that the event is not firing at all.

The first thing I would do is to start with something I know does work. Create a new Symphony install with the default workspace, and you'll be able to see how the frontend event works on the About page. You should be able to submit the form and view the XML. Try with empty values to see if validation is working. Then try filling in some field values and see what happens when the event fires successfully and an entry is created. If that works for you, then try to reproduce what works and modify it for you own specific requirements.

K thanks!

I know the about default wrks. It's not the default code. The code I use is the example on the event page so maybe I need to add some if/choose statements?

here is a piece of the default

<label>Name <input type="text" name="fields[author]" value="{events/save-comment/post-values/author}" /></label>

here is mine

> <input name="send-email[sender-email]"
> value="fields[email]" type="hidden" />

Do I need to add an xpath to the value field?

Bauhaus:

Are you able to view the XML?

what xml are we referring to?

ok i got it to wrk. Not sure what or why but it wrks...

First, you need to find out why the event is not firing. If the event is not firing and you cannot see the event XML, it doesn't matter what the values of the fields are. In fact, don't bother with anything else until you can get a form like this to return the event XML:

<form action="?debug" method="post">
    <fieldset>
        <input id="submit" type="submit" name="action[testing]" value="Test" />
    </fieldset>
</form>

This form cannot successfully create an entry, but it can fire the event and return the XML with the validation errors. If the event is not firing, you can't hope for anything else to happen.

So, the problem has got to be one of the following:

  • the form is not using the post method
  • the submit input is using the wrong value for the name attribute
  • the event is not attached to the page
  • the event PHP contains an error

So, before going any further, open up the event file created by Symphony. In the default workspace, the file is event.save_message.php. At the end of the file, there are two methods: the load() method and the __trigger() method. You should find a file called event.testing.php in the workspace/events directory that contains the following lines of code:

public function load(){
    if(isset($_POST['action']['testing'])) return $this->__trigger();
}

protected function __trigger(){
    include(TOOLKIT . '/events/event.section.php');
    return $result;
}

The $_POST array is a multi-dimensional array. The values need to correspond exactly with the value of the name attribute of the submit input. The PHP code is looking for a value in the $_POST array that matches this value:

$_POST['action']['testing']

So, the form needs to use the post method to submit the value of the name attribute:

name="action[testing]"

To test your event, you can use the print_r() function to print the human-readable information about the $_POST variable. So, you can insert a line at the beginning of the __trigger() method to output the values of the $_POST array when you click the submit button.

protected function __trigger(){
    print_r($_POST); die();
    include(TOOLKIT . '/events/event.section.php');
    return $result;
}

Now, when you click the submit button, you should see a white screen in the browser window, with the following (when you view the source code):

Array
(
    [action] => Array
        (
            [testing] => Test
        )

)

If you do not see this, then the event is not properly attached to the page or the name attribute is incorrect.

To make sure the event is properly attached to the page, you need to edit the page. For the default workspace, the About page looks something like this. Notice how the Save Message event is selected under Page Resources -> Events.

If the value of the name attribute of the submit button does not match, change that value to match.

So, let's see if we can first confirm that the event is firing properly before going any further.

It looks like I was too slow!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details