Home › Forums › Quform WordPress › database strings
- This topic has 13 replies, 2 voices, and was last updated 11 years, 6 months ago by Ally.
- AuthorPosts
- April 26, 2013 at 5:04 am #4098rubyjParticipant
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!
April 26, 2013 at 11:10 pm #4117rubyjParticipantAlso, 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.
April 27, 2013 at 9:06 am #4123AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
April 29, 2013 at 11:14 pm #4169rubyjParticipantHi 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-
May 1, 2013 at 1:21 am #4187rubyjParticipantAnd 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.
May 1, 2013 at 10:57 am #4195AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
May 3, 2013 at 2:23 am #4240rubyjParticipantOk, 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.
May 3, 2013 at 2:32 am #4241rubyjParticipantIn 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
May 6, 2013 at 8:38 am #4278AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
May 6, 2013 at 9:46 pm #4305rubyjParticipantThis is perfect, thank you so much!!!
May 7, 2013 at 3:20 am #4318rubyjParticipantThis 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.
May 7, 2013 at 9:38 am #4324AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
May 17, 2013 at 10:55 pm #4459rubyjParticipantUnfortunately, 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-
May 20, 2013 at 9:24 am #4465AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.