Jump to content

Default/Custom Text


uph printshop

Recommended Posts

I am developing a thank you card where you can select a default message or enter your own custom message that appears on the inside of the card. The way I have it set up now, is I have a field named "message type" that is intended to be a drop-down menu with "default" and "custom" selections, and then I have a field named "custom message" where if "custom" is selected, you can type in your message. If default is selected, I want a generic thank you message to appear. Basically I want the coding to say if "default" is selected, return "default thank you message". If "custom" is selected, return the contents of the "custom message" field. Im just not sure how to set up the coding for this.:confused: Thank you!
Link to comment
Share on other sites

That worked great, but i also need some text replaced in the return line. The code below is what I had before I added the If statement. They all worked, I just need to incorporate the ReplaceSubstrings into the If statement.

 

var a = Field("custom text");

a = ReplaceSubstring(a, "=" , "<br />");

a = ReplaceSubstring(a, "&" , "&");

a = ReplaceSubstring(a, "\\" , "|");

return a;

 

 

The code I have now is below. I could figure out how to incorporate one replacesubstring at a time.

 

var a = Field("custom text")

var b = "Custom Message Here";

 

if (Field("message type") == "custom")

return ReplaceSubstring(a, "=", "<br />");

 

else if (Field("message type") == "default")

return ReplaceSubstring(b, "=", "<br />");

 

Thanks so much for your help with this!:)

Link to comment
Share on other sites

Why are you replacing an ampersand with an ampersand here?

a = ReplaceSubstring(a, "&" , "&");

 

You could do the replacement where you define 'a' like this:

var a = Field("custom text")[color="Red"].replace("\\"," | ").replace("=","<br />");[/color]
var b = "Custom Message Here";

if (Field("message type") == "custom")
return a;

else if (Field("message type") == "default")
return b;

 

I don't think you should have to replace anything for the 'b' variable. Since you're defining a static string, you'd just define it exactly as you'd like it to be returned.

 

And more succinctly:

return (Field("message type" == "default") ? "Custom Message Here" : Field("custom text")[color="Red"].replace("\\"," | ").replace("=","<br />")[/color];

Edited by step
syntax
Link to comment
Share on other sites

Maybe try replacing the ampersand with the HTML entity character:

return (Field("message type" == "default") ? "Custom Message Here" : Field("custom text").replace("\\"," | ").replace("=","<br />")[color="Red"].replace("&","&")[/color];

Link to comment
Share on other sites

It is only replacing one equal sign(break). If the customer wants a double space, they would enter the equal sign twice. It is breaking the copy, but only once, not twice. It leaves the second equal sign as literal text. Am I missing something? Thanks!

The JavaScript String.replace function replaces only one instance of the matched substring, by default, unless the first parameter is a RegExp object with a "g" flag.

 

So you could do this to fix it:

if (Field("message type" == "default"))
   return "Custom Message Here";
//else
return Field("custom text").replace(new RegExp("\\", "g"), " | ").replace(new RegExp("=", "g"), "<br />").replace(new RegExp("&", "g"), "&");

Although in this case, I think using the FusionPro-specific ReplaceSubstring function is more clear, even if it's a bit less succinct:

if (Field("message type" == "default"))
   return "Custom Message Here";
//else
var a = Field("custom text");
a = ReplaceSubstring(a, "=" , "<br />");
a = ReplaceSubstring(a, "&" , "&");
a = ReplaceSubstring(a, "\\" , "|");
return a;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...