Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Drupal Form issues

  • 27-08-2015 2:39pm
    #1
    Registered Users Posts: 4,258 ✭✭✭


    Hi All,

    I have built a form that connects to a salesforce database to see if the serial number is valid but this doesn't seem to be working.

    Regardless what value I put in the form, it is still saying it's not part of the array when it is.

    I'm having huge trouble here so any help would be appreciated.

    Here is my code
    <?php
    function salesforceconnection(){	
    define("USERNAME", "USERNAME");
    define("PASSWORD", "PASSWORD");
    define("SECURITY_TOKEN", "PASSWORD TOKEN");
    require_once ('soapclient/SforcePartnerClient.php');
    
    $mySforceConnection = new SforcePartnerClient();
    $mySforceConnection->createConnection("soapclient/partner.wsdl.xml");
    $mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);
    
    $query = "SELECT Name FROM TREK__c";
    $result = $mySforceConnection->query($query);
    	
    $result2[] = $result ; 		
    
    return $result; 
    }
    	
    function formtest_menu() {
      $items = array();
      $items['form'] = array(
        'title' => t('TREK validation'),
        'page callback' => 'formtest_form',
        'access arguments' => array('access content'),
        'description' => t('My form'),
        'type' => MENU_CALLBACK,
      );
      return $items;
    }
    
    function formtest_form() {
      return drupal_get_form('formtest_my_form');
    }
    
    function formtest_my_form($form_state) {
     
      $form['serial'] = array(
        '#type' => 'textfield',
        '#title' => t('TREK'),
        '#required' => TRUE,
        '#description' => "Please enter your TREK serial in the format: XXX-XXX-XXX-XXX",
      );
        
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit',
      );
      return $form;
    }
    
    function formtest_my_form_submit($form, &$form_state){
    
    $serial = $form_state['input']['serial'];	
    
    function formtest_my_form_execute($form, $form_state){
    	foreach($result as $record){
    		
    	$id[] = $record->Name ;
    		 
    	}
    	
    
    
    	if(in_array($serial, $id))
    	{
    		drupal_set_message("Valid Serial number &#8230; Download will start");
    	}
    	else
    	{
    			drupal_set_message("This is not a valid serial number, please try again");
    	}
    
    }
    


Comments

  • Registered Users Posts: 5,963 ✭✭✭Talisman


    Where is the code below getting $result from?

    [PHP]function formtest_my_form_execute($form, $form_state){
    foreach($result as $record){

    $id[] = $record->Name ;

    }

    if(in_array($serial, $id))
    {
    drupal_set_message("Valid Serial number … Download will start");
    }
    else
    {
    drupal_set_message("This is not a valid serial number, please try again");
    }

    }[/PHP]


Advertisement