Using MechanicalSoup, does one have to set values for hidden fields in a form as well? Or can we just ignore them?
Here is their code in the HTML form:
<input type="hidden" name="details[sid]" />
<input type="hidden" name="details[page_num]" value="1" />
<input type="hidden" name="details[page_count]" value="1" />
<input type="hidden" name="details[finished]" value="0" />
<input type="hidden" name="form_build_id" value="form-OoBDi0_aQvgHZN-Iyc" />
<input type="hidden" name="form_id" value="webform_client_form_337" />
<input type="hidden" name="honeypot_time" value="1519679330|-x8kCHBe6qh7E" />
Hidden fields are typically used internally by the website you're browsing: they are generated with a value, and this value is sent together with non-hidden fields when you submit the form.
MechanicalSoup does what you expect here: it sends the values of hidden fields when you submit the form, so essentially you don't have to care about them: their value will be set by the website you're visiting, and then taken into account by MechanicalSoup just like a normal browser.
You shouldn't need to modify their value, because when using the website with a real browser, the user has no simple way to set a value (that's the point of hiding the fields ...).
You can add your own hidden input name:value pairs using the new_control() method. I've had to do this when the form used javascript to set a hidden element before form submission.
browser.new_control('hidden','name','value')
https://mechanicalsoup.readthedocs.io/en/stable/mechanicalsoup.html#mechanicalsoup.Form.new_control
Related
I have a Wicket page with this structure:
<form wicket:id="generalForm" method="post" class="form_recherche">
<input value="" type="text" wicket:id="myField_1" />
<form wicket:id="innerForm" method="post">
<input value="" type="text" wicket:id="myField_2"/>
<input type="submit" class="button-classic" wicket:id="accept_2"/>
</form>
<input type="submit" class="button-classic" wicket:id="accept_1" />
</form>
1 external form with 1 inner form. One field each. The fact is that when the "accept_2" button is clicked, the field "myField_1" is not submitted to the server (only the "myField_2" is submitted). And in fact, I would need the "field_1" field to do some validation.
What am I missing and why isn't the "myField_1" being filled on the server why "accept_2" is clicked?
You need to override Form#wantSubmitOnNestedFormSubmit() on the outer Form to return true. This way you will tell Wicket that you want the (outer) form to be submitted as well when one of its nested forms is submitted.
You used SO tags wicket-1.5 and wicket-1.6. I am not sure whether this method is available for your version of Wicket.
I have 2 forms on one page that I need to pass to the same page to assemble a pdf. How can I do that? I have tried using a action="post" for one and action="get" for the other, but I can't get that to work. I have tried assigning one form to session variables, but I can't get that either. Any suggestions??
<form name="formOne" id="formOne" method="post" action="#buildURL('goTothisPage.page')#">
<input name="name" id="name" autofocus="true" >
<input name="address" id="address" >
I would try just creating one big form instead of 2 smaller forms if the action is going to be the same and go to the same .cfm page. (Just expand the scope of your tags)
You can also create 2 "Submit" buttons (1 for each form) to make it appear as 2 separate forms, even though the buttons will submit the same form.
If it is required to have two separate forms in your html, it is also possible to forge the form values from one form into the other at the moment of the submit event.
HTML:
<form name="formOne" id="formOne" method="post">
<input name="name" id="name" type="text" >
<input name="address" id="addressHidden" type="hidden">
</form>
<form name="formTwo" id="formTwo" method="post">
<input name="address" id="address" type="text">
<input name="name" id="nameHidden" type="hidden" >
</form>
Javascript:
$(document).ready(function(){
$('#formOne').submit(function(event){
$('#addressHidden').val($('#address').val());
return true;
});
// same for #formTwo
$('#formTwo').submit(function(event){
$('#nameHidden').val($('#name').val());
return true;
});
});
I am processing a simple form to PayPal's Express Checkout using the basic standard free account and the standard form "_xclick" option.
When passing through the item name or description, I understand you are limited to 144 characters but I want to have the information inside the title or the description on different lines to separate the information when on PayPals checkout area so the user can clearly see what they are paying for.
I have tried to use "\r" and "\n" to seperate the lines, as seen below in the "item_name" input using "This is line 1\r\nThis is line 2\r\nThis is line 3", but it just ignores the "\r" and the "\n" when passed through to the PayPal payment page and when sent in the receipt email.
Current Example Code:
<form name="TheForm" method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="item_name" value="This is line 1\r\nThis is line 2\r\nThis is line 3">
<input type="hidden" name="price" id="price" value="" />
<input type="hidden" name="business" value="test#test.com">
<input type="hidden" name="amount" value="">
<input type="hidden" name="no_shipping" value="1">
<input type="submit" name="Submit" id="Submit" value="Process Payment" />
</form>
I have also tried using
,
, <br> and <br /> and none of these work either and are passed through as text.
How can I achieve separating the item information on seperate lines using the form option INPUT value, as shown above, for the item description or title please as the way I have tried does not work and I cannot find any solution?
Thanks.
Currently there is not a way to do this. The standard buy now buttons do not support this. The closest you can come to putting things on a different line would be using a cart upload method. Instead of passing over 1 item, with 3 values in the item name that you want displayed on 3 different lines you would pass over 3 individual items which would cause them to be on 3 different lines.
Suppose we're building an address book application (contrived example) with AngularJS.
We have a form for contacts that has inputs for email and phone number, and we want to require one or the other, but not both: We only want the email input to be required if the phone input is empty or invalid, and vice versa.
Angular has a required directive, but it's not clear from the documentation how to use it in this case. So how can we conditionally require a form field? Write a custom directive?
There's no need to write a custom directive. Angular's documentation is good but not complete. In fact, there is a directive called ngRequired, that takes an Angular expression.
<input type='email'
name='email'
ng-model='contact.email'
placeholder='your#email.com'
ng-required='!contact.phone' />
<input type='text'
ng-model='contact.phone'
placeholder='(xxx) xxx-xxxx'
ng-required='!contact.email' />
Here's a more complete example: http://jsfiddle.net/uptnx/1/
if you want put a input required if other is written:
<input type='text'
name='name'
ng-model='person.name'/>
<input type='text'
ng-model='person.lastname'
ng-required='person.name' />
Regards.
For Angular2
<input type='email'
[(ngModel)]='contact.email'
[required]='!contact.phone' >
Simple you can use angular validation like :
<input type='text'
name='name'
ng-model='person.name'
ng-required='!person.lastname'/>
<input type='text'
name='lastname'
ng-model='person.lastname'
ng-required='!person.name' />
You can now fill the value in only one text field. Either you can fill name or lastname. In this way you can use conditional required fill in AngularJs.
In AngularJS (version 1.x), there is a build-in directive ngRequired
<input type='email'
name='email'
ng-model='user.email'
placeholder='your#email.com'
ng-required='!user.phone' />
<input type='text'
ng-model='user.phone'
placeholder='(xxx) xxx-xxxx'
ng-required='!user.email' />
In Angular2 or above
<input type='email'
name='email'
[(ngModel)]='user.email'
placeholder='your#email.com'
[required]='!user.phone' />
<input type='text'
[(ngModel)]='user.phone'
placeholder='(xxx) xxx-xxxx'
[required]='!user.email' />
For Angular 2
<input [(ngModel)]='email' [required]='!phone' />
<input [(ngModel)]='phone' [required]='!email' />
I have a 'customer' form which has a section called 'contacts'. To start with this contacts section will contain the following elements..
<input type="text" name="contacts[0][fname]" />
<input type="text" name="contacts[0][sname]" />
But the user may want to add another contact which will duplicate the elements with javascript to produce the following:
<input type="text" name="contacts[0][fname]" />
<input type="text" name="contacts[0][sname]" />
<br />
<input type="text" name="contacts[1][fname]" />
<input type="text" name="contacts[1][sname]" />
I know how to produce the first set of elements, however if the form gets submitted and there are errors, how can i ensure that the correct number of 'contacts' elements get rendered?
Ive never had to do this with Zend_Form but i have done it with Symfony 1.4's sfForm which has a similar API and theory of operation. Based on that the basic process is:
In the parent forms constructor intialize some default number of subforms. Youll want to separate out the logic for actually creating and embedding n subforms into a separate method(s). Ill refer to this as the method emebedContacts($count = 1)
Override the isValid and setDefaults methods on the parent form so that they detect the number of subforms in the $data arguments passed to them and then call embedContacts before calling parent::isValid() or parent::setDefaults().
Hope that helps.