By drupalinthailand on
DRUPAL 6 Short php code NOT working on php5.6 - CAN YOU TELL ME WHY ?
Hello, I am using this module to change my Ubercart store button, but since my host changed php to 5.6 the button cannot be seen anymore. I tested before and it only works with php5.3, can you tell me why ? Thank you so much.
The module comes from here:
http://www.primalmedia.com/blog/how-to-replace-the-add-to-cart-button-wi...
//$Id$
/**
* @file
* Replaces the default HTML 'Add to Cart' button with a more attractive graphic.
*
* See http://www.primalmedia.com/blog/replace-add-cart-button-image-ubercart
*/
/**
* Implementation of hook_form_alter().
*/
function uc_gfxbtn_form_alter($form_id, &$form) {
if(( $form_id['#validate'][0] == 'uc_product_add_to_cart_form_validate' && $form_id['#submit'][0] == 'uc_product_add_to_cart_form_submit') OR ( $form_id['#validate'][0] == 'uc_catalog_buy_it_now_form_validate' && $form_id['#submit'][0] == 'uc_catalog_buy_it_now_form_submit') OR ( $form_id['#validate'][0] == 'uc_product_buy_it_now_form_validate' && $form_id['#submit'][0] == 'uc_product_buy_it_now_form_submit')){
$form_id['submit']['#type'] = 'hidden';
// strip '?submit_x=15&submit_y=27' from $_POST
if (isset($_POST['submit_x'])) {
$form_id['submit'] = array(
'#type' => 'submit',
'#value' => 'submit',
);
}
$form_id['submit_image'] = array(
'#value' => '<input name="submit" type="image" width="380" height="145" class="add_to_cart" title="'. t('Add to Shopping Cart') .'" src="/'. drupal_get_path('module', 'uc_gfxbtn') .
'/button.png">',
);
}
}
Comments
1) Please do not start
1) Please do not start multiple threads on the same topic: https://www.drupal.org/forum-posting#crosspost
2) Please do not use caps in your topic titles: https://www.drupal.org/forum-posting#punctuation
3) You can wrap your code in <?php ?> tags to make it more readable (you forgot the closing tag).
Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.
I am sorry, I try again
I am sorry, I try again.
What error messages are you getting?
Can you please post the related error messages from your logs.
If it is not working because of a PHP version incompatibility then you will have errors in your web server logs.
It will be much easier for someone to help with that information.
Errors
Thank you, most of the errors that I can see in logs are:
Declaration of views_handler_argument_many_to_one::init() should be compatible with views_handler_argument::init(&$view, $options) in xxx/sites/all/modules/views/handlers/views_handler_argument_many_to_one.inc on line 0.
But I cannot find an error related to the button that doesn't show up anymore.
Tell me if I can help more ?
Hard to be sure
Without access to your site for proper debugging or more error messages to go on it's hard to say exactly what the issue is but I will say that your code looks a bit odd.
The parameters for your form alter are not correct and the form array isn't passing in by reference so your code is not going to update the form.
As you can see on the documentation page for hook_form_alter() your function declaration should look like this:
function uc_gfxbtn_form_alter(&$form, &$form_state, $form_id) {Note that the $form parameter is passed by reference (indicated by the ampersand) but your function doesn't do that so you are updating a local copy of the form array, not the actual form array.
After changing to the above declaration your references to $form_id throughout the function should change to $form.
You can also probably better target the forms you want to modify by using the $form_id variable instead of by checking which validate and submit handlers are on the buttons.
I would fix those issues and it may then work.
I also recommend making sure that all your modules are updated to their latest versions because if you aren't on the latest versions you may be missing out on fixes for newer PHP versions.
I cannot code :-)
Hello and thank you, but I do not know how to code.
I contacted the company who made the module but no reply.
Do you know where I could ask some help ?
Thanks again.
Contact a Drupal development company or freelancer
Updating a Drupal 6 site that has custom code or uses a lot of contributed modules is often not a task for someone not familiar with coding.
I would recommend contacting a Drupal development company or freelancer and pay them to do it for you.
_
Please don't spam the forums with duplicate threads, I've deleted the dupes. Thanks.
Thank you so much
Thank you so much, I will never do it again., but asking questions in different forums is not spamming.
And people who do not read this forum won't see the message.
_
Seriously? Did you even bother to read the link to the forum guidelines?
I am so sorry.
I am so sorry.
_
Yes, and everyone here exists to help you, lol. Breathtaking.
Saying sorry and not living
@drupalinthailand: Saying sorry and not living up to that is called an empty gesture and people get rather annoyed by that behavior, so no surprise you find this place unfriendly.