I am trying to pull dynamic form id to create a dropdown for the end-user. This I have done here.
Now, I'd like to pass that id so that a different form shows up based on selection as shown below:
<form class="ui form">
<select name="select" class="ui fluid search selection dropdown">
<?php $myforms = RGFormsModel::get_forms(); foreach ($myforms as $form) { ?>
<option name="select" value="<?php echo $form->id ?>"> <?php echo $form->title ?> </option>
<?php } ?>
</select>
</form>
<?php echo gravity_form($form, true, true, false, '', true, 1); ?>
Here's what I might do to make a shortcode for gravity forms that pulls the ID from the URL parameter.
function return_gform_embed(){
$form_id = $_GET["form_id"];
return do_shortcode('[gravityform id="'.$form_id.'" title="false" description="false"]');
}
add_shortcode('form-url', 'return_gform_embed');
You'd add the shortcode [form-url] to the page where you'd like the form to display.
So now the URL with ?form_id=6 would load the gravity form with id 6. I didn't test the whole javascript aspect but assuming you can change the URL and force a reload things should work out ok.
Here is what I ended up doing if it helps someone else out there:
<form class="ui form">
<select name="select" id="select" class="ui fluid search selection dropdown" onchange="location = this.options[this.selectedIndex].value;">
<?php
function return_gform_embed(){
$form_id = $_GET["form_id"];
return do_shortcode('[gravityform id="'. $form_id .'" title="false" description="false"]');
}
add_shortcode('form-url', 'return_gform_embed');
?>
<?php $myforms = RGFormsModel::get_forms(); foreach ($myforms as $form) { ?>
<option value="/prevention/sessions/?form_id=<?php echo $form->id ?>"> <?php echo $form->title ?> </option>
<?php } ?>
</select>
</form>
<?php echo do_shortcode('[form-url]') ?>
Related
1. Setup
We've added two layout dropdown fields to the page_list block's edit screen by overriding:
db.xml
page_list_form.php
Adding the fields to the view
2. In db.xml we've added:
<field name="gridSize" type="C" size="255">
</field>
<field name="gridPaddingStyle" type="C" size="255">
</field>
3. In page_list_form.php
We've added the slect fields to the block edit screen like this:
<div class="ccm-block-field-group">
<h2><? echo t('Grid layout')?></h2>
<p><? echo t('Grid size')?></p>
<?php
$gridSize = array(
'1up' => 'grid-list-item-single grid-unit-1',
'2up' => 'grid-unit-2',
'3up' => 'grid-unit-3',
'4up' => 'grid-unit-4',
'5up' => 'grid-unit-5',
'6up' => 'grid-unit-6'
);
if (is_array($gridSize)) :
?>
<select name="gridSize" id="selectGridSize">
<? foreach ($gridSize as $gridItem => $value) : ?>
<option value="<?= $value ?>" <?php if ($gridSize == $value) { ?> selected <?php } ?>>
<?= $gridItem ?>
</option>
<? endforeach; ?>
</select>
<? endif; ?>
<p><? echo t('Grid padding style')?></p>
<?php
$gridPaddingStyle = array(
'Padding' => '',
'No padding' => 'grid-no-padding',
'Hairline' => 'grid-hairline'
);
if (is_array($gridPaddingStyle)) :
?>
<select name="gridPaddingStyle" id="selectPaddingSize">
<? foreach ($gridPaddingStyle as $gridPaddingStyleItem => $value) : ?>
<option value="<?= $value ?>" <?php if ($gridPaddingStyle == $value) { ?> selected <?php } ?>>
<?= $gridPaddingStyleItem ?>
</option>
<? endforeach; ?>
</select>
<? endif; ?>
</div>
4. In the view.php we've added:
$gridSize = $controller->gridSize;
$gridPadding = $controller->gridPaddingStyle;
Which obviously pulls the data out of the database for use when we output the markup.
Everything works great except when we come to re-edit the block - essentially the values previously set for our custom fields don't get read and the dropdowns revert back to the first items in the select lists.
5. Question
How do we get the page_list edit screen to read the values previously set in the database?
Any pointers in the right direction would be much appreciated (sorry, can't work out how to get syntax highlighting working - wish the markdown was the same ad Github issues).
Cheers
Ben
Your problem here is that you're overwriting the variables in your edit view $gridSize = array(...) just before you're trying to access them, you can probably fix it by changing those array variable names to something semantic like "grid_size_options".
If that doesn't work, you can use $this->set to pass variables to the view from the controller edit method. Your edit method would look something like this:
public function edit()
{
$this->set('grid_size', $this->gridSize);
$this->set('grid_padding_style', $this->gridPaddingStyle);
}
and then your edit view can just magically access $grid_size and $grid_padding_style.
<select name="gridPaddingStyle" id="selectPaddingSize">
<?php
foreach ($gridPaddingStyle as $gridPaddingStyleItem => $value) {
?>
<option value="<?= $value ?>" <?= $grid_padding_style == $value ? 'selected' : '' ?> >
<?= $gridPaddingStyleItem ?>
</option>
<?php
}
?>
</select>
How I search my WordPress site pages with search box I placed in my site?
Currently I am using this code.
<form id="searchform" method="get" action="<?php bloginfo('siteurl')?>/" style="margin-left: -43px;">
<input type="text" name="" id="s" class="textbox" placeholder="Search" required/>
<input id="btnSearch" type="submit" name="submit" value="<?php _e('Search'); ?>" />
</form>
I used name="s" but it not do search properly. I want that if user right page1 name search box take it to siteurl/page1 and so for page2 and remaining page.
Thanks in advance
Try this :
function redirect_search() {
if (is_search() && !empty($_GET['s'])) {
wp_redirect(home_url("/").urlencode($_GET['s']));
exit();
}
}
add_action('template_redirect', 'redirect_search' );
Add above code in your functions.php file.
So now when you type something, it will redirect it to that page.
NOTE:If you type something related to the published post, it will redirect to that POST instead of what have you entered.
For example : If I type hello in search box, then it will redirect you to hello world(which is default post that comes during installation of wordpress).
This is what have for you.
<div id="content" class="textbox <?php echo of_get_option('blog_sidebar_pos') ?>">
<?php _e('Search for:',''); ?> "<?php the_search_query(); ?>"
<?php
if (have_posts()) : while (have_posts()) : the_post();
$format = get_post_format();
get_template_part( 'include/'.$format );
if($format == '')
get_template_part( 'include/standard' );
endwhile; else:
?>
<?php echo '<p><strong>' . __('There has been an error.', '') . '</strong></p>'; ?>
<p> <?php _e('return to home page', ''); ?> <?php _e('use the search .', ''); ?></p>
<?php get_search_form(); ?>
</div><!--no-results-->
<?php endif; ?>
<?php get_template_part('include/post'); ?>
I've added a select box audio option to the default gallery settings. Here's what I added to the functions.php file:
<?php
function add_custom_gallery_settings() {
global $post;
$attached_audio = get_attached_media( 'audio', $post->ID );
?>
<script type="text/html" id="tmpl-custom-gallery-settings">
<label class="setting">
<span><?php _e('Audio'); ?></span>
<select data-setting="audio">
<option value="">No Audio</option>
<?php foreach($attached_audio as $a): ?>
<option value="<?php esc_attr_e($a->ID); ?>">
<?php echo $a->post_name; ?>
</option>
<?php endforeach; ?>
</select>
</label>
</script>
<script>
jQuery(document).ready(function(){
wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({
render: function() {
wp.media.view.Settings.prototype.render.apply(this, arguments);
this.$el.append(wp.media.template('custom-gallery-settings'));
wp.media.gallery.defaults.audio = null;
this.update.apply( this, ['audio'] );
return this;
}
});
});
</script>
<?php }
add_action('print_media_templates', 'add_custom_gallery_settings');
?>
As you see, select box populates with audio attachments uploaded to the post. Because I generate those templates on print_media_templates hook, any audio files uploaded to the post, won't show up until I update/save the post and/or reload the page. Question is, what would be a good way to dynamically update those options when an audio attachment is uploaded?
I have the following piece of code which creates a drop down of a number of posts.
<?php
$mypostype = get_posts('post_type=rentals');
if($mypostype) : ?>
<form action="" id="myform">
<label for="myselect">Rentals</label>
<select id="myselect" name="select_post_type" onChange='document.location.href=this.options[this.selectedIndex].value;'>
<?php foreach ( $mypostype as $mypost ) : ?>
<option value="?rentals=<?php echo $mypost->post_name; ?>"><?php echo $mypost->post_title; ?></option>
<?php endforeach; ?>
</select>
</form>
<?php endif ?>
This is working brilliantly apart from one thing and that is being able to add a default value to the drop down list that links to no page, some text like 'Select Rental'.
It would be great if someone could explain how to add this value in.
Thanks for your time and help in advance.
By adding an <option> in the <select> and a slight change in the javascript onChange event by checking if the selected option value is not empty :
<?php
$mypostype = get_posts('post_type=rentals');
if($mypostype) : ?>
<form action="" id="myform">
<label for="myselect">Rentals</label>
<select id="myselect" name="select_post_type" onChange="((this.options[this.selectedIndex].value != '') ? document.location.href=this.options[this.selectedIndex].value : false);">
<option value="" selected="selected">Select Rentals</option>
<?php foreach ( $mypostype as $mypost ) : ?>
<option value="?rentals=<?php echo $mypost->post_name; ?>"><?php echo $mypost->post_title; ?></option>
<?php endforeach; ?>
</select>
</form>
<?php endif ?>
This should satisfy your needs...
By the way you could do like this to echo the post links (absolute links):
<option value="<?php echo get_permalink( $mypost->ID ); ?>"><?php echo $mypost->post_title; ?></option>
I have a custom post type for products. I have two TinyMCE editors (the standard and one for a summary field) loading correctly in the Dashboard. From the Dashboard side of things, everything is working correctly. Adds, updates. etc...
On the site though, output is loosing the line breaks (paragraph tags). Here is an example:
http://keg.brettatkin.com/products/complete-consulting-skills-learning-system/
I'm using the wp_editor function for this. (http://codex.wordpress.org/Function_Reference/wp_editor)
Here is my code:
<?php
function keg_product_fields (){
global $post;
$custom = get_post_custom($post->ID);
$keg_product_price = $custom["keg_product_price"][0];
$keg_product_link = $custom["keg_product_link"][0];
$keg_product_type = $custom["keg_product_type"][0];
$keg_product_featured = $custom["keg_product_featured"][0];
$keg_product_summary = $custom["keg_product_summary"][0];
$editor_id = "kegprodsummary"
?>
<p>
<label>Summary:</label><br />
<?php wp_editor( $keg_product_summary, $editor_id, $settings = array('textarea_name' => 'keg_product_summary') ); ?>
</p>
<p>
<label>Price:</label><br />
<input size="10" name="keg_product_price" value="<?php echo $keg_product_price; ?>" />
</p>
<p>
<label>Type:</label><br />
<select name="keg_product_type">
<option value="<?php echo $keg_product_type; ?>" selected="selected"><?php echo $keg_product_type; ?></option>
<option value="Book">Book</option>
<option value="CD">CD</option>
<option value="Downloadable">Downloadable</option>
<option value="Multimedia">Multimedia</option>
<option value="Virtual">Virtual</option>
</select>
</p>
<p>
<label>Link:</label><br />
<input size="65" maxlength="200" name="keg_product_link" value="<?php echo $keg_product_link; ?>" />
</p>
<p>
<input type="checkbox" name="keg_product_featured" value="Yes" <?php if (!(strcmp("$keg_product_featured","Yes"))) {echo "checked=\"checked\"";} ?>/>
<label>Featured Product</label>
</p>
<?php
}
function add_keg_product_box (){
add_meta_box(
"keg_product_info",
"Product Details",
"keg_product_fields",
"keg_products"
);
}
function save_keg_product_attributes ( $post_id )
{
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
return $post_id;
}
global $post;
update_post_meta($post->ID, "keg_product_price", $_POST["keg_product_price"]);
update_post_meta($post->ID, "keg_product_link", $_POST["keg_product_link"]);
update_post_meta($post->ID, "keg_product_type", $_POST["keg_product_type"]);
update_post_meta($post->ID, "keg_product_featured", $_POST["keg_product_featured"]);
update_post_meta($post->ID, "keg_product_summary", $_POST["keg_product_summary"]);
}
add_action ('admin_init', 'add_keg_product_box' );
add_action ('save_post', 'save_keg_product_attributes');
add_action ('publish_post', 'save_keg_product_attributes');
?>
Any ideas here?
Thanks!
Brett
You have to apply the output filters with the apply_filters function in the page where you want to display your summary.
Example:
<?php
$summary = get_post_meta(...);
echo apply_filters('the_content', $summary);
?>
Try using wpautop() when saving the content or when showing it (I recommend you to use it when saving, for performance).
This function adds paragraphs throughout the text depending on the line breaks.