What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    How to delete submissions with JotForm-Api-PHP?

    Asked by commedia on July 12, 2017 at 04:22 AM

    Hi all! I need your help because I can't delete submissions.

    I read all my submissions and update my database with them. This goes right!

    But after my insert into table I try to delete it with

    $result = $jotformAPI->deleteSubmission($id_submissions); print $result;

    and I get this error: Invalid API key or Unauthorized API call

    Can you tell me why?

    Thank you

    Pat

     

    This is my code:

    try {

    include "jotform-api-php/JotForm.php";

    $jotformAPI = new JotForm("*********");

    $submissions = $jotformAPI->getFormSubmissions('*****');

    $referenze_trovate = count($submissions);

    for ($i=0; $i < $referenze_trovate; $i++) {

    $id_submissions = $submissions[$i]['id'];

    echo $id_submissions;

    foreach ($submissions[$i]['answers'] as $key) {

    foreach ($key as $key1 => $value1) {

    ...........

    $sql = "INSERT INTO utenti ($fields) VALUES (\"$values\") ON DUPLICATE KEY UPDATE ". $daUpdate;

    // campi da aggiornare

    if ($risultato = mysql_query($sql)) { // INSERT OR UPDATE OK

    $result = $jotformAPI->deleteSubmission($id_submissions);

    print $result ."<br>";
    ...................

  • Profile Image
    JotForm Support

    Answered by candy on July 12, 2017 at 07:03 AM

    Dear Pat,

    We are sorry for the inconvenience you have. 

    Please find the following guide in order to have further detailed information regarding sending/updating submissions in MySQL database: https://www.jotform.com/help/126-How-to-send-Submissions-to-Your-MySQL-Database-Using-PHP 

    Maybe, you can try to create new API key as you can see in the following guide: https://www.jotform.com/help/253-How-to-create-a-JotForm-API-key 

    Please try and if you need further assistance, let us know.

  • Profile Image

    Answered by commedia on July 12, 2017 at 07:52 AM

    Thank you Candy, but I have only the problem when I try to delete my submission with

    $result = $jotformAPI->deleteSubmission($id_submissions);

    Upadate and Insert are ok

    Bye

    Pat

  • Profile Image
    JotForm Support

    Answered by candy on July 12, 2017 at 09:28 AM

    Dear Pat, 

    Please find the example code below from our API guide that deletes the last 50 submissions:

    <?php
    try
    {
    include "jotform-api-php/JotForm.php";

    $jotformAPI = new JotForm("YOUR API KEY");
    $submissions $jotformAPI->getSubmissions(050nullnull);
    foreach($submissions as $submission)
    {
    $result $jotformAPI->deleteSubmission($submission["id"]);
    print $result;
    }
    }

    catch(
    Exception $e)
    {
    var_dump($e->getMessage());
    }

    ?>

    I hope this helps.

  • Profile Image

    Answered by commedia on July 13, 2017 at 06:26 AM

    Hi Candy! My code shoud be correct:

    $latestFormID = ***;

            $submissions = $jotformAPI->getFormSubmissions(***);

            foreach($submissions as $submission)
    {
    var_dump($submission['id']);    // this is ok!  I get the right id
    $result = $jotformAPI->deleteSubmission($submission["id"]);
    print $result;

    }

    print = Invalid API key or Unauthorized API call

    Bye

    Pat

  • Profile Image
    JotForm Support

    Answered by jonathan on July 13, 2017 at 09:49 AM

    Pat,

    If you are having difficulty making your PHP code work to auto delete form submissions, you may also want to check out Auto Delete Submissions app.

     

    Let us know if this app is not applicable to what you require.

     

  • Profile Image

    Answered by commedia on July 14, 2017 at 07:55 AM

    Hi!

    I can't delete new form submissions instantly as soon as they are received. Before it I must

    insert it into my DB table.

    Thanks

    Pat

  • Profile Image
    JotForm Support

    Answered by jonathan on July 14, 2017 at 09:16 AM

    Can you also share to us your full PHP code. You can paste the code here so that we can test it on our form also.

    We will wait for your updated response.

  • Profile Image

    Answered by commedia on July 17, 2017 at 07:27 AM
  • Profile Image
    JotForm Support

    Answered by jonathan on July 17, 2017 at 08:41 AM

    Hi Pat,

    Thank you for providing the requested details. I was able to get your PHP codes.

    Allow me some more time to try it on my test environment. I'll update you here as soon as I can.

  • Profile Image

    Answered by commedia on July 26, 2017 at 05:37 AM

    Hi! Is these any news about my problem?

    Thank you very much!

    Pat

  • Profile Image
    JotForm Support

    Answered by ashwin_d on July 26, 2017 at 08:35 AM

    Hello Pat,

    Your message has reached my colleague @jonathan. Unfortunately he is currently not available online. I have sent message to him and he will get back to you as soon as he is back online.

    Thank you!