I'm trying to implement a payment system in my website with Symfony.
I have to add a form, which takes the creditcard number. But I don't want this number coming to my server. So I need to do a form in which no name attribute is specified. So the server cannot take this value and I read the value directly by javascript.
Does Anybody know how to do a form without name?
If I do:
$form = $this->createFormBuilder()
->add('creditNum', 'text')
->getForm();
This automatically creates a name attribute.
You could think about creating two separate forms, one form for your order form, and one form that just contains the credit card field(s). That way you can still handle the payment processing via Javascript, and when the user submits the main order form, the credit card field is not part of it, and won't be submitted to your server.
You'd probably have to use Javascript (or some really tricky CSS) to display the two forms nicely, so you might as well just create the credit card field with Javascript outside of the form itself, and position it so it looks like it's part of the form.
Related
What I want to do
I'm trying to build a form in Symfony 2.8 that requests the user's choice between many types of credentials and add an input box to the form it's similar to this one but I use a select option field instead of buttons.
What I did
I was able to create this form with HTML and JavaScript.The user can select more than one credential type only once except the OTV Option that can be selected without limits.
image here
What's my problem
I need a way to store user's data in a session and get them in my controller.
Is it possible to pass submitted data from HTML form to a Symfony controller and if not how can I build a similar form with Symfony's formBuilder ?
CollectionType is probably what you are looking for.
For your purposes, you can think of it as adding rows to the end of a two-column list. The Left Column has credential_type with Name, Email etc in a <select>; and the Right Column allows for your text values.
You'll have two FormTypes: one for the list, and another for the list item. In the list item FormType, you should be able to set a CallbackConstraint to validate e.g. that email values are valid upon form submission.
All user changes are saved at the same time, only when the form as valid.
I think you can do that. There is CollectionType in Symfony form. You can read about it here and how to implement it here
P.S. The main problem in this case is to generate specific names for dynamically created fields to provide a normal handling data in controller.
Is there a way to search on www.qantas.com.au or other sites that don't use GET method, from my own form?
I mean something like this : http://site.com/search.php?data=myData
I don't want to return result on my webpage, I just want to send data with a href
Depending on the website, many forms may contain CSRF tokens intended to prevent this behavior (imagine if a third party site could 'submit' a form for you to another site, perhaps to trans fer money or write embarassing posts)
That said, for sites that don't implement this feature, it should be possible just to copy their form (from <form> to </form>) including the action="/their/website/controller" and method="POST" (if you want it posted)
If you want to design your own form that submits the same data, just make sure the input fields have a name="blah" the same as the form data value that you want to submit
AJAX is also an option if you dont want to use a form. (see http://api.jquery.com/jQuery.post/)
I would like to offer the ability for users to open a form built using PHP/HTML and then on that form have a box which allows them to search for employees then want to send the form to without having to submit the form at this stage.
They will get a search box which allows them to enter the name or part name, the query then finds all employees which match the input string and they then choose the correct employee and that respondent is added to a list and they then search for the next employee and so on until they have added as few or many as they like.
Once they have selected the names, they then fill in some other standard fields on the form and then a separate entry is created in the "forms" table for each request sent.
Happy how to do the last part in terms of entering it into the database etc and how to do a "normal" search in PHP/MySQL but what should I do for the search within a form and add to the list pre submitting?
the technique you are looking for is AJAX which uses javascript to examine the form field as they type, talk to the php, get data, then show it back to the user without having to reload the page or sumbit the form. The exact thing you describe is called auto complete which there are many prebuilt tools for (or you can build your own custom one with some js knowledge). I am not going to try to post all the code here since it would be rather long and involved but if you search around these terms you will surely find what you need.
This can all be achieved with Javascript.
If you have a small number of employees, you could send an array of employees with the page. Use an 'onchange' event in the form field so that with each keypress you run a lookup matching the employees against the typed text.
It's likely that you don't have a small enough number of employees, and also I'm not sure best practice advocates sending your entire company address book inside a web page! In that case you will need to do the same using Javascript ajax calls within the page. On each keypress, fire a request back to the server asking for employees matching the text string.
You will need to dynamically display the matching employees in another form widget that allows for selection, or maybe as text with checkboxes etc.
There are plugins that manage all the client side part of this but you will still have to put together your own web service to do the employee lookup.
I have a form I need to auto fill it using Ajax and php. Suppose My unique field is mobile number. So when form appears firstly person has to fill mobile number. If mobile number exist in the database than all the rest field retrieve its value that is his name, email etc, making all the text fields disable.
my approach to this work is on blur effect I can send value through AJAX. but how call values in array. I have called only single value through echo; but have not called array back from java script page.
Secondly I need jquery to fill all form with respective values and disable particular fields in form.
Please give me some more idea to make this approach better and provide some hint to implement it efficiently.
have you tried Autocomplete from JQuery UI?
http://jqueryui.com/demos/autocomplete/
it is very easy to use, it uses ajax and can be easly used with php. Tell if you will have any problems.
A simple way to do this is to separate your page into 2 forms. The first form will contain only the mobile number field, while the second form will not be initially visible. This way, the user will be forced to fill in his mobile phone before doing anything else.
Submitting the first form will trigger an ajax call to your php file which will check whether the mobile phone exists in the database or not. If it exists, it will return a pre-filled form. If not, it will return an empty form. Therefore, there is no need to change the values of the fields with javascript. Now, all you have to do is to take the response of the php and put it into a div under the first form.
I'm using Zend Framework and I currently have an existing form using zend-form which functions as required.
I want to add another optional text field to it, but allow the user to choose to display the field and also display it multiple times. e.g. A user registration form with an 'alternative emails' area, allowing the user to add further text fields for each of their email addresses.
Unfortunately, I'm not sure how to go about this. I think sub-forms might be the way forward, but not too sure.
Ideally, once the form is submitted I'd want the data in an array so that I can process it for storing in a MySQL table afterwards.
See this excellent post by Jeremy Kendall on dynamically adding fields to a form:
Dynamically Adding Elements to Zend_Form
Upshot is to use jQuery on the client-side to add fields and maintain a registry of the new fields. Then on the server-side, call a new preValidate() method on the form object which checks the posted registry and adds the required fields into the $form object before standard processing - like isValid() and getValues() - is invoked.
Why don't you make an AJAX call to an addfieldAction() method in which you generate the HTML of another textfield and return that? You can still make use of Zend Form and the whole form can be processed the normal way.