Drupal 6 story form submit URL change - drupal

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.

Related

Drupal 8 : send a PDF file after form submit

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.

WP Contact Form 7 - Display [your-name] field on a separate page

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>

Submit form to both code behind and third party url?

I have a legacy app that I need to change to accommodate a new payment processor.
The app is Asp.Net.
Without reconstructing the app (not in the budget) I need to take the final form and save information from it in the code behind, like it currently does, then I need to submit that same form to a third party url. Ideally as one button push to the end user.
I'm drawing a complete blank on a way to do this. Any suggestions?
Forgot to mention that JQuery and javascript are both valid tools for a solution.
You could create a javascript function that's bound to the form submit button's click event, or the form's submit event. The function will need to prevent the default form submission from firing. Use jQuery to serialize the form data, and create a synchronous AJAX request to submit the data to the third party. After the ajax submission has completed, you can trigger the form submission to the code-behind. If the ajax fails to submit properly, you can optionally abort the form submission to the code-behind.
You may need to account for XSS security, so look into cross-origin resource sharing and the Access-Control-Allow-Origin header.
Another option would be to have the code-behind behave as an http client and submit the form data to the third party.
so currently it's saving the results via code? Well, you could hack it by putting some javascript on the page that read's the forms values and posts them (eg with jquery), before doing you actual asp post.
edit (something like this might help (in some cases):
//change the action of the form (you could just change in code or this
$('#myform').attr('action','http://newpaymentproc.com/me/');
//override the default submit
$('#myformsubmitbutton').click(function(){
//extract the form data somehow (depends on form)
var formObj;
$.each($('#myform').find('input').serializeArray(), function(i, field) {
formObj[field.name] = field.value;
});
//post to old place
$.post('/old_current.asp', formObj).then(
//after posting to old place and getting response...
//submit form to new payment processor
$('#myform').submit()
);
// Cancel the actual form submit click to give time for post
return false;
});
Another way would be to have the legacy code (after submission) spit out a form with the data in it and some javascript to trigger submit on page load.
After the original process has completed, just take the submitted form data and push it to whichever URL you're working with. It requires minimal modification on the original app.
I have no code to go on, so I have no code to give. Hope that helps!

ASP.NET should I use a "checkUser" function in pre_init or page_load

Just wondering I have a function which checks the language of a page (multi-lingual site), and if not default language we need to redirect to default language for one section i.e.
if (Sitecore.Context.Language.Name != LanguageManager.DefaultLanguage.ToString())
{
Sitecore.Context.SetLanguage(LanguageManager.DefaultLanguage, true);
Response.Redirect(SourceHomeUrl(), true);
}
I am just wondering is it best to put it in pre_init i.e. do this check before anything loads and just redirect then ?
If you can do it in the pre init event, it would be better to do it there, so that you can redirect the user before any additional/unnecessary loading and processing takes place vs. doing it in page_load.
It seems reasonable but I would also look at other alternatives to handling a multilingual application like storing the language specific text in a database or resource files
http://msdn.microsoft.com/en-us/goglobal/bb688115

adding onsubmit to drupal login forms

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

Resources