Hello i'm using a Drupal 8, i would like to create a form and on submit it send a PDF file at the email in the form.
You might want to use the Rules module if you don't want to do any coding.
Easiest way for creating webforms in drupal is by using Webform module:
https://www.drupal.org/project/webform
Use hook_form_alter(&$form, FormStateInterface $form_state, $form_id) to add your custom submit handler to that form. Inside your hook function you should add code that looks something like this:
$form['actions']['submit']['#submit'][] = 'your_custom_handler_function_name';
Basically that $form['actions']['submit']['#submit'] is a list of submit handler (an array) and you are just adding yours. It may be a bit different - you'll have to inspect and see exact structure. Don't forget to clear the cache after adding your function!
Then your custom submit handler will be called when form is submitted so inside your function you can send an email with PDF attached to it.
Your custom submit handler should look like this:
function your_custom_handler_function_name($form, FormStateInterface $form_state) {
...
For sending emails with attachments you'll have to install additional module, like Swift Mailer:
https://www.drupal.org/project/swiftmailer
or some similar.
Related
I have a simple HTML form that captures someone's name, email address, company name, and a few other items. I want to use onsubmit to run my form validation function before the data is submitted to my MYSQL database.
I have the form built inside of a text box using Wordpress Visual Composer. When I update the box, the form stays put, and works, but any call such as onsubmit, onclick etc.. get stripped out, regardless of what I name the function.
Why does this happen, and how do I get around it to create a form validation function for my basic forms?
Thank you,
- Joe
I am really hoping someone can help. Searched my heart out, but didn't seem to find anything on this.
What I want to do is:
User is in a page where cf7 is, and fills in details. I then redirect the user to a separate page using on_sent_ok: "location.replace('pageurl');"
How do I display the value of the user input name on the redirection page?
If you don't want to do any programming or need your client to be able to easily edit what is on each page of the form you can use the following plugin:
Contact Form 7 Multi-Step Forms
You can just add tags to the form builder that will separate pages. I chose this plugin because I wanted my client to be able to edit the form easily. If you use the code mentioned by purvik7373 you will need to make the updates to change form fields.
First change the on_sent_ok to:
on_sent_ok: 'my_custom_redirect();'
then create that my_custom_redirect() function in the page that displays the form:
<script>
function my_custom_redirect() {
var your_name = document.getElementById('YOUR_NAME_FIELD_ID').value; // get value from your input field (YOUR_NAME_FIELD_ID) id
var url = 'https://www.example.com/?name='+your_name+''; // your redirection url
window.location = url;
}
</script>
I am including a webform that a user will fill out on a job listing page if they are interested in the job. The job listing page itself is created from a custom module as the result of a job search and I am including the webform like so:
render(node_view(node_load(363), 'full', NULL));
where 363 is the webform id. So I'm trying to figure out how I can pass at least the job number into the webform. I know I can edit the webform to include a hidden field where I can get values from the URL like %get[key] but I am using clean URL's so I do not have a specific key in the URL like www.example.com/jobs?job_number=1234 where I can grab "job_number". My actual URL looks like this: http://www.example.com/job-board/view/41904 so I need to grab 41904 in my webform. How can I accomplish this? Can I use a special token in my webform hidden field or is there a way in my custom module to somehow pass the job number to the webform when I go to display it on the job detail page?
Ok so I figured this one out. So it looks like right before I call my webform, I can actually set a $_GET parameter and it will pass to the webform. So I did this in my custom module:
// send job_number to webform via $_GET
$_GET['job_number'] = $job_number;
render(node_view(node_load(363), 'full', NULL));
Now in my webform, I added a hidden form field that has %get[job_number] as the default value and this worked.
You can get all the arguments by using arg();
try
echo "<pre>";
print_r(arg());
echo "</pre>";
In you case you can get it by echo arg(2);
While submitting Drupal Story form default redirect URL
http://localhost/drupal/?q=node/20
I need to change into
http://localhost/drupal_new/xyz.php?q=node/20
If you create a new module you can add an implementation of hook_form_alter to check all forms and alter the submit redirect on the appropriate form(s)
/*
Implementation of hook_form_alter this method hooks into the submission of story forms
and redirects appropriately
*/
function my_redirect_module_form_alter(&$form, &$form_state, $form_id) {
//some code to filter the forms
if(!$form['#node']->type=='story') {return;}
//otherwise this is a for we want to fangle
$form_state['redirect'][0]='http://localhost/drupal_new/xyz.php';
//this should leave all the ?q=node/xx untouched in $form_State['redirect'][1]
}
Code written from memory so YMMV...
Looks like you'll need to implement a custom module for redirection.
Take a look at this page: http://drupal.org/node/134000, specifically the "How to override default form redirection" section. It talks about using the hook_form_alter() function for redirecting.
the default login form in drupal doesn't have any javascript to check whether the fields(Username and password) are empty or not before submitting the form.
so, i want to add it onsubmit to the user login form..how can i do that?
The best way would be to just create a module that adds a .js file (via drupal_add_js()) that does something like this (note: the classes here are just a guess, didn't check the actual class names):
$('.login-form .form-submit').click(function() {
// your error checking here
});
please read how to theme login block: http://drupal.org/node/19855
And attach to submit button one of these javascript functions:
http://www.tizag.com/javascriptT/javascriptform.php