You can use a great plugin like Gravity Forms, but every once in a while you will find yourself in a situation where you will have to build a form yourself.
Below is a super-minimal example of what you will need to create a form that works as a plugin.
Create a php file named SimpleForm.php and add the following:
<!--?php /* Plugin Name: Simple Form Plugin URI: http://example.com/ Description: A simple email form Version: 0.1 Author: your name goes here Author URI: http://www.your-website.com */
Next, the form:
Here’s some stuff that makes this different from a regular php form.
<?php wp_nonce_field('add-item','my_form_added'); ?>
Then, when the user presses the submit button, you verify the submit button was pressed by:
if (isset($_POST['my_form_submit']))
And then you verify the nonce by:
if (wp_verify_nonce($_POST['my_form_added'], 'add-item') )
Refer to how the nonce was created in the form above.
Wrap up the form code and validation code into a function called my_form and then add the shortcode:
add_shortcode('MY_FORM', my_form);
Now you can add this form to any WordPress page using [MY_FORM].
View the complete form plugin.
When you write posts or pages in WordPress, there’s already a setting for status:
This is pretty straightforward to set up with Pods CMS for your pods content, by using input and pre-save helpers.
First, install the helper called Selectbox Your Values. Copy the code from the link and “import” it using the Pods CMS Package Manager.
Go to your WordPress Admin > Pods > Package Manager:
Once you hit “Proceed to Confirmation” you should see a “Success!” and “Finalize” message (not necessarily in that order).
After that, you have to do a quick edit to the helper, so go to Pods > Setup > Input Helper:
Change the code as shown in bold:
<?php
$arr = array("waiting for approval", "published"); //array with fixed values, edit and/or add these with your preferences
?>
<select id="<?php echo $css_id; ?>">
<?php
foreach ($arr as $val) {
if ($val==$value) { $selected="selected"; } else { $selected=""; } // add selected argument to set value
echo '<option value="' . $val . '" ' . $selected . '>' . $val . '</option>';
}
?>
</select>
Then, create a column in your pod called status, and then add the input helper that you just installed and modified:
Now, if this field hasn’t been made a “required field” you can create a pre-save helper so that your default status becomes “waiting for approval“. This is useful if you are making a public form where you won’t be showing the status column as an option.
Go to your WordPress Admin > Pods > Setup > Helpers and add a new helper:
For the code, just add the following:
<?php
if($columns['status']['value']==undefined)
{
$columns['status']['value'] = 'waiting for approval';
}
?>
All this code above does is check the value of your status column. If it’s undefined (because your user hasn’t used the drop-down menu at all) it sets the value of the status column to ‘waiting for approval’.
After that, just go to your pod settings and add this pre-save helper:
To display only the pods content with a status of published, use the following code
$name-of-your-pod-goes-here = new Pod('name-of-your-pod-goes-here');
$params['select'] = '*';
$params['orderby'] ='t.name ASC'; // sorts by the name, optional
$params['where'] = 'status = "Published"';
$name-of-your-pod-goes-here ->findRecords($params);
Thanks to Scott Clark I figured out how to create a pod with a column that relates to WordPress Categories:
The above image demonstrates how to create a multi-select to choose multiple categories to associate with my pod.
Because category is a PICK field, it has to be reference with the syntax:
category.name
Say, if you want to select all pods content with a category name of “my-category” with a link like this:
http://my-domain-here.com/category/my-category/
You can get the “my-category” part of the link above with the code:
$selected = pods_url_variable(-1);
And then use $selected to retrieve all the related pods content with:
$pods= new Pod('my-pod-type');
$params['select'] = '*';
$params['orderby'] = 't.name';
$params['limit'] = 25;
$params['where'] = 'category.name LIKE "'.$selected.'"';
It seems like whenever I move a site from any-domain.com/wordpress/ to any-domain.com (for example, when you are building a wordpress site that will replace the existing site) it’s a bit of a gamble as to whether you are going to end up with a slew of broken images. Sometimes the images are broken; sometimes they aren’t.
I finally figured out a fix that works instantly.
Back up you database, and then use the following query:
UPDATE 'your-wordpress-database-name'.'wp_posts' SET 'guid' = REPLACE ( guid, 'http://anydomain-com./wordpress/', 'http://anydomain-com./');