Hi,
I'm a beginner et I'm trying to make a small module but it doesn't work, I'll be graceful if somebody helps me to find why.
It's a form in a block that send url Ajax to an extern website, then shows the response, files module and js:

emploi.module:

/**
* Implementation of hook_block_info()
*/
function emploi_block_info() {

$blocks['emploi'] = array(
'info' => t('Recherche d"emploi'),
'cache' => DRUPAL_CACHE_GLOBAL,
);
return $blocks;
}

/**
* Implementation of hook_block_view()
*/
function emploi_block_view($delta = '') {

$block = array();
$block['subject'] = t('Recherche d"emploi');
$block['content'] = drupal_get_form('emploiShowForm');
return $block;
}

function emploiShowForm(){
$form=array();
$form['Titre_Offre']=array(
'#type'=>'textfield',
'#title'=>'Titre',
'#size'=>25
);
$form['Ville']=array(
'#type'=>'textfield',
'#title'=>'Ville',
'#size'=>25
);

$form['#suffix']='
';

drupal_add_js(drupal_get_path('module', 'emploi'). "/emploi.js");

return $form;
}

emploi.js:
jQuery(document).ready(function(){
jQuery('#submetAjaxButton').click(function(){

jQuery.ajax({
url: 'http://www.emploitic.com/offres-emploi/
Icône de liens externes
',
data:{
Titre_Offre:jQuery("#edit-titre-offre").val(),
Ville:jQuery("#edit-ville").val(),
option:'com_candidat',
controller:'search',
initSearch:'1',
task:'doSearch'
},
success:function(data){
jQuery("#info").append("hi");
}
});
});
});

Comments

mustafa47’s picture

in the module file in function emploiShowForm() this is #suffix.
$form['#suffix']="

";

Jaypan’s picture

Need more info.

Also, please wrap your jquery code in <code/> tags.

mustafa47’s picture

Thank you for you help,
I'm using Drupal 7.
I'm trying to get informations from an external website which is "http://www.emploitic.com".
I name the module emploi, I create the form that contains 2 input text "Titre-emploi" and "Ville".
I put it in a block emploi, so the module works and i get the Block, so I can enter my search informations then press the button "rechercher", I can see in the Console that the right url is sent but nothing back, it appears in red but i get OK.
again the code in emploi.module:

/**
  * Implementation of hook_block_info()
  */
function emploi_block_info() {

  $blocks['emploi'] = array(
    'info' => t('Recherche d"emploi'),
    'cache' => DRUPAL_CACHE_GLOBAL,
  );
  return $blocks;
}

/**
  * Implementation of hook_block_view()
  */
function emploi_block_view($delta = '') {

  $block = array();
  $block['subject'] = t('Recherche d"emploi');
  $block['content'] =  drupal_get_form('emploiShowForm');
  return $block;
}

function emploiShowForm(){
    $form=array();
    $form['Titre_Offre']=array(
        '#type'=>'textfield',
        '#title'=>'Titre',
        '#size'=>25
    );
    $form['Ville']=array(
        '#type'=>'textfield',
        '#title'=>'Ville',
        '#size'=>25
    );
    
    $form['#suffix']='<input type="button" id="submetAjaxButton" value="Rechercher"/><div id="Result"></div>';
    
    drupal_add_js(drupal_get_path('module', 'emploi'). "/emploi.js");

    return $form;
}

and the emploi.js:

jQuery(document).ready(function(){
   jQuery('#submetAjaxButton').click(function(){

            jQuery.ajax({
           url: 'http://www.emploitic.com/offres-emploi/',
           data:{
               Titre_Offre:jQuery("#edit-titre-offre").val(),
               Ville:jQuery("#edit-ville").val(),
               option:'com_candidat',
               controller:'search',
               initSearch:'1',
               task:'doSearch'
           },
           success:function(data){
               jQuery("#Result").append(data);
           }
           });
    });
});
Jaypan’s picture

I can see in the Console that the right url is sent but nothing back, it appears in red but i get OK.

That means that you've got everything set up correctly in Drupal and the JavaScript. That means the problem is probably here:

url: 'http://www.emploitic.com/offres-emploi/',
           data:{
               Titre_Offre:jQuery("#edit-titre-offre").val(),
               Ville:jQuery("#edit-ville").val(),
               option:'com_candidat',
               controller:'search',
               initSearch:'1',
               task:'doSearch'
           }

Either the URL is wrong, you you are sending the wrong data. You'll need to check with the other server to find out.

mustafa47’s picture

thank you for the answer I'll check that.