Input values into drupal form programmatically
Posted by sagarmitra on December 17, 2010 at 5:30am
How can i populate the form fields programmatically
Let me illustrate, consider the following example
<?php
function form(){
return drupal_get_form('myform');
}
function myform($form_state){
$form['name'] = array(
'#type' => 'textfield',
'$title' => 'Name: ',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save',
);
return $form;
}
function myform_submit($form,&$form_state){
$form_id = 'myform';
$form_state['values']['name'] = 'Hello World';
drupal_execute($form_id,$form_state);
}
?>