1

I am attempting to search and edit information by using 2 webforms. The custom table is found in the database that my Drupal project is using and is named "test_update." It has 2 records on the table.

The webforms are:

1.Edit Search customer

Search form which redirects to Update/Edit customer form if the record was found

The user inputs the name which to retrieve the wanted information. A select query is executed using the value captured by the user to identify the record when the webform is submitted.

  • If the record is identified, it redirects to the Update/Edit Customer webform and displays the values on the respective textfields. Example : Richard was found from the table on the database. Since the record was found, the information "Name: Richard" and "Surname: Warwick" are displayed on the **Update/Edit Customer webform.**

  • If it is not identified, it displays a message and redirects to the "Edit Search customer" webform.

2.Update/edit customer

The form is used to edit existing customer details displayed on the fields. The details are then saved when the webform is submitted

The displayed values on the fields can then be edited. When the webform is submitted, all changes are then saved to the table.

I added the following codes in the webform.module file. They are found inside the function webform_webform_submission_insert($node, $submission) :

$accessnode=$node->nid;
if($accessnode==8) //nid of the eidt search customer form is 8, if this webform is selected
{
    $searchByName=$submission->data[1]['value'];

    //select query
    $result=db_query("SELECT * FROM {test_update} WHERE name = :name",array(':name'=>$searchByName))->fetchAll(); 

    if(!(empty($result)))
    {
        //redirect to webform with nid 7 (Update/Edit Customer webform)
        //Use the result set to display the values to the webform with nid 7 ()
        //on submit, it updates and saves the data into the table from the Update/Edit customer webform


    }
    else
    {
        //display error message and redirects to the search page
        drupal_set_message(t('The customer does not exist. Try again'), 'error'); 
        header('Refresh: 5;url=http://localhost/babyDrupal/node/8');// Aim: redirect after 5 secs to the search edit form, Result: it doesn't redirect to the page

    }

}

Can I have some help on how I can acheive this please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.