I have a form that is generated through an AJAX request. When the form is submitted the correct function is hooked. The values are passed to that function. But when db_query using UPDATE SQL in that function is called, it acts like it works but the data in the database is not updated. Probably something simple I'm missing, but I'm not seeing it.

function docs_edit_folder_form( $form_state, $folder ) {	
	$form['title'] = array(
		'#type' => 'textfield',
		'#title' => 'Title',
		'#description' => 'The human readable descriptive title.',
		'#size' => 40,
		'#max_length' => 50,
		'#value' => $folder->title
	);

	$form['description'] = array(
		'#type' => 'textarea',
		'#title' => 'Description',
		'#description' => 'Any additional information about the folder can be added here.',
		'#cols' => 40,
		'#value' => $folder->description
	);
	
	$form['id'] = array(
		'#type' => 'hidden',
		'#value' => $folder->id
	);
	
	$form['submit'] = array(
		'#type' => 'submit',
		'#value' => t( 'Save' )
	);

	return $form;
}

function docs_edit_folder_form_submit( $form, &$form_state ) {
	db_query( "UPDATE {docs} SET title = '%s', description = '%s' WHERE id = '%d'", $form_state['values']['title'], $form_state['values']['description'], $form_state['values']['id'] );
	
	if ( db_affected_rows() > 0 ) {
		print( $form_state['values']['title'] );
	}
	else {
		print( 'Oops' );
	}
}

Comments

ethanw’s picture

is that a likely point of failure is the $folder argument being passed to the form function. what do you see when you var_dump it? are you sure it's what you're expecting?

--
ethan winn
http://labs.echoditto.com/

--
ethan winn
http://colab.coop

_shane_’s picture

simply passes the current values for the particular folder that is being edited. It's something to do with the query. That is how you perform a db update in Drupal isn't it?

arcaneadam’s picture

in the includes/database.inc and set the db_query function to call the _db_query() function like this _db_query($query,1).

It will put _db_query into debug mode and you will see if there are any errors when you submit the function.

Adam A. Gregory
_____________________________
Web Manger - Marketing Ministries
http://marketingministries.com
Founder - The Open Source Church
http://theopensourcechurch.org
Blogger - AdamAGregory.com
http://adamagregory.com

Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist

_shane_’s picture

getting somewhere now. The new form values are not getting passed to the submit function. Whatever the value was when the form was sent to the browser is what the submit function sees. So it must be something with the fact the form is being rendered and sent through AJAX request.