How to get the value of textbox

hello to all yii users, i need some help i want to get the value of LastName, FirstName, and middle, cause I want to make a auto generated username the rule is this:

User Name - the format is <firstletteroffirstname> + <middleinitial> + <lastname>

e.g: John A. Doe = jadoe

jadoe is become there username

one of my problem is I don’t know how to get the value of variable put in first, last and middle name

my 2nd problem is a logical problem if happen user create like this

e.g: Jake A. Doe is it would be jadoe

and John A. Doe = jadoe

i dont know how to trap that, my boss said no number allowed in username like this jadoe01

this my form its for registration

obRegistraion_form

&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'LastName'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;model,'LastName',array('size'=&gt;50,'maxlength'=&gt;50)); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'LastName'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'FirstName'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;model,'FirstName',array('size'=&gt;50,'maxlength'=&gt;50)); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'FirstName'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'MiddleName'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;model,'MiddleName',array('size'=&gt;50,'maxlength'=&gt;50)); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'MiddleName'); ?&gt;


&lt;/div&gt;

I am new user of yii and php so dont know how its work, your answer save my job please help thanks

You need an ajax function for suggestion based username.

if you want to get value of textbox then just define custom class in your textbox.

eg. -


<?php echo $form->textField($model,'FirstName',array('size'=>50,'maxlength'=>50, 'class'=>'fname')); ?>

<?php echo $form->textField($model,'FirstName',array('size'=>50,'maxlength'=>50, 'class'=>'mname')); ?>

<?php echo $form->textField($model,'LastName',array('size'=>50,'maxlength'=>50, 'class'=>'lname')); ?>

now you can text box value through jquery -


$(document).ready(function() {

   var fname = $('.fname').val();  //first name

   var mname = $('.mname').val();  //middle name

   var lname = $('.lname').val();  //last name




   $.ajax({

        //pass here parameters to your ajax function

   )};

   

});

Create a function in your controller for suggest the username -


public function actionSuggetion() {

    if(Yii::app()->request->isAjaxRequest){ 

      .....

      Here validate & create an username

      ...

      ..

   }

}


bug 1: one of my problem is I don't know how to get the value of variable put in first, last and middle name

In ur controller action :

$firstname = $_POST[‘Members’][‘FirstName’];

$middlename = $_POST[‘Members’][‘MiddleName’];

$lastname = $_POST[‘Members’][‘LastName’];


bug 2: User Name - the format is <firstletteroffirstname> + <middleinitial> + <lastname>

$val1 = substr($firstname, 0, 1); // if it is rupal it will give u first character= ‘r’

$val2 = substr($middlename , 0, 1);

$val3 = $lastname;

Now concate above val

$username = "$val1" . "$val2" . "$val3";


my 2nd problem is a logical problem if happen user create like this

Now u have to check with db is same username exists

if yes then take first 2 character from firstname

e.g. $val1 = substr($firstname, 0, [color="#FF0000"]2[/color]);

else

store in database.

reply me if u find ny bug or ny more suggestion.

thanks for helping me sir/maam

but the only i want to know how the variable pass to each other example in visual basic code

e.g visual basic

firstname = txtFirstName.Text

e.g java

firstname = textField.getText();

e.g php

<input type="text" name="firstname" value="firstname" id="firstname">

<php>echo $_GET[‘firstname’];</php>

in yii??

sorry for newbie question I am only 1 week studying php then I go rush to study Yii because all system in company that I hired is using Yii

in the code that i post I think(iam not sure) $model is the variable and then it pass to database

but the next code $model is use again so $model become dynamic

if I only know how the data flow in yii I can learn it easyly please help me I beg you :unsure: :unsure: :unsure:

<?php echo $form->textField($model,‘FirstName’,array(‘size’=>50,‘maxlength’=>50)); ?>

<?php echo $form->textField($model,‘LastName’,array(‘size’=>50,‘maxlength’=>50)); ?>

Here $model is name of model.

In your controller action $model is defined.

still not understand than copy paste controller code, will show u.

u should start learning basic of yii then jump to code.

here for more info in my question :mellow:

thank a lot every one

http://www.yiiframework.com/forum/index.php/topic/63273-how-to-get-the-value-of-textbox/page__view__findpost__p__279003

read this

got this or still have doubt.

if yes then give me ur mail id will communicate there.

view

<?php echo $form->textField($model,‘FirstName’,array(‘size’=>50,‘maxlength’=>50, ‘class’=>‘fname’)); ?>

<?php echo $form->textField($model,‘FirstName’,array(‘size’=>50,‘maxlength’=>50, ‘class’=>‘mname’)); ?>

<?php echo $form->textField($model,‘LastName’,array(‘size’=>50,‘maxlength’=>50, ‘class’=>‘lname’)); ?>

I resolve it

just go to controller then

if you want to pass the data of last name

$variable = $model->LastName;