database strings

Home Forums Quform WordPress database strings

This topic is: not resolved
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #4098
    rubyj
    Participant

    So I set up a database through my cPanel and have it linked to my form and everything works properly. Now what I am trying to do is a little bit complicated and I want to know if it is even possible within Quform.

    So let’s say I have three fields: first name, last name, and phone number. I want to populate one of the database fields with the first letter of the first name, first letter of the last name, and the last 4 digits of the phone number field. So essentially the format would be like this: AB1234

    Is there any way to manipulate the values when I tie them to the database fields so it only picks up those characters? For instance, my first name field value looks like this: {First Name|1}. Is there more syntax here I can add to make sure it picks up only the first character. And for the phone number it would need to be the last 4 digits so changing the length of the field in my database won’t really work.

    Thanks!

    #4117
    rubyj
    Participant

    Also, is there a way to have a “confirm email” field? I want to make it so that there is an error message displaying if the two email fields do not match.

    #4123
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4169
    rubyj
    Participant

    Hi Ally,

    Thanks so much for your help! I was able to get the email confirmation field in there without any problems and am still working on the other issue.

    Had another question though – When the user submits the form, I want there to be a query to the database to see if there is already an entry with the same first name, last name, and phone number. So far I feel like the easiest way to do this would be to run a php function upon submit, like you see below:

    <form action="welcome.php" method="post">
    Name: <input type="text" name="fname">
    Age: <input type="text" name="age">
    <input type="submit">
    </form>

    You see the form action is welcome.php. How do I attach an action to the submit button in Quform?

    Thanks again-

    #4187
    rubyj
    Participant

    And another question – The guide used to alter the letters to uppercase uses the unique ID of the form element. For the hidden elements that I have created, I see no unique ID.

    This is how I’ve adapted the code; basically I’ve replaced the uppercase string with the string that returns the first character in uppercase. But I do need an ID for the 5th line where you see the question marks. Or, how do I adapt without the unique ID for the hidden field?


    function get_first_characters ($form)
    {
    //Return the first letter of the first name
    if (isset($_POST['iphorm_7_1'])) {
    $_POST['iphorm_7_??'] = ucfirst($_POST['iphorm_7_1']);
    }
    }

    add_action('iphorm_pre_process_7', 'get_first_characters');

    Thanks.

    #4195
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4240
    rubyj
    Participant

    Ok, so I will pull the value of the what the user submitted from the $code variable you have defined above. How do I reference the database to see if those values already exist?

    Let’s say these are my variables for the fields that need validation that the user is submitting:

    $fname = $element->getForm()->getValue('iphorm_7_1');
    $lname = $element->getForm()->getValue('iphorm_7_2');
    $email= $element->getForm()->getValue('iphorm_7_4');

    Then would my code look like this?

    function mytheme_custom_validator($valid, $value, $element)
    {
    if ($value = '$fname' and $value = '$lname' and $value = '$email') {
    $element->addError('You have already registered for an account');
    $valid = false; //no record will be added to the database
    }
    else
    {
    mysqli_query($con,"INSERT INTO database_name (firstName, lastName, emailAddress)
    VALUES ('$fname', '$lname',$email)");
    echo 'Welcome to our website, thanks for registering'; //record will be added to database
    }
    return $valid;
    }

    I want to prevent data from being inserted into the database if a record with the same values already exist. Would the above code accomplish this?

    Thanks for all your help.

    #4241
    rubyj
    Participant

    In case it helps, here is the raw SQL query that illustrates what I’m trying to do:


    INSERT INTO customer_suites( firstName, lastName, emailAddress )
    SELECT *
    FROM (

    SELECT upper( '$fname' ) , upper( '$lname' ) , upper( '$email' )
    ) AS tmp
    WHERE NOT
    EXISTS (

    SELECT *
    FROM customer_suites
    WHERE upper( firstName ) = upper( '$fname' )
    AND upper( lastName ) = upper( '$lname' )
    AND upper( emailAddress ) = upper( '$email' )
    )
    LIMIT 1

    #4278
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4305
    rubyj
    Participant

    This is perfect, thank you so much!!!

    #4318
    rubyj
    Participant

    This code makes complete logical sense when I look at it and I’ve replaced all the dummy names with my database information, but it seems to not want to work. It gives me an error message of “An error occurred submitting the form” every time I submit.

    Thinking that perhaps accessing the database was confusing the plugin (once from the code above, and once from the backend database inputs), I deleted all database info so that nothing was being saved directly from the plugin. This didn’t make any difference.

    Any thoughts on what may be causing the problem?

    Thanks again, you have been a huge help.

    #4324
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4459
    rubyj
    Participant

    Unfortunately, this didn’t end up working for me and we couldn’t find the error 🙁

    I had to make the form from scratch in HTML and add javasript validators for each field and write a PHP back-end with the same functions to check records and insert where necessary.

    It would be great if you could add such features in your next update where there would be options to check the records to see if one exists already.

    Thanks-

    #4465
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy