Drupal 7 Module Development Tutorial #8: Drupal Form Submit and Validate Functions

preview_player
Показать описание


In this 8th Drupal video tutorial, I show you how to create submit and validate functions to handle users submitting forms. Specifically, we use the default submit function created by Drupal to prep our information and pass it off to a function which updates the database. We then log a watchdog message so administrators know applications were reviewed.

Lastly, we create a validate function to double check the information received from the form submission to ensure we don't get incorrect values. In doing so, I show you how to set errors on specific form elements. It's important to remember that validate functions are called before submit functions.
Рекомендации по теме
Комментарии
Автор

Great Playlist. Would love to see more about creating modules involving forms specifically, and template files and how to customize various aspects to a site (views, blocks, forms, etc)

andrewbickford
Автор

I've gotten used to watching you at 50% speed and.. I must say you sound a bit intoxicated talking that low and slow (haha) .  It's amazing how much information you pack in and the pause button works fine.  I go and read a bit of the drupal api (etc) pages you bring us to then resume the videos ... and always pause to type out the code you put on our video "blackboard" .  Thanks for the great job on all of them

TomsTomTomdotcom
Автор

A lot of thank, I was writing dpm into the form, for that reason does not show the array values. It, s into the submit....

EdwinVegaMoreno
Автор

Hi wondering if you might be available for a small freelance project? I tried to reach you through your website but spam protection won't allow me to submit. I basically need help setting up an additional action on user form submission.

Jalapimedia-website-design
Автор

Wow .. really great videos mate, you are very good at explaining your code. I just have one question, somehow when I try to use the dsm() function I just get errors saying that dsm is a undefined function am I missing something? (using drupal 7.34)

Inaquee
Автор

can you give an example of the last thing you were discussing, using the #submit  key in the $form array? what did you mean by doing a "trick" using #validate? how so?

andrewbickford
Автор

If you were using hook_alter_form and you needed insert to some html / text into a entity registration form, what determines where that markup would show up on the form?

AndrewGarman
Автор


Line 99 is ->fileds(array('status' => $action))

See anything I"m doing wrong?

function flag_application_administration($action, $values) {
dsm($action, 'Action');
$status = ($action == 1) ? 'Approved' : 'Denied';
dsm($status, 'Status');
dsm($values, 'Values');
foreach ($values as $key => $value) {
$num_updated = db_update('flag_application')
->fileds(array('status' => $action))
->condition('flagging_id', $value['flagging_id'])
->execute();
watchdog('flag_application', t("!name's application for !node was !status",
array('!name' => $value['name'], '!node' => $value['title'], '!status' => $status)));
}
}

heysusenothere
Автор

Love the tutorials. Please talk slower. At the start of the video you sound like you're just reading as fast as you can and words are so closed together I can't separate them.

CyJobes
Автор

One thing seriously, please talk slower, but you're great!

EdwinVegaMoreno