PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Site broken while adding Gravity code to functions.php

  1. Parse error: syntax error, unexpected '<' in /home/content/31/8674631/html/sf/wp-content/themes/canvas/functions.php on line 98

    I've been working on this since 3:30am, and I've just done something to break my entire site. I'm not a developer. And right now I'm shaking with stress.

    I was trying to create a form Confirmation page using the sample code provided here:

    http://www.gravityhelp.com/documentation/page/Gform_pre_render

    I copied the code for the 2-page form example, and pasted it into the functions.php file of my theme (Canvas, by Woo Themes).

    I was very careful! I'm not a developer and I didn't TOUCH anything in the functions.php file except paste the code into the custom area.

    Steps:

    1. I was working on the form located on this page:

    http://shepherdsfinance.com/sf/address-or-contact-change-form/

    2. I copied and pasted the example code into functions.php. I removed the start and end php from the example code. I specifed the form ID (15) and the field ID (93) of the HTML field on my second page. Saved.

    3. Then I went to my contact form, filled it out, and clicked Next. The confirmation page displayed the Previous and Send buttons, but no field entries.

    4. I thought maybe I'd made a mistake by removing the start/end php tags from the example, so I pasted them back in.

    Saved. And got the error at the top of this message.

    5. I went back to functions.php and removed the start/end php tags from the Gravity example. Saved. Same error.

    6. I deleted the Gravity example code. Saved. Still getting the error.

    7. Pasted in the original code for functions.php. Saved. Still the error.

    There is only one '<' in the entire file: at the beginning. What does the parser want?

    I have no idea what to do! And I would really appreciate any help or suggestions ASAP!!! This site is being reviewed by the attorneys and partners today, and it is totally broken.

    TIA,

    Mary

    Posted 9 years ago on Thursday May 24, 2012 | Permalink
  2. Whew. Thank god for backups. I managed to restore my website by uploading a backup copy of the Canvas theme's functions.php file. It's the same backup copy code I tried to past into the WordPress Editor, but copy/paste didn't work. Is that a common problem in WordPress?

    I'd still like to be able to create a confirmation page but I think I'll look for another solution than that example code.

    Best,
    Mary

    Posted 9 years ago on Thursday May 24, 2012 | Permalink
  3. tcs
    Member

    Yes - The site seems to be running ok when I just clicked on your form link.

    Posted 9 years ago on Thursday May 24, 2012 | Permalink
  4. David Peralty

    You don't need to re-open PHP in your Functions.php file if PHP is already open. Basically you don't need the <?php or ?> if your functions already has it in there. That could cause the error you had.

    I would have to see exactly what you pasted in your functions.php file to better understand what caused the error though.

    Posted 9 years ago on Thursday May 24, 2012 | Permalink
  5. First, thanks both of you for replying, probably over your first cup of coffee.

    David - Here's the code I pasted into the Canvas theme functions.php:

    http://pastebin.com/faTqr5TM

    I changed the IDs of the form and the second page html field to match those of my address form. The form test didn't work (i.e., there were no fields visible on the second page after I clicked Next.

    I thought maybe I should add the open/close php because they are part of the documentation example. (I used to be a tech writer and I notice these things...)

    I'm not a developer but I've been developing websites by hand and in WordPress for years. My Inner User intuition is that the problem is actually with the WordPress editor. It's not a real text editor, and my source code seems to become corrupted really easily when I'm working in the html view of posts and pages.

    The parser error was for the '<' character. Maybe I introduced some corruption to the underlying text when I added the open/close php, saved it, and then removed it again?

    To be honest, I should have made a backup copy of the file before I started working on it. But I was working carefully inside the section of the functions.php provided for custom code, and didn't think I could break anything. Boy did I learn a hard lesson!

    What a shattering experience; I'm scarred for life. I'll never touch the functions.php on a wordpress website without making a backup copy first again as long as I live.

    So the lessons today, ladies and gentlemen, are:

    1. Backup: FTP, Export Tool, MySQL -- everything. Regularly.
    2. Test instances are our friends.
    3. Backups are our friends.
    4. Don't assume the characters you see in a wordpress editor are what they appear to be. (I guess everyone else already knows this and I'm just learning it the hard way.)
    5. Backup. There's a plugin for that and I think it's time to start using it.

    Thanks once again for your support, I really appreciate it.

    Posted 9 years ago on Thursday May 24, 2012 | Permalink
  6. David Peralty

    That is a great looking functions.php file. :) I always recommend people edit files on their computers rather than through WordPress, but not all people have that option. Let us know if you have any other issues.

    Posted 9 years ago on Thursday May 24, 2012 | Permalink