0

I am stuck at handling the value of radio button with text input. The radio button with static values are handled correctly. Here is the AMPscript for 1000, 500 and text input. Can you please help on how the user input text value can be handled using AMPscript.

set @answer = requestparameter ("amount")
set @amountTxt = "false"
set @amount1000  = "false"
set @amount500  = "false"

if @answer == "1000" then 
        set @amount = "1000"
  elseif @answer == "500" then 
        set @amount = "500"
  else set @amount = requestparameter ("amount")
  endif

HTML :

input type="radio" name="Amount" value="1000" %%=IIF(@amount1000, "checked", "1000")=%%> $ 1,000.00
input type="radio" name="Amount" value="500" %%=IIF(@amount500, "checked", "500")=%%> $ 500.00
input type="radio" name="Amount" value=""%%=IIF(@amountTxt, "checked", @answer)=%%> $ <input type="text" name="Amount
  • 1
    What exactly isn't working? – zuzannamj Oct 7 '19 at 10:13
  • I am not able to understand how the radio button with text input type (lets say $45 donation) can be passed as an amount. I am confused in IF ELSE statement in AmpScript as well as how it should be in HTML. Can you please assist? – Rohan Kulkarni Oct 7 '19 at 10:19
  • the radio buttons will have 1000, 500 and a text box. All the static values are getting passed correctly. but how do I pass the value that is entered by a user (for ex: 45). – Rohan Kulkarni Oct 7 '19 at 10:28
2

Considering you need this for the form that creates an opportunity mentioned in your previous question, you can use the following:

<script runat="server">
  Platform.Load("Core","1.1.1");
  try{
</script>
%%[
IF RequestParameter("submitted") == true THEN

set @email = QueryParameter("email")
set @firstName = RequestParameter("firstName") 
set @lastName = RequestParameter("lastName") 
set @email = RequestParameter("email") 
set @amount = FormatNumber(RequestParameter("Amount"),"N2")

/* check if contact exists*/
set @retrievecontact = RetrieveSalesforceObjects("Contact","Id,Email","Email", "=", RequestParameter("email"))

IF RowCount(@retrievecontact) > 0 THEN

/* get Id if exists*/
set @ContactId = Field(Row(@retrievecontact, 1), "Id")

ELSE

/* create a new one if doesn't exists*/
set @ContactId = CreateSalesforceObject("Contact", 3, "FirstName", @firstName, "LastName", @lastName, "Email", @email)

ENDIF

/* create opportunity for either*/
set @opportunity = CreateSalesforceObject("Opportunity", 3, "Name", "Test_donation", "Amount", @amount, "npsp__Primary_Contact__c", @ContactId)

]%%

<h2>Thank you for submitting the form.</h2><br>
<h3>The amount enetered was $ %%=v(@amount)=%%</h3>
%%[ ELSE ]%%

<table style="padding: 20px;"><tr><td>
      <h2>Please fill in the form:</h2>
      <form action="%%=RequestParameter('PAGEURL')=%%" method="post">
         <label>First name: </label><input type="text" name="firstname" required=""><br>
         <label>Last name: </label><input type="text" name="lastname" required=""><br>
         <label>Company: </label><input type="text" name="company" required=""><br>
         <label>Email: </label><input type="text" name="email" required=""><br><br>
         <input type="radio" name="Amount" value="1000"> $ 1000<br>
         <input type="radio" name="Amount" value="500"> $ 500<br>
         <input type="radio" name="Amount"> $ <input type="number" name="Amount"><br>
         <input name="submitted" type="hidden" value="true"><br>
         <input type="submit" value="Submit">
      </form>  
</td></tr></table>

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

The RequestParameter('PAGEURL') function reloads the page when the form is submitted, posting the form parameters to back the page, which are then retrieved by the RequestParameter() functions.

If above is failing, check the following things:

  • how many required fields are on a Contact record and if you are providing values for all of them
  • how many required fields are on an Opportunity record and if you are providing values for all of them
  • do the field types and lengths match for fields on a Contact record
  • do the field types and lengths match for fields on an Opportunity record
  • especially check the Amount fields and the settings you have in Sales/Service Cloud, maybe the field needs to be passed as something else than a number, maybe the format needs to be changed
  • check if you have any rules in your Sales/Service Cloud that would prevent duplication and are now preventing you from creating a test Contact/Opportunity using the same test data
  • try hardcoding some values to see if the Opportunity will be created and only then replace them with AMPscript variables, for example: set @opportunity = CreateSalesforceObject("Opportunity", 3, "Name", "Test_donation", "Amount", "1000", "npsp__Primary_Contact__c", @ContactId)
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.