Tips and Tricks HQ Support

Support site for Tips and Tricks HQ premium products

  • Home
  • Contact Us
  • Documentation
  • Forum Home
    • Forum
    • Forum Search
    • Forum Login
    • Forum Registration

WP eStore – "Collect Customer Input" remove spaces/limit/validate input value

by

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, 11 months ago by icm.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • May 21, 2014 at 4:13 pm #10876
    icm
    Spectator

    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 #63135
    admin
    Keymaster

    Hi, 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 bracket

    May 22, 2014 at 5:03 pm #63136
    icm
    Spectator

    Sorry 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 #63137
    admin
    Keymaster

    I 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 #63138
    icm
    Spectator

    Brilliant. Thanks!

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Log In

Forum Related

  • Forum Home
  • Forum Search
  • Forum Registration
  • Forum Login

Support Related Forms

  • Contact Us
  • Customer Support
  • Request a Plugin Update
  • Request Fresh Download Links

Useful Links

  • Plugin Upgrade Instructions
  • WP eStore Documentation
  • WP eMember Documentation
  • WP Affiliate Platform Documentation
  • Tips and Tricks HQ Home Page
  • Our Projects

Quick Setup Video Tutorials

  • WP eStore Video Tutorial
  • WP eMember Video Tutorial
  • WP Affiliate Platform Video Tutorial
  • Lightbox Ultimate Video Tutorial

Our Other Plugins

  • WP Express Checkout
  • Stripe Payments Plugin
  • Simple Shopping Cart Plugin
  • Simple Download Monitor

Copyright © 2025 | Tips and Tricks HQ