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
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

Drupal Form issues

Options
  • 27-08-2015 3: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: 6,001 ✭✭✭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