- This topic has 10 replies, 4 voices, and was last updated 6 years, 2 months ago by
Steve.
-
AuthorPosts
-
-
November 11, 2015 at 1:28 pm #4928
kattagamiMemberHello,
I’ve wondered if there is a way to build a contact form with Piklist 0.9.9.6?
For a contact form, I don’t need to save the field datas in the database but just get them and then call the wp_mail() function.
Is there any hooks to perform that?
Thx
-
November 12, 2015 at 5:34 pm #4952
SteveKeymaster@kattagami– You would use the Piklist hook
piklist_save_field-{$scope}Here’s how to get started:
1. Create your frontend form
2. You still have to define thescopefor each field, however, since you’re not saving the data choose something unique likecontact.'scope' => 'contact'
3. In your main plugin file include this code:function my_contact_form_email($fields) { piklist::pre($fields); die(); } add_action('piklist_save_field-contact','my_contact_form_email');When you save your form Piklist will trigger this function and you will see the array of field data that you have access to. Just loop through the array and create your mailer.
Let us know if this works for you.
-
November 13, 2015 at 10:18 am #4957
kattagamiMemberThanks very much for your help Steve, you always come with a solution 🙂
It’s works like a charm! but …I use the “message” comment on top of my form php file to tell to my user that the message has been sent when they submit it.
However, if a field doesn’t validate, the error message AND the “message” (which said everything is ok) both display above my form.
How display the “message” only if there is no validate error messages?
Thx
Gilles -
November 16, 2015 at 3:55 pm #4983
SteveKeymasterThis may be a bug. Looking into it.
-
November 28, 2015 at 1:34 pm #5143
StefanMemberI’m creating travel booking website (piklist only) with exactly same issue. Hope this fix soon 🙂
-
December 9, 2015 at 3:30 am #5267
MarcMemberHi there,
Just encountered the same problem.
I looked around, and if inclass-piklist-form.phpline 3775 ->public static function notices
you add&& empty( Piklist_Validate::notices( self::$form_id, true) )in the if statement it sorts the problem.Full code:
public static function notices($form_id = null) { if (!empty(self::$form_submission) && self::$form_id && self::$form_id == $form_id && isset(self::$forms[self::$form_id]) && !empty(self::$forms[self::$form_id]['data']['message']) && empty( Piklist_Validate::notices( self::$form_id, true) ) // Checks if there are any errors ) { piklist::render('shared/notice', array( 'id' => 'piklist_form_notice' ,'notice_type' => 'update' ,'dismiss' => is_admin() ,'content' => self::$forms[self::$form_id]['data']['message'] )); } }At least it works for the frontend forms.
Not sure if it would have any effect somewhere else! -
December 9, 2015 at 4:21 am #5269
MarcMemberI have an other question concerning the frontend form, and in that case a Contact form.
I would like to change the content of the page if the submission is successful.For exemple
if(success) : Notice: Thank you for Your message. Whatever... Content of your message: ... ... [button Click here to go back to the form] else : display formIs there a way to do that?
I’ve found the elements necessary for that in the PiklistForm class, but the variables are private, so not accessible right now. -
December 9, 2015 at 4:41 am #5270
MarcMemberWell, I’ve found a way to do it.
Here it is:
(all the code is in the form’s file)$form_id = $_POST['_']['form_id']; // if we don't have a form posted OR if the form posted contains errors: if( !$form_id || !empty( Piklist_Validate::notices( $form_id, true) ) ) { //display form piklist('field', array( 'type' => 'text ,'scope' => 'contact' ... )); .... } else { ?> <h3>Your request:</h3> <?php foreach( $_POST['_contact'] as $label => $value ) { echo '<p><strong>' . $label . ':</strong> ' . $value . '</p>'; } ?> <a href="<?= the_permalink(); ?>" class="btn btn-default">Go back to Contact form</a> <?php } -
December 9, 2015 at 10:54 am #5275
SteveKeymaster@marcusing– Great job!
Here’s a Pro Tip: Everything in Piklist is dynamic, including the underscore in the $_POST object. “_” is set as
piklist::$prefix, but can be changed if you want to:So instead of:
$form_id = $_POST['_']['form_id'];
Use this:
$form_id = $_POST[piklist::$prefix]['form_id'];
Just keeps things future proof.
-
December 9, 2015 at 4:02 pm #5284
MarcMemberThanks @Steve.
I thought there was a more clever way to do 🙂
So I suppose$_POST['_contact']should be$_POST[ piklist::$prefix . 'contact' ]right? -
December 9, 2015 at 4:24 pm #5286
SteveKeymasteryup!
-
-
AuthorPosts
- The topic ‘Build a Contact Form with Piklist 0.9.9.6?’ is closed to new replies.