PHP Entry Creation

By: Asheley Bailey | Asked: 10/07/2022
ForumsCategory: Code SnippetsPHP Entry Creation
Asheley Bailey asked 2 years ago
I'm trying to use the following code that is in the resource section. I'm linking it to an html button I already have in use, that creates a new post. When I use this code it does create an entry but it continuously creates one non-stop. I've tried using it twice and the last time it crashed my server because of the intense CPU spike. It creates an entry roughly every second. I've been using it with the Code Snippets plugin. What am I doing wrong? I only want one entry to be created when my action (button click) is triggered.    
 
<?php 
global $user_ID;
FrmEntry::create(array(
  'form_id' => 5, //change 5 to your form id
  'item_key' => 'entry', //change entry to a dynamic value if you would like
  'frm_user_id' => $user_ID, //change $user_ID to the id of the user of your choice (optional)
  'item_meta' => array(
    25 => 'value', //change 25 to your field ID and 'value' to your value
    26 => 'value',
    27 => 'value',
    //add any field ids here with the value to insert into it
  ),
));
?>


1 Answers
Best Answer
Rob LeVineRob LeVine answered 2 years ago
You need to put that code in a function and let it be called when you need it called.  As it is, it's going to get called all the time.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right