Forms in GeoDirectory Tabs
This topic contains 15 replies, has 4 voices, and was last updated by Alex Rollin 7 years ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
April 18, 2018 at 8:59 pm #427169
I just cant figure out why the Forms in GeoDirectory Tabs will not work with simple html contact form.
I followed instructions on this link: https://wpgeodirectory.com/formidable-forms-in-geodirectory-tabs/
It creates a tab if e-mail is set correctly but just will not “grab” the email address, tryed echoing it out and send a variable but im missing something.
Please look over it and see if you spot an error, its 95% just copy and paste from tutorial and still nothing. I have not tryed downloading “Formidable” plugin an using its own shortcode, as i will not be using it due to slowing down my site.
Code inside functions.php
// this line tells the tabs function to run our new function to add a new tab add_filter('geodir_detail_page_tab_list_extend', 'geodir_detail_page_tab_list_extend'); // this function adds the tab to the tabs list (but not the content) function geodir_detail_page_tab_list_extend($tab_array) { // the $post var contains all the listing info so we can add conditions global $post; // only add the tab if the post type is <code>gd_place</code> and the email field has been added to the listing if ($post->post_type=='gd_place' && $post->geodir_hpvorm) { $tab_array['booking_form'] = array('heading_text' => 'BOOK NOW', 'is_active_tab' => '', 'is_display' => 1, 'tab_content' => '', ); } return $tab_array; } // this action allows the tab content to be changed or added add_action('geodir_after_tab_content', 'geodir_booking_form_content', 10, 1); // this function adds the content to our new tab function geodir_booking_form_content($tab) { //if the tab exists then we know it has passed the criteria and we can add the content if ($tab == 'booking_form') { echo do_shortcode('[formidable id=2]'); } } // this action tells the form to call our function to add a new field add_action('frm_entry_form', 'geodir_add_hidden_field'); // this function adds our field to the form function geodir_add_hidden_field($form) { // our example booking form has an ID of <code>2</code> so we only want to add the field to that form if ($form->id == 2) {// only send if the form id is 2 global $post; echo '<input type="hidden" name="gd_place_id" value="' . $post->ID . '">'; } } // this tells the formidable form to check our function before sending add_filter('frm_to_email', 'geodir_custom_set_email_value', 10, 4); // this function will add the listing email to the recipiants list when submitted function geodir_custom_set_email_value($recipients, $values, $form_id, $args) { // only run if the submited form is our booking form with ID <code>2</code> if ($form_id == 2 ) {// only send if the form id is 2 //check if the place id is submitted $post_id = (isset($_POST['gd_place_id']) && $_POST['gd_place_id']) ? absint($_POST['gd_place_id']) : ''; if ($post_id) { // we found a post id so we can use it to get the place email address $place_email = geodir_get_post_meta($post_id, 'geodir_hpvorm'); } // if we have a place email address we then add it to the list of email recipiants if ($place_email) { $recipients[] = $place_email; } } return $recipients; } // tell formidable to call our function when sending the form add_filter('frm_email_subject', 'geodir_booking_change_subject', 10, 2); // add the listing name to the function geodir_booking_change_subject($subject, $atts){ extract($atts); $post_id = (isset($_POST['gd_place_id']) && $_POST['gd_place_id']) ? absint($_POST['gd_place_id']) : ''; // if form is our booking for and the post id exists if($form->id == 2 && $post_id){ $place_name = get_the_title( $post_id ); $subject = 'Booking form for: '.$place_name; //Replace Thank You with your email subject } return $subject; } add_action( 'wp_ajax_gd_contact_form_send', 'gd_contact_form_send' ); add_action( 'wp_ajax_nopriv_gd_contact_form_send', 'gd_contact_form_send' ); function gd_contact_form_send(){ if(isset($_POST['gd_name'])){$gd_name = esc_attr($_POST['gd_name']);}else{die('error');} if(isset($_POST['gd_email'])){$gd_email = esc_attr($_POST['gd_email']);}else{die('error');} if(isset($_POST['gd_subject'])){$gd_subject = esc_attr($_POST['gd_subject']);}else{$gd_subject='';} if(isset($_POST['gd_message'])){$gd_message = esc_attr($_POST['gd_message']);}else{die('error');} if(!isset($_POST['name']) || (isset($_POST['name']) && $_POST['name'])){die('error');} $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: '.$gd_email . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $message = "From: $gd_name - $gd_email \r\n"; $message .= "Subject: $gd_subject \r\n"; $message .= " \r\n"; $message .= "Message Body: \r\n"; $message .= "$gd_message \r\n"; $message .= " \r\n"; $message .= "This e-mail was sent from a contact form on GeoDirectory (http://wpgeodirectory.com)\r\n"; wp_mail( $recipients, 'Simple Contact Form :: '.$gd_subject, $message, $headers ); echo "Your message was sent successfully. Thanks ".$gd_name; die(); } //shortcode privaat hinnapäringu vormi näitamiseks add_shortcode('formidable', 'privaatHinnaParing'); function privaatHinnaParing($form){ include 'hinnaparinguvorm.php'; }
Code inside hinnaparinguvorm.php
<?php ?> <!DOCTYPE html> <html> <head> </head> <style> .form{ max-width: 100%; min-width: 25%; border-width: 2px; border-color: #CCCCCC; border-radius: 0px; color: #222222; font-size: 14px; margin: 0px; background-color: #FFFFFF; padding-right: 20px; } .content{ margin: 0px; } .form label{ color: #222222; font-size: 14px; display: block; } .form input[type=radio], input[type=checkbox]{ margin: 10px; width: 13px; } .form div{ display: block; } .form input, form textarea, form select{ border-width: 1px; border-style: solid; border-color: #CCCCCC; border-radius: 3px; padding: 8px; width: 100%; } .form h1{ font-size: 40px; color: #607A75; padding: 0px; margin: 0px; margin-bottom: 10px; border-bottom-style: dotted; border-bottom-color: #CCCCCC; border-bottom-width: 2px; border-radius: 0px; background-color: #FFFFFF; } .intro{ margin-bottom: 10px; } .clear{ clear: both; } .form textarea{ height: 150px; width: 100%; } .form input[type=submit]{ width: 100%; background-color: #FF8333; color: #fff; margin: 0; padding: 15px 10px !important; float: left; font-size: 20px; } .field{ margin-bottom: 7px; } </style> <body> <div id="gd_contact_form"> <form id="form" class="form" accept-charset="UTF-8" enctype="application/x-www-form-urlencoded" method="post"> <div class="content"> <div id="section0"> <input id="name" style="display: none;" type="text" placeholder="Your Name (required)" /> <div class="field"><input id="gd_name" required="" type="text" placeholder="Your Name (required)" /></div> <div class="field"><input id="gd_email" required="" type="email" placeholder="Your Email (required)" /></div> <div class="field"><input id="gd_subject" type="text" placeholder="Subject" /></div> <div class="field"><textarea id="gd_message" placeholder="Your Message" wrap="hard" required></textarea></div> <input id="gd_send" class="button download-btn" name="Send" type="submit" value="Send" /> </div> </div> </form> </div> <div id="gd_contact_form_msg" style="display: none;"></div> <script> jQuery(document).ready(function() { jQuery('.form').submit(function(event) { event.preventDefault(); var form = jQuery('#form').val(); var name = jQuery('#name').val(); var gd_name = jQuery('#gd_name').val(); var gd_email = jQuery('#gd_email').val(); var gd_subject = jQuery('#gd_subject').val(); var gd_message = jQuery('#gd_message').val(); jQuery.ajax({ type: 'POST', url: geodir_all_js_msg.geodir_admin_ajax_url, async: false, data: { action: 'gd_contact_form_send', name: name, gd_name: gd_name, gd_email: gd_email, gd_subject: gd_subject, gd_message: gd_message }, beforeSend: function() { jQuery("#gd_send").prop('disabled', true); }, success: function(returnData) { jQuery('#gd_contact_form_msg').html(returnData); jQuery('#gd_contact_form').hide("slow", function() { jQuery('#gd_contact_form_msg').show("fast"); }); } }); event.preventDefault(); }); }); </script> </body> </html>
April 19, 2018 at 1:56 am #427191Hi Kala,
Please share the URL of the site in question so we can take a better look at it and also WP temp admin access to your site. You can post the details here using the private reply option below.
April 19, 2018 at 7:40 am #427210This reply has been marked as private.April 19, 2018 at 10:35 am #427223looking of the code it seemes correct ?
i have tryed echoing out $recipients and $place_email without success.
The form and email part are working, sening to a fixed email works.
Problem is it will not get the geodir_hpvorm into a variable, it might me due that stupid form id = 2.
I tryed removing it (just using $form) and tryed making my shortcode a id = 2.i just cant figure out why the first part of it works (recognicing a “hpvorm” email set and creating a new tab with shortcode echo) and suddenly it cant get the email to echo out with variable…
April 19, 2018 at 11:00 am #427229Hi Kala,
Please provide us FTP credentials, i need to check code and some debugging.
Kiran
April 19, 2018 at 11:07 am #427231This reply has been marked as private.April 19, 2018 at 11:56 am #427239Hello Kala,
The problem has been fixed, it was missing post id because you did not added hidden field to get post_id variable.
Kiran
April 19, 2018 at 12:24 pm #427246Hello Kiran,
Thats what i get for working till 2 am …
Thank you so much for such fast help, this has made my geodir site semi-automatic and awesome !
April 19, 2018 at 1:14 pm #427253Thanks for letting us know 🙂
April 19, 2018 at 3:38 pm #427263sorry but i found an error.
It only sends to an admin email now because of the if empty loop.The code has set up to send to geodir_email, but i needed to send it to geodir_hpvorm set email.
So i in:$place_email = ''; $post_id = (isset($_POST['gd_place_id']) && $_POST['gd_place_id']) ? absint($_POST['gd_place_id']) : ''; if ($post_id) { $place_email = geodir_get_post_meta($post_id, 'geodir_email'); } if (empty($place_email)) { $place_email = geodir_get_site_email_id(); }
The:
$place_email = geodir_get_post_meta($post_id, 'geodir_email');
and:
if (empty($place_email)) { $place_email = geodir_get_site_email_id(); }
To:
$place_email = geodir_get_post_meta($post_id, 'geodir_hpvorm');
and:
if (empty($place_email)) { echo "bad"; }
So it only echos bad now, it still cant get the email set in the geodir_hpvorm, what is the same field that generates the BOOK NOW tab itself
April 19, 2018 at 3:41 pm #427264the same is with $subject variable, in tutorial it was set up to get listing title but it does not echo also. Something is wrong getting the data to echo out.
April 19, 2018 at 8:32 pm #427328This reply has been marked as private.April 20, 2018 at 5:27 am #427358Hi Kala,
This would be considered a customization and it is beyond support.
Please contact a GD Expert: https://geodirectoryexperts.comKiran
April 20, 2018 at 9:28 am #427375Hi Alex,
Yeah im waiting for the GDV2 to come out, it just sucks i have scheduled my site launch within 2 months.
I would even consider using it, if it supported all the addons in beta, that i have installed for v1 like billing, translating etc.
Is there any kind of an estimate when the core will be released ?
As i understand, plan is to test add-ons during beta and then do full launch, not a launch and then make add-ons releases?Hi Kiran,
Im sorry but i am using a written example that should work and i am only asking why is it not functioning as in the tutorial.
https://wpgeodirectory.com/formidable-forms-in-geodirectory-tabs/
https://wpgeodirectory.com/contact-form-7-vs-simple-html-form/I understand if i try to customize that, then it is beyond support. If i could just understand why the e-mail (and title) is not echoing out in to function, i could start to customize it on my own.
__________________________________________________________________
If its any help i can share my customization i tryed yesterday night.
I tryed to pull the info from mySQL database
query:$place_name = get_the_title( $post_id ); $query = 'SELECT geodir_hpvorm FROM wp_geodir_gd_place_detail WHERE post_title LIKE '; $query .= "'%$place_name%'";
and it echoed out right away. (with foreach loop)
Only thing is my own form im not using a function but a
if(filter_has_var(INPUT_POST, 'submit')){
and it breakes the tab…
it get an error ofgeodir_advanced_search_js_msg is not defined
So right now il start to try if i can make ajax call a function that includes variables to mail.
__________________________________________________________________If i could get the sample form to work as it should, it would be done, case closed.
April 20, 2018 at 10:29 am #427380How i got it to work is this:
1. Included codes only to show a tab and echo shortcode if email is set in to functions.php
2. Created shortchode form (same as in https://wpgeodirectory.com/contact-form-7-vs-simple-html-form/)
Added before that for a query to mysql database to fetch company name a nd the set email in geodir_hpvorm3. added 2 extra hidden inputs to echo data fetched from mysql
4. added those 2 values to jQuery function5. defined those valus in functions.php as variables
6. set the variables in email formI think il start to customize this form then, despite its an ugly wp_mail
If someone could let me know why i cant use my own forms
if(filter_has_var(INPUT_POST, 'submit')){
and it errors
geodir_advanced_search_js_msg is not defined
i would love to know ! It would let me use the mail function instead and include an awesome form to GD.
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket