dougupang0901 2019-04-24 15:39
浏览 107

无法在PHP / Vue JS表单中读取null错误的属性“name”

I'm redesigning an existing application form in Vue JS that interacts and posts via PHP. The form contains a large number of fields, most contain a HTML ID of something. I have a range of Vue JS methods, one of which parses the Vue JS form data and then submits this via a HTTP POST request. I'm getting an error with part of the code which seems to be thinking that my element.name is null.

I didn't write the code, and am simply debugging and attempting to fix this.

I've tried console logging my data, and I appear to indeed be getting a null value, I'm trying to figure out whether I may need to declare var or let infront of my element variable which is getting some property back.

The method in question causing the error which is called when submitting the form, is listed below:

/**
         * Parse Form Data
         * @return {object}
         */
        parseFormData: function parseFormData() {

          console.log('Data ->' + data)

          expanded = ''
          data = this.formData
          ignore = [
            'AddressSelection', 'NextPaydateDay', 'NextPaydateMonth',
            'NextPaydateYear', 'AskDebtsQuestion', 'loanreason',
            'loanreason-select', 'PersonalDebtQuestion'
          ]
          for (property in data) {
            if (ignore.includes(property)) continue // skips
            element = document.getElementById(property)
            console.log('Element ->' + element)
            switch (property) {
              case 'AppLoanPurposeOther':
                expanded += 'data[ApplicationPayday][AppLoanPurposeOther]=' + this.formData.AppLoanPurposeOther
                break;
              case 'EmpEmployerName':
                expanded += 'data[ApplicationPayday][EmpEmployerName]=' + this.formData.EmpEmployerName
                break;
              case 'EmpEmployedYears':
                expanded += 'data[ApplicationPayday][EmpEmployedYears]=' + this.formData.EmpEmployedYears
                break;
              case 'EmpEmployedMonths':
                expanded += 'data[ApplicationPayday][EmpEmployedMonths]=0'
                break;
              case 'EmpIndustry':
                expanded += 'data[ApplicationPayday][EmpIndustry]=' + this.formData.EmpIndustry
                break;
              case 'CheckDebtAdviceTeam':
                expanded += 'data[ApplicationPayday][CheckDebtAdviceTeam]=' + this.formData.CheckDebtAdviceTeam
                break;
              case 'AppWorkPhone':
                expanded += 'data[ApplicationPayday][AppWorkPhone]=' + this.formData.AppMobilePhone
                break;
              case 'AppHomePhone':data[ApplicationPayday][CheckDebtAdviceTeam]
                expanded += 'data[ApplicationPayday][AppHomePhone]=' + this.formData.AppMobilePhone
                break;
              case 'CheckDebtAdviceTeam':
                expanded += 'data[ApplicationPayday][CheckDebtAdviceTeam]=' + this.formData.CheckDebtAdviceTeam
                break;
              case 'CheckPhoneContract':
                expanded += 'data[ApplicationPayday][CheckPhoneContract]=' + this.formData.CheckPhoneContract
                break;
              case 'BankSortcode':
                expanded += 'data[ApplicationPayday][BankSortcode]=' + this.formData.BankSortcode.replace(/-/g , '')
                break;
              default:
                if (element.name === '') continue
                console.log('Element Name ->' + element.name)
                var string =
                expanded += element.name + '=' + data[property]
            }
            expanded += '&'
          }
          expanded = encodeURIComponent(expanded.substring(0, expanded.length - 1))
          expanded = expanded.replace(/%3D/g , '=')
          expanded = expanded.replace(/%26/g , '&')
          expanded = expanded.replace(/%20/g , '+')

          return expanded
        }

The expected result shouldn't be giving me a null value, the error appears on:

if (element.name == '') continue

The error in the console shows:

enter image description here

tlp_aff_id is passed in the URL via: ?aff_id=something and this does work, it's listed in my data as:

tlp_aff_id: '<?php echo urldecode($params['aff_id']) ?>'

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?