Make the email field not required
-
Hello,
I’m looking to make the “Email” field in the Add form not required since many of my users will be using their phone number as a contact instead. Is this possible?
Thanks!
-
Hi, i am afraid the Email field is one of few (or maybe even the only) field that needs to be filled, without it the [adverts_add] shortcode might break when submitting or saving the Advert, as it expects to use the provided email address in a couple of places.
Maybe you can try to assign the admin email always and hide the admin field with css or from the tpl?
Hi, thank you for the prompt responses.
Yes I was also thinking of simply assigning the admin email – how would I do this? I shouldn’t have a problem hiding it with CSS.
I suppose I could then add a new field for Email, which is not required.
Hi, try adding the following code in your theme functions.php
add_filter( "adverts_form_load", "hide_email_field" ); function hide_email_field( $form ) { if( $form['name'] != "advert" || is_admin() ) { return $form; } foreach( $form["field"] as $key => $field ) { if( $field["name"] == "adverts_email" ) { $form["field"][$key]["type"] = "adverts_field_hidden"; } } return $form; } add_action( "init", "set_email_field_value"); function set_email_field_value() { if( adverts_request( "_adverts_action" ) == "preview" ) { $_POST["adverts_email"] = get_option( "admin_email" ); } }
it should hide the email field and prefill its value with admin email when needed.
Hello,
Sorry for delay and thank you very much for the code! I’ve applied it to my functions.php as suggested and added a custom field for email. Submitting new ads works well even though the required email field remains blank.
Just wondering now how I could display the new email custom field in the “Show contact information” dropdown?
Thanks
Hi, there is no easy way to do it i am afraid, you would need to replace the AJAX function which WPAdverts is using to get the contact data.
add_action("init", "my_init", 20); function my_init() { remove_action('wp_ajax_nopriv_adverts_show_contact', 'adverts_show_contact'); add_action('wp_ajax_nopriv_adverts_show_contact', 'my_adverts_show_contact'); }
function my_adverts_show_contact() {
// your custom function here.
}
`The code above you can add to your theme functions.php file, next you need to open file wpadverts/includes/functions.php, find function adverts_show_contact() copy its body to my_adverts_show_contact() and customize to your needs.
Thank you Greg, really appreciate the quick responses!
I can’t find the function you mention but rather there’s an “adverts_single_contact_information” function.
Therefore I’ve tried the code below in my own theme’s functions.php file where I’ve replaced the default “Email” with my custom field “Email Address” but it doesn’t seem to work:
add_action("init", "my_init", 20); function my_init() { remove_action('wp_ajax_nopriv_adverts_show_contact', 'adverts_single_contact_information'); add_action('wp_ajax_nopriv_adverts_show_contact', 'my_adverts_single_contact_information'); } function my_adverts_single_contact_information() { ?> <div class="adverts-single-actions"> <a href="#" class="adverts-button adverts-show-contact" data-id="<?php echo $post_id ?>"> <?php esc_html_e("Show Contact Information", "adverts") ?> <span class="adverts-icon-down-open"></span> </a> <span class="adverts-loader adverts-icon-spinner animate-spin"></span> </div> <div class="adverts-contact-box"> <p class="adverts-contact-method"> <span class="adverts-icon-phone adverts-contact-icon" title="<?php _e("Phone", "adverts") ?>"></span> <span class="adverts-contact-phone"></span> </p> <p class="adverts-contact-method"> <span class="adverts-icon-mail-alt adverts-contact-icon" title="<?php _e("Email Address", "adverts") ?>"></span> <span class="adverts-contact-email"></span> </p> </div> <?php }
Here is my custom field code:
add_filter( "adverts_form_load", "my_adverts_form_load" ); function my_adverts_form_load( $form ) { if( $form["name"] != "advert" ) { return $form; } $form["field"][] = array( "name" => "email_notrequired", "type" => "adverts_field_text", "order" => 10, "label" => "Email Address", "is_required" => false, ); return $form; }
Not sure if I’m going in the right direction. Any suggestions please?
Many thanks
-
This reply was modified 8 years, 4 months ago by
ReD.
Hi,
Sorry please don’t worry about the above – I’ve simply hidden the dropdown using CSS and included the phone and email custom fields as described at https://wpadverts.com/documentation/custom-fields/
While it’s clear how to add custom fields etc to the Ad Details page, how do I do the same for the Ads List page? In addition I’d like to include the full description of ads on the Ads List page too
Thank you
Hi, in the [adverts_add] you can remove fields by removing them from “field” array, for example lets assume you wish to remove “location” field, you can do it using following code
add_filter( "adverts_form_load", "customize_adverts_add" ); function customize_adverts_add( $form ) { if( $form['name'] != "advert" ) { return $form; } foreach( $form["field"] as $key => $field ) { if( $field["name"] == "adverts_location" ) { unset( $form["field"][$key] ); } } return $form; }
Thank you, sorry I mean how do I add my custom fields and the ad description to the Ads List [adverts_list] page?
Documentation (https://wpadverts.com/documentation/custom-fields/) only mentions how to add them to the Ad Details page.
Thanks
Currently, you would need to modify the wpadverts/templates/list-item.php file to do that.
-
This reply was modified 8 years, 4 months ago by
- The topic ‘Make the email field not required’ is closed to new replies.