Hi,
I'm a newby with Drupal, but I have written my own module in Drupal 7.
The module is written for private use and you can insert a URL with the logo of that webpage. It works fine :)
Now i need a 'edit' page zo I make in mymodule.module the following code in the function mymodule_menu():
$items['admin/config/media/mymodule/bewerken/%'] = array(
'title' => 'Bewerk mymodule',
'page callback' => 'drupal_get_form',
'page arguments' => array('mymodule_admin_edit_load', '5'),
'access arguments' => array('administer news feeds'),
'file' => 'mymodule.admin.inc',
);
In mymodule.admin.inc at the function 'mymodule_admin_edit_load' I have the following code:
function mymodule_admin_edit_load($adv_id) {
$vara = $adv_id;
$uid = 23;
$result = db_query('SELECT *
FROM {mymodule}
WHERE ssqd = :uid', array(':uid' => $uid));
foreach ($result as $feed) {
$url= $feed->url;
}
$form['#attributes'] = array('enctype' => "multipart/form-data");
$form['name'] = array('#type' => 'textfield',
'#title' => t('URL'),
'#value' => isset($url) ? $url: '',
'#maxlength' => 255,
'#description' => t('URL of the webpage'),
'#required' => FALSE,
);
$form['image'] = array('#type' => 'file',
'#title' => t('Afbeelding'),
'#maxlength' => 255,
'#required' => FALSE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
Now I see the URL '23' because I have set de :uid = $uid.
When I edit that to $vara or $adv_id I've got the following error:
Incorrect syntax near '='.: SELECT * FROM {mymodule} WHERE ssqd = ; Array ( ) in mymodule_admin_edit_load()
I have try a lot of things, but I don't know how I can fix me.
Does anybody a idea how I can fix this?
Thanks in advance!
Comments
Hi, did you try to remove the
Hi, did you try to remove the single quotes in the page arguments?
Actually you could also use
This way, Drupal will automatically call mymodule_admin_edit_load(23) and then use the result for the page callback.
Of course, then you will build the form in another function that is only the page callback, and in your mymodule_admin_edit_load() you will only load the data.
Best regards
AS
Thanks for your comment
Thanks for your comment AS.
When I try your answer It wouldn't work.
I use the following code:
At that moment, I don't see the edit form.
When I remove 'mymodule_admin_edit' at $items, I see the form, I can send it (it goes wrong but okay).
The only thing is that the variable after /bewerken/ not work.
BUT I found another thing what te problem is I guess.
In
I set
print_r($adv_id) ;
The output is
Array ( )
.Maybe is that 'the' problem??
Best regards,
PV
Change 'page arguments'
Change
to
and then split the function mymodule_admin_edit_load into two functions.
The first one will only load the object that has to be edited and returns it.
The second one will define the form.
Best regards
AS
Thanks for your answer, I
Thanks for your answer,
I have insert your source in mine (mymodule.admin.inc) and I don't have an error but I don't see a URL...
Well I see the input fields and a they are standing in a
<form>..</form>
tag. :DAlso 1 thing,
$adv_id is the id who where given in the % wildcard.
I have edit the $uid in de query to $adv_id but it wouldn't work....
I guess a small thing?
Do you know Watchdog? This is
Do you know Watchdog? This is a function you can call in your code to save information in a log manner.
The logs can be watched via
/admin/reports/dblog
.Load
So try the following in your
load
-function:and check what there is in the log. Of course you have to visit the page with the form :-).
Form
Then try the "same" thing on your
form
-function:What would there be in your $edit variable? Usually, there should be the output of the
load
-function.Best regards
AS
I have done a watchdog with
I have done a watchdog with your code and here is the log:
Can you help me?
Can you help me?
try this
The callback is proper. your url must be sitename/admin/config/media/mymodule/bewerken/integer if ssqd is an integer.
so when you go to link sitename/admin/config/media/mymodule/bewerken/20
then $uid is 20
At the function some changes and do clear cache whenever change in callback.
also instead of doing
$result = db_query('SELECT * FROM {mymodule} WHERE ssqd = :uid ', array(':uid' => $uid));
foreach ($result as $feed) {
$url= $feed->url;
}
you can use
$url = db_result(db_query('SELECT field_url FROM {mymodule} WHERE ssqd = :uid ', array(':uid' => $uid)))
I don´t see a form.
I don´t see a form.
'access arguments' =>
'access arguments' => array('administer news feeds'),
replace with
'access callback' => TRUE,
clear cache and try
This is my source
This is my source now:
mymodule.module:
mymodule.admin.inc:
When I visit '/admin/config/media/mymodule/bewerken/20' I only see the message who I have set in mymodule.module in the function mymodule_help($path, $arg)....
some changes for drupal 7
some changes for drupal 7, I am not sure but this code worked for me hope it will work to you also
mymodule.admin.inc:
clear cache and try
previously i was trying with drupal 6 this one is for drupal 7
It doesn't work....
It doesn't work....
I only see the message who I have set in mymodule.module in the function mymodule_help($path, $arg)....
this is mymodule.module
this is mymodule.module
take a backup and remove all other stuff
clear cache
put just this
go to http://localhost/sitename/admin/config/media/mymodule/bewerken/2
it gives form filled with url = email id of user having uid 2
* Notice: Undefined index:
* Notice: Undefined index: mymodule_admin_edit_load in drupal_retrieve_form() (line 736 of C:\Users\*******\includes\form.inc).
* Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'mymodule_admin_edit_load' not found or invalid function name in drupal_retrieve_form() (line 771 of C:\Users\*******\includes\form.inc).
some minor change
sorry working on two things at a time messed up the code
'page arguments' => array('mymodule_admin_edit_load', 5),
replace with
'page arguments' => array('multipart_admin_edit_load', 5),
also function name
function multipart_pager_display_nodes(&$form_state, $adv_id) {
with
function multipart_admin_edit_load(&$form_state, $node) {
clear cache and try. it should work now
<?php/*** @file* create a
I don't see a form. What I see is this location: admin/config/media
Anyone?
Anyone?
Nobody?!?!?!?!?!?!?!?!?!
Nobody?!?!?!?!?!?!?!?!?!