Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Drupal Form issues

  • 27-08-2015 03:39PM
    #1
    Registered Users, Registered Users 2 Posts: 4,260 ✭✭✭


    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, Registered Users 2 Posts: 7,104 ✭✭✭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