Which Action Hook To Use
-
I have a piece of code (below) that sends a form submission to the CRM database that we use. In my previous theme I had placed it at the bottom of the funtions.php file. My thought is that I can enable the correct action hook and then use the PHP Code Widget to place this code where it needs to be. I have tried different action hooks, but can’t find one that will work. Anyone know where this should go?
Thanks,
Vittorio
//ZOHO WEB TO LEAD FORM
function post_to_crm($entry, $form){
if($form["id"] != 2) //NOTE: replace 3 with your form id
return;
?>
<form method="post" action="https://crm.zoho.com/crm/WebToLeadForm"
name="form_to_crm" id="form_to_crm">
<input type="hidden" name="First Name" value="<?php echo $entry["4.3"] ?>" />
<input type="hidden" name="Last Name" value="<?php echo $entry["4.6"] ?>" />
<input type="hidden" name="Email" value="<?php echo $entry["7"] ?>" />
<input type="hidden" name="Phone" value="<?php echo $entry["14"] ?>" />
<input type="hidden" name="LEADCF1" value="<?php echo $entry["10.1"] ?>" />
<input type="hidden" name="LEADCF2" value="<?php echo $entry["10.3"] ?>" />
<input type="hidden" name="LEADCF3" value="<?php echo $entry["10.4"] ?>" />
<input type="hidden" name="LEADCF8" value="<?php echo $entry["10.5"] ?>" />
<input type="hidden" name="LEADCF4" value="<?php echo $entry["8"] ?>" />
<input type="hidden" name="LEADCF5" value="<?php echo $entry["11"] ?>" />
<input type="hidden" name="LEADCF7" value="<?php echo $entry["12"] ?>" />
<input type="hidden" name="LEADCF6" value="<?php echo $entry["13"] ?>" />
<input name="xnQsjsdp" type="hidden" value=" /" />
<input name="xmIwtLD" type="hidden" value=" /" />
<input name="actionType" type="hidden" value=" /" />
</form>
<script type="text/javascript">
document.getElementById("form_to_crm").submit();
</script>
<?php
}
add_action("gform_post_submission", "post_to_crm", 10, 2);Mod
Is this something that should go in the
<head>part of your html? In that case, try hooking it to thewp_head()action hook, via your child theme’s functions file. (A good tutorial is here: http://www.nathanrice.net/blog/an-introduction-to-wordpress-action-hooks/ )The reason this is not working by attaching it to any of the hooks in the theme is that the code above is only executed when a hook called
gform_post_submissionis fired (theadd_action()call at the end). I suspect that this happens before the graphene hooks are fired so you are attaching your code after the event that is supposed to trigger it.It would be possible to rewrite the above function to work but the problem is that it is passed two parameters, one of which
$entrycontains all the data to put into your form. Somewhere in your themedo_action ('gform_post_submission'...)is being called which currently generates the form. I don’t think the graphene hooks can be passed parameter. I would suggest unless you know where the data is comming from you leave your code alone.If it is being hooked successfully from functions.php there seems little point making it theme dependent.
I hope this helps
Jon
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
