{"id":2240,"date":"2025-12-04T11:49:58","date_gmt":"2025-12-04T11:49:58","guid":{"rendered":"https:\/\/iadv.shop\/?page_id=2240"},"modified":"2025-12-06T12:27:03","modified_gmt":"2025-12-06T12:27:03","slug":"companys-valuation-report-2","status":"publish","type":"page","link":"https:\/\/iadv.shop\/index.php\/companys-valuation-report-2\/","title":{"rendered":"Company&#8217;s Valuation Report"},"content":{"rendered":"\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\" \/>\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\" \/>\n<title>Company Valuation | India Advocacy<\/title>\n\n<!-- Fonts & Icons -->\n<link href=\"https:\/\/fonts.googleapis.com\/css2?family=Inter:wght@400;500;600;700&#038;display=swap\" rel=\"stylesheet\">\n<link href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/font-awesome\/6.4.0\/css\/all.min.css\" rel=\"stylesheet\">\n\n<!-- jQuery -->\n<script src=\"https:\/\/code.jquery.com\/jquery-3.6.0.min.js\"><\/script>\n\n<style>\n\/* (your CSS kept unchanged except minor helpers) *\/\n.entry-title, .is-content-justification-space-between { display: none !important; }\n\/* ... (rest of your CSS omitted here for brevity in this snippet) ... *\/\n<\/style>\n<\/head>\n<body>\n<div id=\"ipad-panel\">\n  <div class=\"logo-container\">\n    <img decoding=\"async\" src=\"https:\/\/indiaadvocacy.in\/wp-content\/uploads\/2024\/02\/logo.png\" alt=\"Company Logo\">\n  <\/div>\n\n  <!-- your form HTML (unchanged from the non-working code you pasted earlier) -->\n  <!-- Ensure this form has id=\"valuationForm\" and file inputs with id=\"financialFile\" and id=\"capFile\" -->\n  <!-- (Paste your full form HTML here exactly as in your non-working page) -->\n  <!-- For brevity I'm assuming you keep the form markup you already provided earlier. -->\n  <!-- ... existing form markup ... -->\n\n<\/div>\n\n<script>\njQuery(document).ready(function($) {\n  \/\/ ---------- config ----------\n  var runLegacy = false; \/\/ set true only if you intentionally need legacy POST create_ticket\n  var endpointUrl = 'https:\/\/iadv.shop\/forms\/process.php';\n\n  \/\/ ---------- utility: wrap spans ----------\n  function wrapSpans() {\n    $('span.msf-h3').each(function() {\n      if (!$(this).parent().is('p')) $(this).wrap('<p><\/p>');\n    });\n  }\n  wrapSpans();\n  var observer = new MutationObserver(wrapSpans);\n  observer.observe(document.body, { childList: true, subtree: true });\n\n  \/\/ ---------- form & UI state ----------\n  var $form = $('#valuationForm');\n  var $sections = $form.find('section');\n  var currentIndex = 0;\n  var totalSteps = $sections.length;\n  var $stepCounter = $('#stepCounter');\n  var $progressFill = $('#progressFill');\n  var $prevBtn = $('#prevBtn');\n  var $nextBtn = $('#nextBtn');\n\n  function showStep(index) {\n    $sections.hide().eq(index).show();\n    currentIndex = index;\n    $stepCounter.text(index + 1);\n    var pct = Math.round((index \/ (totalSteps - 1)) * 100);\n    $progressFill.css('width', pct + '%');\n    $prevBtn.prop('disabled', index === 0).attr('aria-disabled', index === 0 ? 'true' : 'false');\n    if (index === totalSteps - 1) $nextBtn.html('Get Valuation <i class=\"fa-solid fa-check\" style=\"margin-left:8px\"><\/i>');\n    else $nextBtn.html('Next Step <i class=\"fa-solid fa-arrow-right\" style=\"margin-left:8px\"><\/i>');\n  }\n\n  \/\/ ---------- validation helpers (identical logic to your working page) ----------\n  function patternTest(el) {\n    var $el = $(el);\n    var val = ($el.val() || '').toString().trim();\n    if ($el.prop('required')) {\n      if ($el.is(':checkbox')) return $el.is(':checked');\n      if ($el.is('select')) return val !== '';\n      if (val === '') return false;\n    }\n    if ($el.attr('type') === 'email' && val !== '') return \/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$\/.test(val);\n    if ($el.attr('type') === 'tel' && val !== '') return \/^\\d{10}$\/.test(val.replace(\/\\s+\/g,'')); \n    if ($el.attr('type') === 'number' && $el.attr('min')) {\n      var min = parseFloat($el.attr('min') || '0');\n      return Number(val) >= min;\n    }\n    return true;\n  }\n\n  function validateCurrent() {\n    var valid = true;\n    var $panel = $sections.eq(currentIndex);\n    $panel.find('input, textarea, select').each(function() {\n      var ok = patternTest(this);\n      var $wrap = $(this).closest('.field');\n      if (!ok) { $wrap.addClass('has-error'); valid = false; } else { $wrap.removeClass('has-error'); }\n    });\n    if (currentIndex === totalSteps - 1) {\n      var fin = document.getElementById('financialFile');\n      if (!fin || !fin.files || fin.files.length === 0) { $('#financialError').show(); valid = false; } else { $('#financialError').hide(); }\n    }\n    return valid;\n  }\n\n  $prevBtn.on('click', function(e){ e.preventDefault(); if (currentIndex > 0) showStep(currentIndex - 1); });\n\n  \/\/ ---------- final submit flow (fixed) ----------\n  $nextBtn.on('click', function(e){\n    e.preventDefault();\n    if (!validateCurrent()) return;\n    if (currentIndex === totalSteps -1) {\n      \/\/ build FormData in a deterministic manner\n      var formData = new FormData();\n\n      \/\/ append named form controls (text\/select\/textarea\/checkbox)\n      $form.find('input, textarea, select').each(function(){\n        var $el = $(this);\n        var name = $el.attr('name') || $el.attr('id');\n        if (!name) return;\n        if ($el.attr('type') === 'checkbox') {\n          formData.append(name, $el.is(':checked') ? '1' : '0');\n        } else if ($el.attr('type') === 'file') {\n          \/\/ handled below\n        } else {\n          formData.append(name, $el.val());\n        }\n      });\n\n      \/\/ append file inputs explicitly\n      var fin = document.getElementById('financialFile');\n      if (fin && fin.files && fin.files.length) formData.append('financialFile', fin.files[0]);\n      var cap = document.getElementById('capFile');\n      if (cap && cap.files && cap.files.length) formData.append('capFile', cap.files[0]);\n\n      \/\/ legacy name compatibility (keep but non-destructive)\n      try {\n        var legacyName = $('#msf-text-capital-structure').val() || $('#company_name').val() || '';\n        if (legacyName) formData.set('name', legacyName);\n      } catch(e){}\n\n      \/\/ >>> FIX: ensure a single action value only <<<\n      \/\/ remove any possible existing action entries, then set exactly one.\n      formData.delete('action');\n      formData.append('action', 'company_valuation');\n\n      \/\/ Disable UI while request in flight\n      $nextBtn.prop('disabled', true).text('Calculating...');\n\n      $.ajax({\n        url: endpointUrl,\n        method: 'POST',\n        data: formData,\n        processData: false,\n        contentType: false,\n        success: function(resp) {\n          \/\/ jQuery will auto-parse JSON if Content-Type: application\/json\n          try {\n            var json = (typeof resp === 'object') ? resp : JSON.parse(resp);\n            if (json &#038;&#038; json.success) {\n              alert(json.message || 'Valuation request received. We will email the report.');\n              if (json.download_url) window.location = json.download_url;\n            } else {\n              alert((json &#038;&#038; json.message) || 'Valuation processed, but server reported an issue.');\n            }\n          } catch (err) {\n            \/\/ fallback for non-JSON responses\n            console.warn('Non-JSON server response:', resp);\n            alert('Your request was submitted. If you do not receive email, please contact support.');\n          }\n        },\n        error: function(xhr, status, err) {\n          console.error('AJAX Error:', status, err);\n          \/\/ try to parse JSON error\n          var text = xhr.responseText || '';\n          try {\n            var j = JSON.parse(text);\n            alert('Error: ' + (j.message || text));\n          } catch(e) {\n            alert('Error processing valuation. Please try again later.');\n          }\n        },\n        complete: function() {\n          $nextBtn.prop('disabled', false).html('Get Valuation <i class=\"fa-solid fa-check\" style=\"margin-left:8px\"><\/i>');\n        }\n      });\n\n      return;\n    }\n    showStep(currentIndex + 1);\n  });\n\n  \/\/ keyboard submit\n  $form.on('keydown', function(e){ if (e.key === 'Enter') { e.preventDefault(); $nextBtn.click(); } });\n\n  \/\/ ---------- file upload handlers (identical to your working code) ----------\n  function setupUpload(zoneId, inputId, nameDisplayId, allowedExtensions){\n    var $zone = $('#' + zoneId);\n    var $input = $('#' + inputId);\n    var $name  = $('#' + nameDisplayId);\n\n    function setInputFilesFromFileList(inputElem, fileList){\n      try {\n        var dt = new DataTransfer();\n        for (var i = 0; i < fileList.length; i++) dt.items.add(fileList[i]);\n        inputElem.files = dt.files;\n        return true;\n      } catch (err) {\n        try { inputElem.files = fileList; return true; } catch(e){ console.warn('Could not set files programmatically', e); return false; }\n      }\n    }\n\n    function handleFileObj(file){\n      var max = 1610612736; \/\/ 1.5 GB\n      if (!file) { $input.val(''); $name.text(''); return; }\n      if (file.size > max) { alert('File too large (max 1.5 GB).'); $input.val(''); $name.text(''); return; }\n      if (Array.isArray(allowedExtensions) && allowedExtensions.length) {\n        var ok = allowedExtensions.some(function(ext){ return file.name.toLowerCase().endsWith(ext); });\n        if (!ok) console.warn('Uploaded file has an unexpected extension:', file.name);\n      }\n      $name.text('Selected: ' + file.name);\n      if (inputId === 'financialFile') $('#financialError').hide();\n    }\n\n    $zone.on('click', function(){\n      if ($input && $input.length && $input[0] && !$input[0].disabled) {\n        try { $input[0].click(); } catch(e){ $input.trigger('click'); }\n      }\n    });\n\n    $zone.on('keydown', function(e){\n      if (e.key === 'Enter' || e.key === ' ') {\n        e.preventDefault();\n        if ($input && $input.length && $input[0] && !$input[0].disabled) {\n          try { $input[0].click(); } catch(err){ $input.trigger('click'); }\n        }\n      }\n    });\n\n    $input.on('change', function(){ if (this.files && this.files.length) handleFileObj(this.files[0]); });\n    $zone.on('dragenter dragover', function(e){ e.preventDefault(); e.stopPropagation(); $(this).addClass('dragover'); });\n    $zone.on('dragleave', function(e){ e.preventDefault(); e.stopPropagation(); $(this).removeClass('dragover'); });\n\n    $zone.on('drop', function(e){\n      e.preventDefault(); e.stopPropagation();\n      $(this).removeClass('dragover');\n      var dt = e.originalEvent && e.originalEvent.dataTransfer;\n      if (!dt || !dt.files || !dt.files.length) return;\n      var success = setInputFilesFromFileList($input[0], dt.files);\n      if (!success) {\n        handleFileObj(dt.files[0]);\n        alert('Your browser prevented automatic file assignment. Please click the upload area and select the same file manually before submitting.');\n        return;\n      }\n      handleFileObj($input[0].files[0]);\n    });\n  }\n\n  setupUpload('financialUpload','financialFile','financialFileName',['.pdf','.xls','.xlsx','.csv']);\n  setupUpload('capUpload','capFile','capFileName',['.pdf','.xls','.xlsx','.csv']);\n\n  \/\/ ---------- legacy fallback (disabled by default) ----------\n  $('.fw-button-next').off('click.legacy').on('click.legacy', function() {\n    if (!runLegacy) return; \/\/ disabled unless you explicitly set runLegacy = true above\n    var name = $('#msf-text-capital-structure').val() || $('#company_name').val() || '';\n    $.ajax({\n      type: 'POST',\n      url: endpointUrl,\n      data: { name: name, action: 'create_ticket' },\n      success: function(response){ console.log('legacy send:', response); },\n      error: function(xhr, status, error){ console.log('legacy send error', error); }\n    });\n  });\n\n  \/\/ initialize\n  showStep(0);\n});\n<\/script>\n<\/body>\n<\/html>\n\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Company Valuation | India Advocacy<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2240","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/iadv.shop\/index.php\/wp-json\/wp\/v2\/pages\/2240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iadv.shop\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/iadv.shop\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/iadv.shop\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iadv.shop\/index.php\/wp-json\/wp\/v2\/comments?post=2240"}],"version-history":[{"count":16,"href":"https:\/\/iadv.shop\/index.php\/wp-json\/wp\/v2\/pages\/2240\/revisions"}],"predecessor-version":[{"id":2271,"href":"https:\/\/iadv.shop\/index.php\/wp-json\/wp\/v2\/pages\/2240\/revisions\/2271"}],"wp:attachment":[{"href":"https:\/\/iadv.shop\/index.php\/wp-json\/wp\/v2\/media?parent=2240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}