Jqgrid conflicting with wordpress query vars - wordpress

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.

Related

Testing for WordPress custom post type variables

Within the array for a custom post type named rg_story that I am defining, I have the following statement:
'chronological' => true,
Later, I have this:
if ( 'rg_story' == get_post_type()) {
As far as I know, everything is working OK. I'll know for sure once I create my templates. This is my first time with this stuff.
The problem is that I would like to test for the value of 'chronological', rather than the specific post type. I'm just not sure which function would do that.

Symfony form don't pass empty value

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

Remove or Filter Options on Exposed Filter in Drupal 7

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
);
}

Accessing values in Drupal's $form_values from a custom Drupal Form

EDIT: Seems like my "array-crawling" skills were not enough, thanks for the suggestions.
Moreover, I found out that I was checking the $discounttype condition with a plain "=" instead of a double "==". I guess banging your head on the same block of code for 3 hours makes you dumb and miss the most obvious errors.
First thing first, I'm on Drupal 6.
I have created a form with the following markup:
$form["cart_".$index] = array(
'#type' => 'image_button',
'#src'=> 'files/imghome/sidebar-add-demo.gif',
'#attributes' => array('rel' => '#item', 'class' => 'buybutton', 'title' => $discounttype),
'#prefix'=>'<p class="renewprop">'.$newren.' for '.$node_abb->field_tipo_abb_value.':</p><p class="renewblock"><span class="pricetag">'.$node_abb->field_prezzo_value.''.$discounttype.'</span>',
'#suffix' =>'</p>' ,
'#submit' =>array('usercp_form_submit'),
);
The form renders correctly, as you can see from this picture: http://cl.ly/3D2C2h1t1m2B351L1T31
(the N and R values beside the € symbol are actually the value of the $discounttype variable, just for checking it)
Each white box is basically an istance of the beforementioned form.
I need to pass the value of the $discounttype variable on each submit, so I decided to set it as the title of the submit button.
My problem is that in the submit function itself I cannot access the value of the 'title' attribute contained in the #attributes array. Mainly because probably I don't know the right syntax.
So far I've tried
$foo = $form_values['attributes']['title'];
$foo = $form_values['#attributes']['title'];
$foo = $form_values['attributes']['#title'];
And every other possible combination, but probably I'm just doing it wrong.
It's actually an hour that I'm crawling the web searching for an asnwer but I came up with anything.
first, you should mention form element ID.
so, you can access submit button by $form_state["cart_".$index]['#attributes']['title'];
but actually, why don't you use hidden field ('#type' => 'hidden') ?
I believe you have to use $form_state instead of $form_values. Give this a try:
$foo = $form_state['clicked_button']['#attributes']['title'];
I recommend using the Devel module while developing for Drupal. It is an extremely helpful tool during development, allowing you to see all the queries run when a page loads, stop a redirect to debug, and much more.

Best way to layer Custom Posts regarding structure and data

I would like to know the best method for layering posts in wordpress 3.0 when you need to swap back and forth between structure and data. For example, custom post type 1 has 6 custom fields, each field contains a value for the tab shortcode; i.e. [tab:data] [tab:credits] [tab:where to buy] etc - this type is standard every time the page is called and always the same post; then it needs to switch to another custom post type and select the data post it's going to use based on what tag page is being called. Then it needs to pump a custom field from data post into the same display space as the base structure post, and then hop back and forth between structure and data, and THEN run a loop. Thanks in advance.
I would just query for the two special posts before you do the loop, with get_posts (which will not mess up the regular query). Then you can display them however you want, with their information mixed together, and then do the loop.
In this example, $fixed_post is a fixed post with slug "fixed_post_slug" of the custom post type "fixed_posts". $tag_post is a post where the name equals the current tag (if we are showing a tag page), and of custom post type "tag_posts".
$fixed_post = get_posts(array('name' => 'fixed_post_slug', 'type' => 'fixed_posts'));
if ($fixed_post) {
$fixed_post = $fixed_post[0]
}
$tag_post = get_posts(array('name' => get_query_var('tag'), 'type' => 'tag_posts'));
if ($tag_post) {
$tag_post = $tag_post[0];
}

Resources