Title: syntax error, unexpected &#8216;else&#8217;
Last modified: May 25, 2022

---

# syntax error, unexpected ‘else’

 *  Resolved [VR Webs](https://wordpress.org/support/users/net4earning/)
 * (@net4earning)
 * [4 years ago](https://wordpress.org/support/topic/syntax-error-unexpected-else/)
 * 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)

 *  [George Appiah](https://wordpress.org/support/users/gappiah/)
 * (@gappiah)
 * [4 years ago](https://wordpress.org/support/topic/syntax-error-unexpected-else/#post-15677965)
 * I’m not a developer, but there definitely seems to be a missing closing bracket`}`
   just before the `else`.
 *  [pattycake](https://wordpress.org/support/users/pattycake/)
 * (@pattycake)
 * [4 years ago](https://wordpress.org/support/topic/syntax-error-unexpected-else/#post-15677983)
 * 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](https://wordpress.org/support/users/net4earning/)
 * (@net4earning)
 * [4 years ago](https://wordpress.org/support/topic/syntax-error-unexpected-else/#post-15678677)
 * >  but there definitely seems to be a missing closing bracket
 * added one,but still error is their
 *  [Dion](https://wordpress.org/support/users/diondesigns/)
 * (@diondesigns)
 * [4 years ago](https://wordpress.org/support/topic/syntax-error-unexpected-else/#post-15678896)
 * Then you added it in the wrong place. Look at your indentation…it’s very obvious
   where the closing brace is missing.
 *  [pattycake](https://wordpress.org/support/users/pattycake/)
 * (@pattycake)
 * [4 years ago](https://wordpress.org/support/topic/syntax-error-unexpected-else/#post-15679635)
 * count the { brackets, then count the } brackets – see if they match (btw, i already
   counted themand they matches)
 *  Thread Starter [VR Webs](https://wordpress.org/support/users/net4earning/)
 * (@net4earning)
 * [4 years ago](https://wordpress.org/support/topic/syntax-error-unexpected-else/#post-15679988)
 * Thanks all,
    got it working
 *  [pattycake](https://wordpress.org/support/users/pattycake/)
 * (@pattycake)
 * [4 years ago](https://wordpress.org/support/topic/syntax-error-unexpected-else/#post-15680110)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 4 participants
 * Last reply from: [pattycake](https://wordpress.org/support/users/pattycake/)
 * Last activity: [4 years ago](https://wordpress.org/support/topic/syntax-error-unexpected-else/#post-15680110)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
