Form submit button to email based on a fields value - forms

I'm creating a PDF form with a submission button. I would like the form to email based on the value of another form in the field. I'm assuming I need to do an "IF...ELSE" statement, but keep getting a syntax error that I cannot figure out. I am completely java illiterate.

This can be done using multiple solutions, but you do need to program Javascript inside of the PDF. You can use if-else on-click of the email-button. Here you can check values entered inside of the PDF form:
if (this.getValue("somefield") == "left") { emailvalue = "toA#domain.com" } else { emailvalue = "toB#domain.com" }
But you could also set the value onBlur or onFocus of a certain field. Like with radio-buttons the onBlur is useful because you know the user clicked or focused on this field and so set the variable emailvalue to a certain value.

Related

Angular 2 - Dynamic Reactive form with Radio Inputs build with FormBuilder, FormGroup, FormArray

Case:
I have an array of answers which I want to show in the view as radio inputs. When one of the answers is already answered it must be [checked] and if it's [checked] a textarea shows, so far so good.
Next I want to check another radio input and I want the current selected to be deselected and its textarea hidden, then the new selected radio input should be [checked] and it's textarea should show.
I use the FormBuilder and FormArray and have following issues.
I can't use index without intrapolation, I see many examples where the index is used without.
If I select another radio input, first my data disappears and it's not checked and on the second click it get's checked but now both are checked.
- I don't have access to the checked event, I can show it in the view with {{tempVar.checked}} as you can see above, if I use a template variable #tempVar, but I don't have access to it in the textarea below *ngIf="tempVar.checked". If I do use it in the ngIf I get the following error
Expression has changed after it was checked. Previous value: 'false'. Current value: 'true'.
Questions:
Is this the right approach?
An example of a Reactive Dynamic form with FormBuilder and FormArray with Radio inputs
Here is my code
https://gist.github.com/webwizart/121c85a0f316f47977cc0c99455af7bf
I would think using the tags should be reserved for unique identifiers? I wouldn't be surprised if dom renderer will update all elements with the same id.
Not sure if this will help, but you could use an answer view model instead (containing the same data) but that also has a 'checked' property
This way you can be sure that it will behave as you would expect.
e.g.: (in your component.ts)
let answers = this.question.Question.PossibleAnswers
.map(a =>
{ return Object.assign({}, a, { checked: false });
}
);
then in html you use: 'answer.checked' instead of 'radio.checked'
ps: also you could use ng-container instead of span, so you don't have an extra DOM imprint in your html

How to know if jQuery validator already exists for a form?

Imagine I have an unordered list with 2 cols, col 1 is the name of a file and col 2 is a pencil icon which has tooltip enabled. When the user clicks on this pencil icon, it opens a tooltip which contains a form. In this form the user will enter a new file and the value will be validated.
When the tooltip is shown, I attach jQuery validator to the form inside the tooltip. The problem is that each time the tooltip is shown, a new validator is attached. I would like to only attach one validator to a form. How can I successfully check if validator already exists for a form?
var validator = forms.validate();
console.log(validator);
// always evaluate to true
if (validator) {
}
This doesn't seem to work. Does anyone have any ideas?
You can use the jQuery data to check if the validator exists on a form element like this:
var form = $('#myform');
if(form.data('validator')){
// validator exists
}
I realized that I could just check to see if a form has the class "novalidate" to determine if the form has a validator attached or not.
var forms = jQuery("form.edit");
if (forms.attr("novalidate")) {
return;
}

When using ['#access'] in hook_form_alter() for a field than I am loosing '$form field default value' and $form_state input

When using an EntityReference field and in hook_form_alter() hiding that field with ['access'] than after submitting form $form_state input is empty for that field.
I have field field_to_a which is an entityrefence field on content type B that references content type A.
I am using hook_form_alter() in which i am using a line like $form['field_to_a']['#access'] = FALSE; and also setting this field to a certain value
When I am pressing submit button (my Save button) on node add:
When I am using $form['field_to_a']['#access'] = FALSE;: I am loosing $form_state['input']['field_to_a'] (does not exist) and $form['field_to_a']['und'][0]['target_id']['#default_value'] (empty) and I have PHP errors.
When I am using NOT $form['field_to_a']['#access'] = FALSE;: I have $form_state['input']['field_to_a'] properly and node is saved without any errors.
When I am using any other field I can use ['#access'] = FALSE and not loosing input in $form_state for that field.
Is there any solution or workaround for this thing? Is it a bug or normal behavior?
Thanks
First check log what you have received.
try this :
function hook_submit($form, &$form_state) {
watchdog("Your Form data ", '<pre>'.print_r($form_state, true).'</pre>');
}
Then check your log report. you will receive your value in $form_state['values']
It may helps you

Submit Form with nameless input in HtmlUnit

Good morning!
I need to post a form, I've already changed all the values inside that form (drop-drown list, text fields , check-boxes, etc), in this way:
final HtmlPage page4 = webClient.getPage("somepagemakinmemad");
HtmlForm formx= page4.getFormByName("lista_grupos");
changing values like:
HtmlSelect duracion = (HtmlSelect) page4.getElementByName("p_duracion_"+datum.getCrn()+"_1");
HtmlOption option1 = duracion.getOptionByValue("0029_029");
duracion.setSelectedAttribute(option1, true);
That is, I am changing the values through obtaining the html element from the page, not through the form (is that okay anyway?).
And then I try to submit the form, through:
<input id="p_guardar" class="boton" type="button" onclick="validaAPG()" value="Guardar">
Which is the "button-like" input where someone clicks when is over with the form.
I have to say, when I print the html code of the form, with "asXml()", I see the form the with selected values I've intended to select.
Question: How can I click on that button and send the form? That input runs a script, when clicked
Thanks everyone, let me know if you need any other kind of info.
You can use below code to click on the button to submit the form.
HtmlButtonInput button = (HtmlButtonInput)page.getElementById("p_guardar");
page = button.click();
You dnt need to care what script runs when clicked.If you dont need to run the script remove the attribute.

Problem about the customised validation rule using regular expression in JQuery

I have a form having some text boxes, radio buttons, and select boxes. I write custom validation methods which i added using validator.addmethod.
If user submitted this form keeping some or all fields empty then form should get submitted but if user enters data in text boxes then data should be alphabetic and should not contain special character and numbers.
I write validation code for some text boxes for which the custom validation code as I mentioned above is as follows.
$.validator.addMethod('specialchar', function (value) {
return /^[^a-zA-Z]$/.test(value);
}, 'First Name should not contain special characters.');
**Now actually when user submits form with empty fields then error messages of above custom validation method is displayed for those textboxes to which above method is assigned **
I think there is also problem in my regular expression which i can not able to spot.
If my regular expression is right then is there any other method to add regular expression in JQuery i.e. lookahed regular expression.
Please help me on these two problems guys
Thank You
Maybe something more like this:
/^[^a-zA-Z]{0,}$/