I'm a newbie to web designing. I'm using contact form 7 to create a registration form for our conference.
All I wanted to do is, I need to give a unique id for all of them after they have registered for the conference and the further forms should be identified using this unique id.
So far, I have installed contact form 7 and contact form dtx
for this purpose and I have tried Koen de Bakker solution of generating a random number.
But it's slightly different from what I want, since it changes the random number for each refresh.
What I'd like is:
An unique number like "17ICLAA001,..." should be generated for each form submission.
Send the unique number to the applicant after successive submission of the form.(I hope this can be easily done once the shortcode is done).
Editing the form using the unique id.
Any help will be much appreciated. Thank you.
I have found a way to do this. Its just the number of rows+1 in the table.
When you add a record to your table the unique number also gets increased by 1 in the following code. Add the following function in function.php in your theme and use the short code "row_count" to call the function. Use it with dynamichidden text from dtx.
function row_count_shortcode() {
global $wpdb;
$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->username_wp1.SaveContactForm7_1" )+1;
return "17ICLAA".sprintf('%03d',$user_count);
}
add_shortcode( 'row_count', 'row_count_shortcode' );
Usually when you are creating contact forms using contact form7 it automatically creates a table in your database something like
username_wp1.SaveContactForm7_1
Instead of this replace your database table name.
So in your contact form, type
[dynamichidden uniqueid "row_count"]
and use [uniqueid] in your email body to serve your purpose.
It works fine. I have checked in my site.
Correct way to generate a unique and progressive number is to set a field in wp_option like this:
add_option('unique_number', '1');
When filter is called, you must simply increment this unique number:
function genTicketString() {
$currentUniqueNumber = get_option('unique_number');
$newCurrentUniqueNumber = $currentUniqueNumber + 1;
update_option('unique_number' $newCurrentUniqueNumber );
return $newCurrentUniqueNumber;
}
add_shortcode('quoteticket', 'genTicketString');
Related
SilverStripe: v4
Module used: https://github.com/unclecheese/silverstripe-display-logic
Hello and good day!
I'm in the Security page (Lists of Members) and was trying to display a ListboxField upon a certain string or value is found on another ListboxField.
.
With The image above, I wanted to select or input in the Groups field the Sales Representative role, and once the Sales Representative is present in the Groups, that's the moment I shall display another field
Here's my code snippet
$codesList = Member::get()->column('Code');
$codes = ListboxField::create(
'AccountPurchases',
'Account Purchases',
$codesList);
$fields->insertAfter('DirectGroups', $codes);
$codes->displayIf("DirectGroups")->contains("Sales Representative");
But the problem is, no matter what I did (1: dev/build?flush=1, 2: refresh the page, 3: restart the app) the desired field named $codes still won't appear.
But if I'm applying it to a normal field like the FirstName (which is a simple TextField), it's working perfectly fine...
$codesList = Member::get()->column('Code');
$codes = ListboxField::create(
'AccountPurchases',
'Account Purchases',
$codesList);
$fields->insertAfter('DirectGroups', $codes);
$codes->displayIf("FirstName")->contains("Sales Representative");
Any ideas how to perform my desired output?
For non-standard form fields, you'll need to use the display-logic wrapper. https://github.com/unclecheese/silverstripe-display-logic#dealing-with-non-standard-form-fields
The definition of "non-standard" is a bit hard to find, but in my experience it's anything non-plain-html-input. Listbox is a fancy front-end thing, so it qualifies. The examples in the docs can be confusing, but if you are using SS4 and the latest display-logic, then use Wrapper::create instead of DisplayLogicWrapper::create. If you wrap it, it should work.
$codesList = Member::get()->column('Code');
$codes = Wrapper::create(
ListboxField::create('AccountPurchases','Account Purchases',$codesList);
)->displayIf("DirectGroups")->contains("Sales Representative")->end();
$fields->insertAfter('DirectGroups', $codes);
I just know a little bit about Javascript, I'm not a programmer yet.
I created a Ninja Forms to be used in my Wordpress site. When a user fills out the 4 fields of the form and press Submit, I need those data to appear always in the frontend ( in their 4 specific places I've created in html), and the last one submitted overwrite to the previous one.
Ninja is saving the data in wp_postmeta like this:
**meta_key** **meta_value**
_field_12 (the first of the values I want appear in frontend)
_field_13 (the second one)
_field_14 (the third one)
_field_15 (the fourth one)
_form_id 1 (always the same value)
_seq_num 3 (increase 1 every time Submit is pressed)
How can I do it?
I know is out of my range without PHP knowledge but, can someone give me some trick? Is there a plugin to get it?
Help, please
You have several options:
Create a custom Ninja Forms Action. This obviously will require significant amount of programming skills, understanding how Ninja Forms works, etc. Advantage, you could store your data in preferred location and format (e.g. in wp_options table).
Hackfix the problem. You can probably do something like this in your template:
.
$form_id = 3;
$submissions = Ninja_Forms()->form( $form_id )->get_subs();
if ( is_array( $submissions ) && count( $submissions ) > 0 ) {
// Get first element of array; latest submission
$latest_submission = reset( $submissions );
// Returns array with all submission values
$all_fields = $latest_submission->get_field_values();
print_r( $all_fields );
// To get/display single value
$single_field = $latest_submission->get_field_value( 'firstname_1531139833971' );
echo $single_field;
}
If you not sure about form ID, check the id listed in shortcode (Ninja Forms -> Dashboard, then shortcode column). E.g. [ninja_form id=3] id=3 is your form_id.
Easiest way to obtain key for method get_field_value is to print_r all submission values and check which one is which one, otherwise, click to edit form, select field to edit, expand administration section and you should see the key for that field.
Option #1 should be preferred method to address this issues, if you intend to proceed with option #2 make sure to check function Ninja_Forms() exists first, otherwise you will get fatal errors if Ninja Forms is disabled/not loaded/etc.
I have a WordPress sites using Gravity Forms, and within this form I have a field that requires a special 10 digit code to be input by the user that matches up with a database of codes (there are 20 of these codes). If the code that has been input matches one of the 20 codes, then they can proceed with submitting the form. If it doesn’t match then they cannot proceed.
Please advise on how to create a PHP function that achieves this?
Many thanks
I wrote a snippet that you might find helpful.
http://gravitywiz.com/require-existing-value-submission-gravity-forms/
To use this snippet for your needs, you would need to setup a new form that will be used to store the 20 codes. Add a field a Single Line Text field to your form. Add an entry for each code.
On your original form, you can now configure the snippet to check the values of the new form for a valid code. Happy to answer any questions.
new GW_Value_Exists_Validation( array(
'target_form_id' => 613, // your original form ID where the codes will be validated
'target_field_id' => 1, // the field on your original form where the user should enter the code
'source_form_id' => 519, // the new form you will create to store your codes
'source_field_id' => 1, // the field on the new form that will store one code per submission
'validation_message' => 'Hey! This isn\'t a valid reference number.' // the error message displayed if the user does not enter a valid code
) );
I can add and remove fields in the user profile section with:
function add_remove_contactmethods($contactmethods ) {
// Remove AIM
unset($contactmethods['aim']);
//add Phone
$contactmethods['phone'] = 'Phone';
return $contactmethods;
}
add_filter( 'user_contactmethods', 'add_remove_contactmethods' );
When I view this screen in the backend, the "Phone" field comes last, after some other fields like "Email" and "Website". I guess this is because my added field was added after the default Wordpress fields. How do I sort this, for instance alphabetically, so that my "Phone" field comes in alphabetical order instead of after the default fields? How do I sort the output of $contactmethods without messing it up?
try using ksort
function add_remove_contactmethods($contactmethods ) {
// Remove AIM
unset($contactmethods['aim']);
//add Phone
$contactmethods['phone'] = 'Phone';
ksort($contactmethods);
return $contactmethods;
}
add_filter( 'user_contactmethods', 'add_remove_contactmethods' );
re
UPDATE: So I guess the answer to my original question, is to explain why and how "Website" and "Email" are stored, and how the output is controlled in the backend when you view a profile. Maybe it's an ordered action? I guess "Website" and "Email" are just user meta, but how is the output order controlled. I accept that I might have to write a custom script to sort the output, I just don't know where to begin.
Your right about that, all the new contact fields were added into user_meta table. user_email and user_url are in the users table. The problem you are going to have doing this, is that a filter does not exist to modify the information. You can check the main filters here:
http://codex.wordpress.org/Plugin_API/Filter_Reference
and also you can look at core itself. All the admin templates are in wp-admin so you can look at the variable you need to modify in user-edit.php ($profileuser). Im in no way recommending this, but you could modify the template there, it will be overwritten on the next update of course so thats a drawback to it.
There may be a hook somewhere in admin in the load template process, if you could find one, you could relocate the template location to a theme file and recreate it with the changes you want. But all this seems like a lot of work to include just 2 fields to reorder?
Another approach is to use a higher priority the other when adding the fields. For example, Yoast adding 3 contact methods, and if you want your 'phone' appear before those, set the filter to:
add_filter('user_contactmethods', 'my_contactmethods', -5, 1);
Email and Website cant be re-ordered unless deep PHP coding or javascript re-order or advanced CSS.
if you know the key(s) (check the name fields in the source code), you can add other plugin fields by yourself, and choose exact appearance. A field is only added once if they added twice (!) This is how we use:
function entex_author_contactmethods($contactmethods){
$contactmethods['mail'] = __('Public email', 'entex-theme');
$contactmethods['phone'] = __('Phone', 'entex-theme');
$contactmethods['googleplus'] = __('Google+', 'wordpress-seo');
$contactmethods['youtube'] = __('YouTube URL', 'wordpress-seo');
$contactmethods['facebook'] = __('Facebook profile URL', 'wordpress-seo');
$contactmethods['instagram'] = __('Instagram URL', 'wordpress-seo');
$contactmethods['twitter'] = __('Twitter username (without #)', 'wordpress-seo');
$contactmethods['linkedin'] = __('LinkedIn URL', 'wordpress-seo');
$contactmethods['myspace'] = __('MySpace URL', 'wordpress-seo');
$contactmethods['pinterest'] = __('Pinterest URL', 'wordpress-seo');
return $contactmethods;
}
add_filter('user_contactmethods', 'entex_author_contactmethods', -5, 1);
Happy contact-ing!
Going a bit mad here... :)
I'm just trying to add CCK fields from a Content Profile content type into page-user.tpl.php (I'm creating a highly-themed user profile page).
There seem to be two methods, both of which have a unique disadvantage that I can't seem to overcome:
'$content profile' method.
$var = $content_profile->get_variables('profile');
print $var['field_last_name'][0]['safe'];
This is great, except I can't seem to pass the currently viewed user into $content_profile, and it therefore always shows the logged in user.
'$content profile load' method.
$account_id = arg(1);
$account = user_load($account_id);
$user_id = $account->uid;
$var = content_profile_load('profile', $user_id);
print $var->field_first_name[0]['value'];
Fine, but now I can't access the full rendered fields, only the plain values (i.e. if the field has paragraphs they won't show up).
How can I have both things at once? In other words how can I show fields relating to the currently viewed user that are also rendered (the 'safe' format in 1)?
I've Googled and Googled and I just end up going round in circles. :(
Cheers,
James
Your content profile load method seems to be the closest to what you want.
In your example:
$account_id = arg(1);
$account = user_load($account_id);
$user_id = $account->uid;
$var = content_profile_load('profile', $user_id);
print $var->field_first_name[0]['value'];
The $var is just a node object. You can get the "full rendered fields" in a number of ways (assuming you mean your field with a filter applied).
The most important thing to check is that you're field is actually configured properly.
Go to:
admin/content/node-type/[node-type]/fields/field_[field-name] to configure your field and make sure that under text processing that you've got "Filtered text" selected.
If that doesn't fix it,try applying this:
content_view_field(content_fields("field_last_name"), $var, FALSE, FALSE)
(more info on this here: http://www.trevorsimonton.com/blog/cck-field-render-node-formatter-format-output-print-echo )
in place of this:
print $var->field_first_name[0]['value'];
if none of that helps... try out some of the things i've got on my blog about this very problem:
http://www.trevorsimonton.com/blog/print-filtered-text-body-input-format-text-processing-node-template-field-php-drupal
When you're creating a user profile page there is a built in mechanism for it. just create a user template file, user_profile.tpl.php.
When you use the built in mechanism you automatically get access to the $account object of the user you are browsing, including all user profile cck fields. You have the fields you are looking for without having to programmatically load the user.
I have a field called profile_bio and am able to spit out any mark up that is in without ever having to ask for the $account.
<?php if ($account->content[Profile][profile_bio]['#value']) print "<h3>Bio</h3>".$account->content[Profile][profile_bio]['#value']; ?>
I've tried themeing content profiles by displaying profile node fields through the userpage before and it always seems a little "hacky" to me. What I've grown quite fond of is simply going to the content profile settings page for that node type and setting the display to "Display the full content". This is fine and dandy except for the stupid markup like the node type name that content profile injects.
a solution for that is to add a preprocess function for the content profile template. one that will unset the $title and remove the node-type name that appears on the profile normally.
function mymodule_preprocess_content_profile_display_view(&$variables) {
if ($variables['type'] == 'nodetypename') {
unset($variables['title']);
}
}
A function similar to this should do the trick. Now to theme user profiles you can simply theme your profile nodes as normal.