I've got a syfmony form with type checkbox or radio.
If no checkbox is selected data is not passed to post action.
For example if I have a form with two ChoiceType and i dont select anything from the second one i expect to see in post action something like
form[q1][]:4
form[q2][]:null
form[submit]:
Instead i get in post action:
form[q1][]:4
form[submit]:
I also trying to add in my form:
'required' => false,
and
'empty_data' => null,
but still continue having the same issue.
Anyways if i use
$form->handleRequest($request)
i've got empty values as expected but just because there isn't any request with the formName.
This is not what i need because I need to use
$form->submit($request->get($form->getName()), false);
So is there a way to pass to post also empty value?
Thanks.
Your question is not a Symfony issue. Instead it is a HTML standard behavior. Only checkboxes and radioboxes that ARE checked will be posted. You can simply set all the fields to FALSE and overwrite them with the $_POST values that exists.duplicate. Another (bad in my opinion) solution is to add hidden fields and update them with javascript when the state of the checkbox changes
Related
Sonat admin bundle allow to edit only text fields and boolean, i would like to know if there a way to override sonata make it edit datetime/date fields.
Thank you in advance!
At this time , they only support scalar types :
Theses types accept an editable parameter to edit the value from within the list action. This is currently limited to scalar types (text, integer, url...).
https://sonata-project.org/bundles/admin/master/doc/reference/field_types.html
I guess to have to digg more into the documentation to get it working. ( See how scalar types are dealt with and try to write similar logic )
Not sure in which version they added this (can't find it in the change log), but in admin bundle 3.8.0 adding 'editable' => true' to a date field in a list makes it editable alright. The value becomes underlined with a dashed line and clicking it opens a jQuery date selector.
I'm working on a website that uses Domain Access and for a view I expose a filter that lists all domains. I want to list only some domains but not all. I know that it is posible to do with the filter configuration, but if I limit the options this way there is a problem with ajax which changes all the options text to "1", and in any case I want to know how to do it, with either hook form alter or with themes, but preferably using some hook from a module.
In general I'm trying to figure out how to remove some of the options for an exposed filter, I managed to do it using JQuery, but I'd like to do it with php, thanks!
It should be fairly straight forward using hook_form_FORM_ID_alter as you suggest. First inspect the <form> element of the filter form (using Firebug or similar) and get it's ID attribute. The form's ID in Drupal will be that string but with all '-' characters replaced with '_' (so 'form-exposed-filter-form' would become 'form_exposed_filter_form').
The thing to remember is that the submit handler for the form will probably be expecting the elements you're trying to remove to be there, so you'll probably get unexpected results if you just yank them out of there.
The way round it is to change the type of the elements to value instead (so they're available to the submit function in $form_state['values']), and choose a default value for each. Something like this:
// Replace 'FILTER_FORM_ID' with the form's ID
function mymodule_form_FILTER_FORM_ID_alter(&$form, &$form_state, $form_id) {
$form['some_existing_element'] = array(
'#type' => 'value',
'#value' => $default_value_for_filter
);
}
In a multi-step Drupal webform, is it possible to show a value entered in a previous-step page?
For example, the first step page captures a username field as "John", is it possible to show a greeting in next step page, showing Hello John, ... ?
p.s. for anonymous user.
I know this is old, but I needed the same thing so I hope this helps others in search.
I needed values from a previous Webform step for my custom Webform component. The _webform_redner_[component](...) hook doesn't provide the form or form_state, also the previous steps' data (more than previous step that was just submitted) isn't in the $_POST.
To solve this, I manually retrieve the form from Drupal's form caching system using the form_build_id which is in the $_POST variable.
/* ... */
$form_state = array();
// Get the form_state to pass on to our build function.
// Webforms doesn't provide it at this point so we'll need to manually get it using the form's build_id.
$form = form_get_cache($_POST['form_build_id'], $form_state);
/* ... */
You now have the entire form and form_state that also includes previous steps' values.
Have a look at multistep form example here: http://drupal.org/node/717750
The general idea is that in the submit function you save all posted values to $form_state['storage'], which you can later access on the next steps.
Edit:
Have a look at the example with both Prev and Next buttons I have just created: http://zgadzaj.com/basic-drupal-multipart-form-example-with-previous-and-next-buttons
I have written a wordpress plugin that uses jqgrid. When I submit one of the rows in the jqgrid to be saved, the names in my table columns (like "name") are conflicting with the wordpress query vars and causing a 404 to be returned.
Is there any way to get the jqgrid post to be wrapped in another object, so it's not posting the raw query var "name" to the server? Can it post something like
$_POST = array(
'jqgrid' = array('oper' => 'add', 'name' => 'whatever')
);
instead of
$_POST = array('oper' => 'add', 'name' => 'whatever');
?
jqGrid has prmNames option which can be used to rename any of the parameters used in URL or POST by jqGrid. For example default value for the "add" operation are defined by addoper:"add".
I don't understand what you mean under the "name" parameter. the column name are not used as the name of any parameter which are posted. If you have the problem because of the usage of toolbar searching I would recommend you to use stringResult:true option which makes information about the searching in the same format like in case of the usage of advanced searching. If you describe the problem more detailed I am sure that I could help you.
UPDATED: You can use serializeEditData (for form editing), serializeRowData (for inline editing) or serializeCellData (for cell editing) to convert in any way the data which will be send to the server during Edit/Add operation.
When a user login , the user will be redirect to a user profile page, which has a My account field set.
the field set has 2 fields, "Username: ", "Email address:". those 2 fields are generated by drupal.
those 2 field contained in a form which has a id ("user_profile_form") . I want to change the order of those 2 fields.
I have tried to intercept 'user_profile_form' , inside hook_form_alter.
code as follow:
$form['account']['name']['#weight'] = 1;
but that did not success, drupal did not even rendering the 'name' field, so no username: showed on browser.
What you did is absolutely correct, and probably did work. You can change the weight of the fields with the method described above.
The username field is not always rendered. The reason is that a persmission is required: change own username. If that perm is not set, you wont be allowed to alter you username and the field wont be shown.
Info on debugging.
Your info alone is not quite enough to debug. From what you describe, you are doing the right thing, but other modules could be making things a bit tricky for you. The devel module is quite good when it comes to debugging, ti defines two functions I use a lot when debugging:
dpm() pretty prints the variable to the message area using krumo.
dd() Prints / saves a variable to a log file. Useful when you can't view messages on the screen.
I would suggest that you look at the $form variable before and after you alter it.
Things that could make it go wrong:
Did you remember to pass the $form variable by reference using the & notation?
Is another module altering your form after you?
Are you checking for the correct form id, so you alter the correct form?
These are some pointers, before you bring more info, all I can do is guess to what your problem exactly can be. I did something like this a few days ago so I know what you describe shouldn't be a problem.