I have a image upload field and a URL field in CF7 and how can i make it that a user needs to use one of the 2 fields. So select a image or put a link in the URL field?
I already search a little and i saw some options to do it on normal txt fields but that was not working for me i think because of the upload field.
I don't think that CF7 can do this out of the box. You would probably have to go down to code to solve this issue.
Since I don't know how big you form is this could maybe help you out:
https://wordpress.org/plugins/cf7-conditional-fields/ - Plugin for conditional field inside CF 7
https://conditional-fields-cf7.bdwm.be/conditional-fields-for-contact-form-7-tutorial/ - Tutorial how to use it.
So with this plugin you could basically create a dropdown in which the user first has to select if he wants to use an image or use the URL field. After that, only his selection would pop up and he can proceed with the selected option.
If you want to do the coding you can add some JS to the site and check on validation if one of the two fields is filled out or not.
If the plugin solves your issue - great, if not let me know so I can help you out with the code validation.
###Edit since we need code###
So to dynamically alter the required function I found a pretty good post:
Dynamically Disable Contact Form 7 Field Validation
Some Background information:
CF7 does the validation on server side, so working with JS or JQuery won't help in this case. What we are going to do is manipulate the server validation. If one of the fields is filled out correctly we are just putting content in the other field on the validation.
I created a form that looks like this:
The form in CF7 module looks like this:
<label> URL
[url* url ]
<label> Image
[file* image ]
[submit "Send"]
Then you just have to add the following code to your functions.php file of your theme.
function alter_wpcf7_posted_data( $data ) {
if($_FILES['image']['size'] != 0) {
$_POST['url'] = "http://fileupload.com";
}
if($_POST['url'] != "") {
$_FILES['image']['tmp_name'] = "urlprovided";
}
return $data;
}
add_filter("wpcf7_posted_data", "alter_wpcf7_posted_data");
Normally both fields will be empty in the beginning, if one of them has contet the other one gets fake data and the use has only to provide one.
Let me know if this helps.
I think i found the solution with a little help of the code from #Aschi33.
I made the image (upload field) required and the url field not. So there needs to be alwasy a image selected. But with this code:
function alter_wpcf7_posted_data( $data ) {
if($_POST['url'] != "") {
$_FILES['image']['tmp_name'] = "urlprovided";
}
return $data;
}
add_filter("wpcf7_posted_data", "alter_wpcf7_posted_data");
if the URL field is filled in then the required image field is faked to be filled in so then the URL field can be used to submit the form.
And then with this code:
function cf7_custom_url_check( $result, $url ) {
if ($result) {
$regex='/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/';
if (!preg_match($regex,$url)) $result=FALSE;
}
return $result;
}
add_filter( 'wpcf7_is_url', 'cf7_custom_url_check', 10, 2 );
I check if its a real video link from YouTube and if not the field will give a error.
Related
I've got a Typerocket form (within Wordpress) and I'm trying to make a conditional field.
Like if the Type field is Image, show and Image field afterwards and if the Type field is Quote have a text (editor) field afterwards.
I can't find anything about Conditional fields in Typerocket's doc.
Here's what I got right now.
echo $form->repeater('pj_images_du_projet')->setLabel("Images du projet")->setFields([
$form->select('Type')->setOptions([
"Image"=>'image',
"Vidéo"=>'video',
"Témoignage"=>'temoignage'
]), //Type is what chooses what fields are below. Options are Image, Video or Testimonial
$form->image('image')->setLabel('Image'), //image only
$form->text('video')->setLabel('Vidéo'), //video only
$form->toggle('autoplay')->setLabel('Autoplay'), //video only
$form->textarea('temoignage')->setLabel('Témoignage'), //temoignage only
$form->text('auteur')->setLabel('Auteur'), //temoignage only
]);
Created a JS that does the work.
JS
jQuery('body').ready(function(){
jQuery("body").on('change','.is-conditional-selector',function(){px_redoConditionals();})
px_redoConditionals();
})
function px_redoConditionals(){
jQuery('body').find('.is-conditional-selector').each(function(){
var repeater = jQuery(this).parent().parent().parent();
console.log(repeater.attr('class'));
repeater.find('.is-conditional').removeClass('px-show');
//console.log(jQuery(this).val());
repeater.find('.is-conditional.is-conditional-'+jQuery(this).val()).addClass('px-show');
})
}
CSS
.is-conditional:not(.px-show){
display:none !important;
}
And then I add this to the select that changes which section is shown
->setAttribute('class','is-conditional-selector')
And this on the fields that need to be shown or hidden
->setAttribute('class','is-conditional is-conditional-[value of the select to show this]'),
In my wordpress website, i am using a gravity form to complete one online application process with about 10 to 12 pages of form filling. Once a user fills out all the process and make it to payment method page (which is the last before page), he sees display of details about payment method he has chosen in previous page.
In the previous page, i had 3 options to choose like credit card, check, and money order. Now selecting credit card, works fine and displays its details in the next page. But for the other two - check and money order, anything among these are selected, the next page displays a black details area. I need to display of details according to the selection.
This is mainly because of the Jquery issue in displaying content.
In this page, there seems to be code like the below to display the contents and to stop them from displaying.
in Plugins/gravity_forms/form_display.php
<div id='gform_page_{$form["id"]}_{$field["pageNumber"]}' class='gform_page{$custom_class}' {$style}>
<div class='gform_page_fields'>
<ul class='gform_fields {$form['labelPlacement']}'>";
and li like
$style = !empty($form) && !IS_ADMIN && RGFormsModel::is_field_hidden($form, $field, $field_values) ? "style='display:none;'" : "";
$field_id = IS_ADMIN || empty($form) ? "field_$id" : "field_" . $form["id"] . "_$id";
return "<li id='$field_id' class='$css_class' $style>" . self::get_field_content($field, $value, $force_frontend_label, $form == null ? 0 : $form["id"]) . "</li>";
}
when form current page came then it show that fields other fields are display :none
I need to know how these process of display:block and none works accordingly in this situation. Which file is causing these all actions?
Here
i faced one more issue
for few id it does not show fields
so then for this i coded Themes/function-application.php
add_filter('gform_pre_render_'.$form_id, 'populate_checkbox',10);
function populate_checkbox($form)
{
in this ....
my code
if($current_page==12){
require_once 'includes/application_form/payment.php';
?>
<script type="text/javascript">
alert('inside');
jQuery("#field_1_212").css("display","block");
jQuery("#field_1_129").css("display","block");
alert('after');
</script>
<?php
}
?>
here i find only first alert inside worked fine .. and then jquery, alert after are all not worked..
so i need to know which file i need to modify ??
Thanks in advance..
Hey Guys, hopefully you can help. this is my first WP Plugin, and it allows user to add car details to a DB which works fine, then outputs those details to a page.
I can add cars just fine, but now I need to be able to delete them and edit them. And this is where im a little stumped... to edit, i want to click on the item from the list up the top and its details be placed in the fields below, edit then click save to update it.
but im struggling to find out how to grab the data? should i be using Ajax or is there another way?
thanks.
I have created such plugin without using ajax
In the table I've created 2 links - "edit" and "delete", and sent the id of the element
Edit
Delete
if $info=del
if($info=="del")
{
$delid=$_GET["did"];
$wpdb->query("delete from ".$table_name." where id=".$delid);
}
and similarly for "edit"
$act=$_REQUEST["act"];
if($act=="upd")
{
$recid=$_REQUEST["id"];
$sqlL="select * from ".$table_name = $wpdb->prefix . "member where id=$recid";
$result = mysql_query($sqlL) or die ('Error, query failed');
if (mysql_num_rows($result) > 0 )
{
if($row = mysql_fetch_assoc($result))
{
$id = $row['id'];
$film_name = $row['film_name'];
// etc
}
}
}
And also I've added submenu page, where I'm adding or editing records
I am working on a module where i have a page that must have no regions or extra content. A kind of "please wait" page.
How do i diable all extra content (regions menus...etc) ? i think Panels has this ability but i can't find the snippet it uses.
On another hand is it possible for a module to specify a special custom page ? like the maintenance-page for example ?
The page.tpl.php method is not flexible. It is based on a presentation logic. You should use hook_page_alter() for a business logic solution. For example:
function yourmodulename_page_alter(&$page) {
if (current_path() == 'node/add/yourcontenttype') {
unset($page['sidebar_first']);
}
}
Also look at very powefull Context module.
You can create a an extra page.tpl.php specifically for the page where you want to hide the regions. The naming principle is similar to the one for nodes.
Let's say you have a page with the url example.com/content/contact. A template named page--content--contact.tpl.php would serve that page and any page that starts with that url, i.e. the page example.com/content/contact/staff would also use that template (I think).
Check the classes of the body element for clues to what you can name your template, most themes will print that. In my example above, the body element would include the class page-content-contact.
Only thing i can think of is writing checks in your page.tpl.php file to see if you on that "page" your talking about and not printing out the regions/menus, or use a different template. http://drupal.org/node/223440
If you want to do this before the blocks are rendered:
/**
* Implements hook_block_list_alter()
*
* Hides the right sidebar on some pages.
*/
function THEME_NAME_block_list_alter(&$blocks) {
// This condition could be more interesting.
if (current_path() !== 'node/add/yourcontenttype') {
return;
}
// Go through all blocks, and hide those in the 'sidebar_second' region.
foreach ($blocks as $i => $block) {
if ('sidebar_second' === $block->region) {
// Hide this block.
unset($blocks[$i]);
}
}
}
Note: Interestingly, this hook seems to work no matter if you have it in your theme or in a module.
(Please correct me if I'm wrong)
This is the same question of this link:
Removing [nid:n] in nodereference autocomplete
According with the first answer (Grayside) I've created my own module and activated. Then I create a new content, I look sth up in the nodereference field and finally select it -> it works (Doesn't appear the [nid:n]).
But, when I view/preview or save or edit the content, the [nid:n] appears again.
Anybody can help me?
When viewing the node, it is the theming function for the field that determines what is displayed, so you need to overwrite it, if you want to change the output.
The value when you edit the node, is determined by the #default_value property, so you need to change in your hook_form_alter()
Thanks for the answer.
I've found the solution. (At least in my case)
I change the code of this file:
drupal\modules\cck\cck\modules\nodereference.module
function nodereference_autocomplete_value($element, $edit = FALSE)
{
...
// $value .= ' [nid:'. $nid .']'; --> Comment this line
return array($field_key => $value);
}
It works very well! Doesn't appear in any case: Not in selected from the list, nor when save, edit, etc.
Regards!