How to add timezone drop down in wordpress with contact form 7 plugin? - html

I am creating a website and it contains query form which includes timezone dropdown .
How can we add time zone drop down using Contact form 7 ??
Attached is output I want.
Thanks in advance!!

You can use the wp_timezone_choice function available within WordPress. This function returns values in <option> form so you can use something of below sort:
<select>
<?php echo wp_timezone_choice( '' ); ?>
</select>
Please note that I have passed empty string so that user can select an option. If you want any timezone to be preselected then you can pass the same timezone instead of empty string.

First of all you will need a timezone database. There are several which you can google for or donwload one from here.
Next import your data into WordPress, if you have a CSV file you can use the plugin Really Simple CSV Importer to import the timezones as a taxonomy for example.
The other option is to import the data as a separate table in your DB, it all depends on how you want to manage the data. If you want to be able to differentiate timezones between different continents/countries/regions then best to store them as a taxonomy and create parent terms for each region you want to differentiate.
Next to display them in your form, use the dynamic dropdown field available with the Smart grid-layout extension plugin.
The dynamic dropdown allows you build a select field using either a list of terms from an existing dropdown (see this video tutorial on how to use it) or using a custom filter and programmatically building the list (see this tutorial) using your database custom table if that's the way you imported your timezone data.
Last but not least, the dynamic dropdown also allows you to transform your select field into a select2 field which is handy for large lists as it allows your users to search for a particular timezone.

Related

Getting the value of a particular cell with AJAX

My goal is very simple and I would guess it is a very common goal among web developers.
I am creating a Rails (5.1) application, and I simply want to use AJAX to get the value of a specific cell in a specific row of a specific table in my database (later I am going to use that value to highlight some text on the current page in the user's browser).
I have not been able to find any documentation online explaining how to do this. As I said, it seems like a basic task to ask of jquery and ajax, so I'm confused as to why I'm having so much trouble figuring it out.
For concreteness, say I have a table called 'animals', and I want to get the value of the column 'species' for the animal with 'id' = 99.
How can I construct an AJAX call to query the database for the value of 'species' for the 'animal' with 'id' = 99 .
Though some DBs provide a REST API, what we commonly do is define a route in the app to pull and return data from the DB.
So:
Add a route
Add a controller/action for that route
In that action, fetch the data from the DB and render it in your preferred format
On the client-side, make the AJAX call to that controller/action and do something with the response.

Access New ID Field YYYYMMNN [duplicate]

I need to automatically generate a 12 character value for my Business Key. Without any user interaction.
8 character -> Today Date (yyyymmdd or ddmmyyyy).
+
4 character -> Sequential Number (0001,0002,0003).
The Sequential Number must reset on each new day.
Is it possible to do this in Microsoft Access 2010+ without any coding involved?
Since you are using Access 2010+ the best way to accomplish your goal would be to use a Before Change data macro like this
To create the Before Change macro, click the "Before Change" button on the "Table" tab of the ribbon when the table is open in Datasheet View:
For more details on Data Macros see
Create a data macro
Good question, thanks for the challenge!
After some search, it seems it's possible to do that.
You can prefix the AutoNuber value by processing like the explanation available here: http://www.databasedev.co.uk/add_prefix.html
You can try to specify in the format of the field a format(now(),"ddmmyyyy").
Check this page for more informations, another user seems to have the same problem and got a solution: http://bytes.com/topic/access/answers/695188-custom-made-autonumber-show-todays-date
Hope it's helping you!

How to insert json encoded inputs into foreign related tables

I am creating functionalities in yii+extjs. My client side is desighned in extjs and server side is in yii framework.
I am having two tables as
Poll Option
-pollId -optionId
-PollQuestion -option
-pollId
Now through poll creation form which will be in extjs,Question and its related option gets send to server in json format. So in yii framework,in actionCreate function will get input as-
$json='{"pollId":1,"PollQuestion":"Who is the best
cricketer","option":"ABC","option":"DEF","option":"XYZ"}'
$obj=json_decode($json);
During creation of poll,user can enter any number of options.So number of options can be anything.
i am creating above functionality in Pollcontroller.
So this newly created question gets inserted into Poll table as=
$model=new Poll();
$model->pollId=$obj->pollId;
$model->PollQuestion=$obj->PollQuestion;
Now i want to put all these new options in option table with same pollId. So how to add all these options in option table? Please help me
I would start by modifying the JSON so the options are a separate JSON within the pollquestion JSON.
Something like this...
$json='{"pollId": 1,"PollQuestion": "Who is the best cricketer",
"options":{[{"value":"ABC"},{"name": "DEF"},{"name": "XYZ"}]}';
That way when you decode it with json_decode you'll get an options array which you can go through and add each of the elements in that array in the options array.
for($i=0; $i<sizeof($obj['options']);$i++){
//Add to table logic here
}

two fields with the same name create string instead of an array?

I've two fields with the same name name="s[]", but this creates an array, I don't need an array instead I'd like to construct a string.
I'm using these fields to submit search query to wordpress, if I will use an array I will have to mess with wordpress core, which I don't want. So my only option is to create 1 single string from two fields and submit it to query.
What do you think?
I think there are two options:
Submit the form to a different page, which redirects to the normal WordPress search page
Catch the onSubmit event using JavaScript and rewrite / add to the form data
I would prefer option 1 because it will work for browsers that don't use JavaScript. If you go with option 2, then you should not even show your two-field search interface to browsers that don't have JavaScript.

Not saving to db if form input fields are empty?

I have created Wordpress custom fields through functions.php. My code works fine, and I've few input fields and some checkboxes.
Problem is when I save post, even if I don't put content inside my form, these rows are created in DB. I'd like to do some kind of php check and avoid creation of row in DB if field content is not saved.
I tried several ways, but in most cases it would result in incorrect behaviors of checkboxes for example.
Full code is here: http://pastebin.com/embed_js.php?i=Vvnseiep
I'd appreciate your help in this matter. I'm not very experienced.
Thanks!
Here Validation part comes into play. Why cant you use Javascript to validate your input in the client environment itself and then allowing it to hit the db.
Name all of the checkboxes the same(name="meta_box_check[]"). They must still have different ID's. When the form is posted you will be given an array of values that were checked in $_POST['meta_box_check']. You can then check if the array is empty. You can also save the checkbox data as JSON data. This isn't always good practice, but will only use one data row to save any and all checkbox values.
<?php
if(!empty($_POST['meta_box_check']))
{
//process your data and save it
update_post_meta($post_id, 'meta_features_checklist', json_encode($_POST['meta_box_check']));
}
?>
This is a basic example and make sure you do some data validating before saving.