1

I am using ampscript in Cloud Pages. I am creating a form that will have a different number of options based on DE data. I need to change DE data based on the information that comes out of the form. I intend to put the data into the post array, but I don't know how to pull it out. I know how to put information into the post array with CloudPagesURL(), and I can get information out of the post array when I know what to ask for with requestparameter().

Is there a way to find the length of the array, or find the keys in the array?

2 Answers 2

3

The values of the various form elements' name attributes will be available to RequestParameter() after form submission.

For example, if your form looks like this...

<form method="POST" action="https://my-other-landing-page">
  <input type="text" name="firstName">
  <input type="text" name="lastName">

  <select name="state">
    <option value="ca">California</option>
    <option value="ny">New York</option>
  </select>

  <input type="radio" name="optin" value="yes"> Yes
  <input type="radio" name="optin" value="no" checked> No

  <button>Submit</button>
</form>

The AMPscript on "my-other-landing-page" would look something like this...

%%[
var @firstName,
    @lastName,
    @state,
    @optin

set @firstName = RequestParameter('firstName')
set @lastName = RequestParameter('lastName')
set @state = RequestParameter('state')
set @optin = RequestParameter('optin')

/* the rest of your logic... */
]%%
1
  • 1
    I agree with this being the generally accepted method, but here OP specifically provides the point of not being able to use RequestParameter, as the names and number of fields are not known Commented Apr 18, 2019 at 20:19
0

A bit late, but this works

<script runat="server">
Platform.Load("Core","1.1.1");
try{
  var jsonpost = Platform.Request.GetPostData();
  Write(decodeURI(jsonpost));
  var arr = jsonpost.split("&");
  var fieldArr = [];
  Write('<br>');
  
          for(i=0;i<arr.length;i++){
            var field = arr[i].split("=");
            var value = field[1];
            Write(field[0]);
            Write(value);
            Write('<br>');
            if(field[0] == 'Email' || field[0] == 'EmailAddress'){
              value = value.replace(/%40/g, '@');
            }

            if(value != ''){
              fieldArr.push(field[0]);
              fieldArr.push(value);
            }

          }
  Write(Stringify(fieldArr));
  
  

</script>


<script runat="server">
}catch(e){
 Write(Stringify(e));
}
</script>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .