I have two forms in a single page
Create Record Form
Update Record Form
Create Record form works perfectly but when I use the Update Record form the values are populated in the Create Form when an error occurs. What can be done to prevent this or any better structure to be followed for creating such functionality.
#Dharma Sai Teja - Please make sure that the names provided to the fields should be unique in all form. The values will be populated wrong if the
Related
I have created custom form in Moodle and inserted the data into moodle database. Also i used most of the field in form as autocomplete like below eg
$mform->addElement('autocomplete', 'SBName', get_string('searcharea', 'search'), $sbnames, $options);
Then, I need to update this form . I got record from db as a array, Then i need to add db values in my update form to proceed further.
Here I could not populate the values in edit form for the field of autocomplete $mform->addElement('autocomplete.
Kindly help on this to apply the values in edit form.
Please let me know Is there any way to do this in moodle
A few things to note - in Moodle variables and database field names should all be lowercase, so you will find things easier if you call the field 'sbname' instead of 'SBName'.
You mention you have "got the record from the db as an array" - none of the Moodle database access functions return a record as an array, they all return records as objects (although they will return multiple records as an array of objects) - please double-check the code you are using to retrieve the record, if it is reaching you as an array.
Finally, to initialise values when editing a form, the usual method is to write (outside the form itself):
$form = new name_of_form();
$form->setData($recordfromdatabase);
Where $recordfromdatabase is the record object returned by one of the $DB->get_record_* functions.
After that, you can use the $form->getData() function to retrieve the submitted values and $form->display() to display the form itself.
There are lots of examples in the core Moodle code that you can follow for this.
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.
I liked to know how I can show a value from my database into an input field. I'm working with CakePHP.
Right now, I have some empty fields, but I want them filled with the database values when I display my page the first time and of course when there are values in the database relative to these fields. I'm able to retrieve all my database data, but unable to show them into the fields.
Is there an easy way with CakePHP to do it or I need to set each field individually in my controller and retrieve it in my view.
Thank you
You are able to fill forms from the controller, by using $this->form->data.
Example:
$this->request->data = $this->YourModel->findById($id);
Edit:
You have to create your form with the form helpers to attach the form to your model, otherwise it won't work.
echo $this->Form->create('YourModel');
I have a HTML form with several fileds in it. Using PHP and mySQL i was able to store the form values in one or more tables and retrieve back in the same form for editing and update it in the database.Now i want to record the values of the form fields that are changed in the form edit for reference. I want to record the following in a seperate table.
1. old value of modified field
2. New value of modified field
3. field name of the modified field
Please help me here.how to perform the following functioanlity using PHP and Mysql
Any help would be greatly appreciated !!
I have a form in my application with a multi select. I'm using CI's form helper to build my forms, so the build of the element looks like this:
return form_multiselect('authors[response][]', $faculty->get_all_for_multiselect(),
$pre_selected, $additional_attributes);
This is all well and good if the items are in the database ($pre_selected gets existing responses). However, I'm also running the form through CI's form validation, and when that happens, if validation fails, then the multi select loses the values that had been selected.
I'm sure this is something simple that I'm just over looking, so hopefully someone can help me out here.
Adding more information
The field is marked as required so it is going through the validator (although it will always pass as I'm automatically selecting the current user).
(I'm assuming $pre_selected is an array of values?)
You can reset selected values after failed form submit using the $_POST array.
Since you're already using $pre_selected, you should be able to use the following:
return form_multiselect('authors[response][]', $faculty->get_all_for_multiselect(),
array_unique(array_merge($pre_selected, $_POST['response'])), $additional_attributes);