This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 4

Add somekind of custom check on a simple 'Single Line Text'


  1. MvdL79
    Member

    Hi Yuniar (and other staff ofcourse)!

    I have a small question. I am redoing several order forms for one of our sites and I am running into a 'small' issue. I have created 3 order forms, created logic on all of these, setup prices and they finally work as it should, however during testing I noticed a small issue.

    I am using a 'Single Line Text' together with a 'Drop Down'. The 'Single Line Text' is used to enter the domainname (without TLD) where a customer can select the TLD (extension) in the 'Drop Down'. The 'Drop Down' has prices listed in them.

    While this works perfectly, if customer fills it in correctly, it's possible they make a mistake by typing "thisdomainname.com" (in the 'Single Line Text') and then selecting .eu (from the 'Drop Down'). This results in;

    a) wrong price ofcourse, since .com and .eu have different prices
    b) wrong domainname for example: 'thisdomainname.com.eu'
    c) having no clue what the customers wants, does he want a .com or .eu domainname

    Is there a way to add some checks to this element based on ID's?

    What I want is that it automatically checks this 'Single Line Text'-field on correct input. It should remove everything in front of the domainname (http://, www, etc.) and remove the TLD / extension from it, because the customer should select this from the 'Drop Down', so it will show the correct price for it. If correcting is not possible, maybe the customer should get a error message or something?

    For example, the customer enters 'http://www.anotherdomainname.eu'
    It should remove 'http://wwww.' and '.eu' from it.

    I checked my 3 order forms I currently have and this would need to be applied to two of them.
    It should apply to:

    - form id 10203 and element_1
    - form id 11901 and (also) element_1

    I hope I explained myself correctly and hoping this will be possible. Please let me know when you have the chance.

    Oh, and I rather not replace fields on the forum, because of the logic schemes I have already setup. But if there is no other way...

    Thanks in advance.

    Regards,
    Michel

    Posted 8 years ago #
  2. MvdL79
    Member

    Small bump.

    Posted 8 years ago #
  3. yuniar

    Having the code to automatically remove unwanted characters is too risky. However, I can help you with the code that simply check for those unwanted characters and display error message.

    Edit your "machform/includes/post-functions.php" file. Search around line 450 for this code:

    if('text' == $element_type){ //Single Line Text

    below that line, you can add this:

    if(($form_id == 10203 && $element_id == 1) || ($form_id == 11901 && $element_id == 1)){
    					if(!preg_match("/^[a-z0-9-]*$/i",$user_input[$element_name])){
    						$error_elements[$element_id] = 'Incorrect domain';
    					}
    }

    MachForm Founder

    Posted 8 years ago #
  4. MvdL79
    Member

    Sorry for the late reply Yuniar (was celebrating my birthday). :)

    Yeah, that's what I was looking for. Works perfectly! Many thanks for this solution. It will save us a lot of hassle on orders and mix-ups!
    Thank you!

    Posted 8 years ago #

RSS feed for this topic

Reply