Retrive address from an array

Ron 28 Apr, 2012
Hello,

I have an address.php file as an array and I want to retrieve the address corresponding to each name. I want to us it for replies to users in my chronoforms. How can I do it please help.
The code is below:
 <? php

    $values = array(
	/* The username are james123, sandra090 etc. for help contact: siki_@email.com */
		
       'james123' => array( 
	                       'company'=>'<strong>James Turner Ltd.</strong><br>',
	                       'address'=>'Street Name.<br>Lane-6<br>South Africa.<br>',
						   'email'=>'james@xyz.com<br>',
						   'phone'=>'+1-987-1234567<br>'						   
						    ), 
							
       'sandra090' => array( 
	                       'company'=>'<strong>Sandra Jones Inc.</strong><br>',
	                       'address'=>'Oxford Street.<br>London.<br>',
						   'email'=>'sandra@abc.com<br>',
						   'phone'=>'+44-667-121212<br>'
						   ) 						   
     );
?>


I was trying to use something like this to retrieve:
$path = JPATH_ROOT.DS.'components'.DS.'com_addresses'.DS; 
require_once($path.'name_array.php');
 echo("\n         {$values['james123']}");


I would like the address to be displayed as:

James Turner Ltd.
Street Name.
Lane-6
South Africa.

[email]james@xyz.com[/email]
+1-987-1234567

Please suggest
Thanks
Ron
GreyHead 29 Apr, 2012
Hi Ron,

The code looks OK. What isn't working?

Bob
Ron 29 Apr, 2012

Hi Ron,

The code looks OK. What isn't working?

Bob



Sorry Bob,

I asked a question wrongly 😶 The form code is below.
   <table class="tmc"> 
<tr><th width="361" rowspan="2" nowrap>Please mention your username correctly.</th>
<td width="10" class="tmc"></tr></table>
   <table width="100%" border="0" cellspacing="1" cellpadding="4">

                             
<tr>
				  <td width="299" align="left" valign="middle" class="">Please enter Your username:</td>

					<td><input size="42" required="true" name="username" id="username" type="text" style="font-family:Verdana, Geneva, sans-serif; width:280px; font-size:15px; border:1px solid #999;" /></td>
				</tr>             
				<tr>
                 <td width="299" align="left" valign="middle" class="">Need a call? Your phone number:</td>
					<td><input size="35"  name="phone" id="phone" type="text" style="font-family:Verdana, Geneva, sans-serif; width:280px; font-size:15px; border:1px solid #999;"/></td>
				</tr> 
                <tr>
				  <td width="299" align="left" valign="middle" class=""></td>
					<td><input value="<?php echo $values['username']['email']; ?>" size="35" class=" validate['required']" name="email" id="email" type="hidden" /></td>
				</tr>                
                <tr>
				  <td width="299" align="left" valign="middle" class=""><strong>Telephone call from us can help.</strong></td>
					<td><input value="Dealership Agreement" size="35" class=" validate['required']" name="subject" id="subject" type="hidden" /></td>
				</tr>
                                <tr>
				  <td width="299" align="left" valign="middle" class=""></td>
					<td><input value="<?php echo date("d-m-Y")?>" size="35" class=" validate['required']" name="date" id="date" type="hidden" /></td>
				</tr>
                <tr>
				  <td width="299" align="left" valign="middle" class=""><input value="Submit " name="submit" type="submit" class="required" id="submit"
    onclick="this.disabled=false;this.value='Okay ! Submit...';document.getElementById('country_name').style.visibility ='show';document.getElementById('phone').focus();"/>
</td>
					<td></td>
				</tr>
                
                                
   </table>


I do not know how to pickup the username. I tried to use this:
<?php echo $values["<?php echo $form->data['username']; ?>"]["email"]; ?>
But I am not successful.
I need that when the user enters his username the code should fire as per username.

thanks for the help

Ron
GreyHead 29 Apr, 2012
Hi Ron,

Hmm you can't put PHP tags inside PHP tags:
<?php echo $values["<?php echo $form->data['username']; ?>"]["email"]; ?>
Please try
<?php
echo $values[$form->data['username']]["email"];
?>
or more tidily:
<?php
$user_info =& $values[$form->data['username']];
echo $user_info['email'];
?>

Bob
Ron 29 Apr, 2012
Thanks Bob,

It worked. I just need to know something more. The form has a field for username input. If I am to use the username used in joomla registration then what do I modify in the code?

Thanks for that great help

Ron
GreyHead 29 Apr, 2012
Hi Ron,

It will be something like this:
<?php
$user =& JFactory::getUser(); 
$user_info =& $values[$user->username];
echo $user_info['email'];
?>

Bob
Ron 29 Apr, 2012
It works Bob,

Thanks Very much.

Ron
Ron 08 May, 2012
Hey Bob 🙂

Hope I am not bothering too much. I have a bottle neck and I need a push to go through. The below mentioned is a form field:
<td>
<select name="currency" required="true" id="currency" onchange="setFlag(this.value)" style="font-family:Verdana, Geneva, sans-serif; width:280px; font-size:15px; border:1px solid #999;">
<option value="US Dollars">US Dollars</option>
<option value="Euros">Euros</option>
<option value="Ukrainian Hryvna">Ukrainian Hryvna</option>
<option value="Indian Rupees">Indian Rupees</option>
</select> <input size="35"  name="price" id="rate" type="text" style="font-family:Verdana, Geneva, sans-serif; width:80px; font-size:15px; border:1px solid #999;"/></td>


There is a price field in the form and the user fill in the value. I also have a dynamic price array. Now I want that if the user does not fill in the value the reply template should pickup from the price array.

I tried this code but it does not seem to work:
 <? php
require_once ( JPATH_ROOT .DS.'components'.DS.'com_prices'.DS.'prices.php' );
$percent = '0.3'; // without %
$freight_value = ("\n         {$prices['frt_eur_200']}");// Freight Charges
$packing_value = ("\n         {$prices['pack_eur_200']}");// Packing Charges
$total = $form->data['price'];
if ($form->price) {
        $value =& $form[$form->data['rate']];
            //redirect('/');
    } else {
        $user_info =& $prices[$form->data['eur_200']];
    }


Please help.

Thanks

Ron
GreyHead 15 May, 2012
Hi Ron,

Sorry for the delay, I was away last week.

Where does $form->price come from in this line:
if ($form->price) { 
It isn't defined anywhere that I can see.

Bob
Ron 16 May, 2012
Thanks for the Reply Bob,

I am very bad at understanding codes but I try my best and most of the time I get confused. The "price" comes from the text field of the form:

</select> <input size="35"  name="price" id="rate" type="text" style="font-family:Verdana, Geneva, sans-serif; width:80px; font-size:15px; border:1px solid #999;"/></td>


I think it may be wrong but I just need that if the users fills in the value it is taken and if it remains empty the code picks up from the prices.php array.

Thanks

Ron.
GreyHead 17 May, 2012
Hi Ron,

Yes, BUT - ChronoForms pus the form data in the $from->data array so it will be $form->data['price']

Bob
Ron 17 May, 2012
Thanks Bob,

So do you thnik the code should be like this :
<? php
require_once ( JPATH_ROOT .DS.'components'.DS.'com_prices'.DS.'prices.php' );
$percent = '0.3'; // without %
$freight_value = ("\n         {$prices['frt_eur_200']}");// Freight Charges
$packing_value = ("\n         {$prices['pack_eur_200']}");// Packing Charges
$total = $form->data['price'];
if ($form->price) {
        $value =& $form[$form->data['rate']];
            //redirect('/');
    } else {
        $user_info =& $prices[$form->data['eur_200']];
    }
?>

Please give your views as this code does not work.

Thanks
GreyHead 17 May, 2012
Hi Ron,

What is this line??
if ($form->price) {
You can't make code up from thin air and expect that it will work :-(

Bob
Ron 18 May, 2012
Sorry bob

I think I have messed up the post:I just need
<?php
$total =
if (price is filled in)
  code to be executed if condition is true;
else
  code to be executed if condition is false;
?>

and for that I am trying to use the following code:
<?php  
  
$total = 
//Trying to pick up from the form field
if ($form->price) {
        $value =& $form[$form->data['rate']];
//redirect and pickup from an array
    } else {
        $user_info =& $prices[$form->data['eur_200']];
    }
?>

I have a price field in my form if the user enters a figure in the field it is taken if it is not entered then the code picks up from an array.

Hope I am able to rightly explain.

Thanks

Ron
GreyHead 19 May, 2012
Hi Ron,

Please see my earlier posts about $form->price. As far as I can see you have invented this and it has no value.

Bob
Ron 19 May, 2012

Hi Ron,

Please see my earlier posts about $form->price. As far as I can see you have invented this and it has no value.

Bob



Thanks for replying,

I have solved it. There were few errors which I could resolve.

Thanks again

Ron.
This topic is locked and no more replies can be posted.