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 there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Drupal Form issues

  • 27-08-2015 2:39pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 6,289 ✭✭✭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