I'm building a simple shout box (like a chat box) for my personal website and I'm a little stuck. I want users to be able to delete a shout by clicking a small image next to it. Shouts are stored in an SQL table and the browser should refresh when the shout is deleted.
What I've done is create a form function with a 'hidden' element that stores the id of the shout (passed in as a parameter). The form is submitted by a little bit of javascript that is executed when the user clicks an image. The problem is that without a Submit button the page refreshes but the SQL query is never executed. I don't want the submit button because I just want a little image. Is there a way I can submit the form without a button? Perhaps a hidden button or something like that?
Just for referene I'll post the code I'm currently using.
The form looks like
function _ubershoutbox_delete_shout($id) {
$form['submit'] = array( //Want to get rid of this submit button but
'#type' => 'submit', //the form won't submit without it
);
$form['id'] = array(
'#type' => 'hidden',
'#value' => $id,
'#submit' => 'true'
);
return $form;
}This is the code that calls the delete_shout function and the link that submits the form.
$output .= drupal_get_form('_ubershoutbox_delete_shout', $shoutid);
$output .= "<a href=\"javascript:document.getElementById('-ubershoutbox-delete-shout').submit();\">";
$output .= "<img src=\"" . drupal_get_path('module', 'ubershoutbox') . '/delete.png' . "\" title=\"Delete Shout\" /></a>";
Comments
I don't know, but perhaps
I don't know, but perhaps this could help:
But then, here's a better solution: