• Resolved VR Webs

    (@net4earning)


    i’m working on a form and added the below code but i’m geting this parse error, don’t know why
    “syntax error, unexpected ‘else'”

    add_action("gform_pre_submission_3", "pre_submission_handler");
    function pre_submission_handler($form_meta) {
      $saveVars = array("fname", "sname", "mail", "phone");
      foreach($form_meta["fields"] as $field) {
        if( $field["allowsPrepopulate"] ){
          if( is_array($field["inputs"]) ){
            foreach($field["inputs"] as $sub){
              $val = $_POST["input_" . str_replace(".", "_", $sub["id"])];
              setcookie("gf_".$sub["name"], $val, time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false, true);
          } else {
            $val = $_POST["input_" . $field["id"]];
            setcookie("gf_".$field["inputName"], $val, time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false, true);
          }
        }
      }
    }
    
Viewing 7 replies - 1 through 7 (of 7 total)
  • I’m not a developer, but there definitely seems to be a missing closing bracket } just before the else.

    remove the else and see if the error goes away or if another error appears
    ————————
    else {
    $val = $_POST[“input_” . $field[“id”]];
    setcookie(“gf_”.$field[“inputName”], $val, time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false, true);
    }
    ————————

    Thread Starter VR Webs

    (@net4earning)

    but there definitely seems to be a missing closing bracket

    added one,but still error is their

    Dion

    (@diondesigns)

    Then you added it in the wrong place. Look at your indentation…it’s very obvious where the closing brace is missing.

    count the { brackets, then count the } brackets – see if they match (btw, i already counted themand they matches)

    Thread Starter VR Webs

    (@net4earning)

    Thanks all,
    got it working

    so tell everyone what the issue was so that others can learn

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘syntax error, unexpected ‘else’’ is closed to new replies.