Tips and Tricks HQ Support Portal › Forums › WP eStore Forum › WP eStore Tweaks › WP eStore – "Collect Customer Input" remove spaces/limit/validate input value
- This topic has 4 replies, 2 voices, and was last updated 10 years, 4 months ago by icm.
-
AuthorPosts
-
May 21, 2014 at 4:13 pm #10876icmSpectator
Hi, I’m using the Collect Customer Input option to create usernames for another site. I have it all working, but I can foresee a couple of problems if users enter certain things in the field.
1) spaces: If the user enters a space in the Collect Customer Input field, they will create a username that is invalid in the other site.
2) parentheses: If the user enters an open or close parenthesis, it will mess up the stuff going on behind the scenes that extracts the username from the product name.
How do I automatically remove spaces and parentheses, or prevent the user from proceeding by just popping-up an alert to inform them of the problem.
I’m not a coder, but I am familiar with basic HTML and CSS and can figure out some of what goes on with code, so I can copy/paste bits in. I already added the pop-up alert for when the customer tries to add to cart without adding something to the collect customer input field.
Thanks.
dwb
May 22, 2014 at 12:57 am #63135adminKeymasterHi, This will probably be best done using JavaScript. If you have added a popup alert when no value is entered, then you can add additional code in there to check the *entered value* also. You can use the string replace function in JavaScript to remove some of those value that you don’t want.
Here is a very basic example JavaScript code snippet for this:
var custom_input = "Some Input From Customer";
var custom_input = custom_input.replace(" ", "");//replace space character
var custom_input = custom_input.replace("(", "");//replace bracketMay 22, 2014 at 5:03 pm #63136icmSpectatorSorry to be dense, but I’m still a newb with this stuff.
What I have now (excerpt from eStore_read_form.js – ReadForm1 function:
if (val.length != 0)
{
val = val.replace(“(“,”[“);
val = val.replace(“)”,”]”);
val_combo = val_combo + ” (” + val + “)”;
}
// added else statement to make form mandatory —
else
{
alert(“Please enter a username for your employee.”);
return false;
}
// —- end edit
Now, I assume I’d need to put the snippet you suggested at the top of the if statement… (IF something is entered then Replace the spaces made by customers and then put it inside parentheses).
Won’t “Some Input From Customer” need to be a variable? What is the variable name I need to use? Would it be val?
Thanks again.
May 22, 2014 at 11:25 pm #63137adminKeymasterI think something like the following should do (it will remove empty space from the input):
if (val.length != 0)
{
val = val.replace(" ","");
val = val.replace("(","[");
val = val.replace(")","]");
val_combo = val_combo + " (" + val + ")";
}
else // added else statement to make form mandatory
{
alert("Please enter a username for your employee.");
return false;
}May 23, 2014 at 2:59 pm #63138icmSpectatorBrilliant. Thanks!
-
AuthorPosts
- You must be logged in to reply to this topic.