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.

Post Submission Trouble With Theme

  1. I'm having trouble adding a post_submission to my functions.php in my theme. I thought it might be a conflict with the theme itself, but I've switched to a simple theme and am encountering a similar problem.

    I've created a single Gravity Form and when I add this to my functions.php:

    add_action("gform_post_submission_1", "set_post_content", 10, 2);
    function set_post_content($entry, $form){
    //do nothing
    }

    I get an error. I've tried moving it around in the functions.php file to no avail. Is there a full example of a functions.php file that I can examine?

    I'm using WP version 3.2.1 and GF 1.5.2.8.

    Thanks,

    Brent

    Posted 12 years ago on Thursday August 18, 2011 | Permalink
  2. Looks like I got beyond that issue. Thanks!

    Brent

    Posted 12 years ago on Thursday August 18, 2011 | Permalink
  3. One thing to note: Not sure it is related but part of my WP site uses Exec PHP. As part of my troubleshooting I had disabled it. Problem still existed and then I re-enabled it and my code started working.

    Posted 12 years ago on Thursday August 18, 2011 | Permalink
  4. Very strange. So your code worked WITH Exec PHP activated but doesn't without it?

    Posted 12 years ago on Thursday August 18, 2011 | Permalink
  5. I don't think that is the issue. When I try to use any of the $entry values in my code, I get an error. I've tried to simplify it but it looks like when I reference the $entry, it blows out.

    At the moment I'm just trying to insert either the user $entry['created_by'] and/or a hidden form value $entry['1'] which would return the user name. Both of these values are to go into my custom table.

    Any thoughts?

    Posted 12 years ago on Thursday August 18, 2011 | Permalink
  6. Please post the actual code you're using in your functions.php.

    And can you share the error with us in its entirety? It will help with debugging. Thanks.

    Posted 12 years ago on Friday August 19, 2011 | Permalink
  7. In my functions.php, this code executes successfully (I've hidden my database info):

    add_action("gform_post_submission_1", "set_post_content", 10, 2);
    function set_post_content($entry, $form){
    	define("HOSTNAME","*****");
    	define("USERNAME","*****");
    	define("PASSWORD","*****");
    	define("DATABASE","*****");
    	$con = mysql_connect(HOSTNAME, USERNAME, PASSWORD);
    		if (!$con)
    		{
    			die('Could not connect: ' . mysql_error());
    		}
    		echo "do";
    		$sql="INSERT INTO user_items (user, item) VALUES ('1', '2')";
    		if (!mysql_query($sql,$con))
    		{
    			die('Error: ' . mysql_error());
    		}
    		mysql_close($con);}

    The form executes, my data gets entered, and my "do" is written to the form as expected. If I change the code to this:

    add_action("gform_post_submission_1", "set_post_content", 10, 2);
    function set_post_content($entry, $form){
    	define("HOSTNAME","*****");
    	define("USERNAME","*****");
    	define("PASSWORD","*****");
    	define("DATABASE","*****");
    	$con = mysql_connect(HOSTNAME, USERNAME, PASSWORD);
    		if (!$con)
    		{
    			die('Could not connect: ' . mysql_error());
    		}
    		echo "do";
    		$sql="INSERT INTO user_items (user, item) VALUES ($entry['created_by'], $entry['2'])";
    		if (!mysql_query($sql,$con))
    		{
    			die('Error: ' . mysql_error());
    		}
    		mysql_close($con);}

    I get this error or a variation of it:

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/63/6744963/html/wp-content/themes/CeCe3/functions.php on line 38

    The line number of the error generaly doesn't point to anything meaningful.

    Let me know if you need more info.

    Posted 12 years ago on Friday August 19, 2011 | Permalink
  8. I think you can do line 13 in your non-working example differently. Something like this:

    [php]
    $sql='INSERT INTO user_items (user, item) VALUES (' . $entry['created_by'] .','. $entry['2']. ')';

    Line 38 probably corresponds to line 13 as you pasted it here.

    Here's the nitty gritty on why that needs to be:
    http://php.net/manual/en/language.types.string.php#language.types.string.parsing

    Posted 12 years ago on Friday August 19, 2011 | Permalink
  9. Thanks. That got me the rest of the way. Hats off for auto-incrementing the file upload name if it already existed. I was going to write something to handle that.

    Brent

    Posted 12 years ago on Friday August 19, 2011 | Permalink
  10. Glad you got it worked out. Thanks for the update.

    Posted 12 years ago on Friday August 19, 2011 | Permalink

This topic has been resolved and has been closed to new replies.