Yii Framework Forum: How to get the value of textbox - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to get the value of textbox Newbie question please help me Rate Topic: *---- 1 Votes

#1 User is offline   xmatzx01 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 10-March 15

Posted 19 April 2015 - 10:48 PM

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


<div class="row">
<?php echo $form->labelEx($model,'LastName'); ?>
<?php echo $form->textField($model,'LastName',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'LastName'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'FirstName'); ?>
<?php echo $form->textField($model,'FirstName',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'FirstName'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'MiddleName'); ?>
<?php echo $form->textField($model,'MiddleName',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'MiddleName'); ?>
</div>


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

Attached File(s)


0

#2 User is offline   Rohit Suthar 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 247
  • Joined: 12-May 14
  • Location:Mumbai, India

Posted 20 April 2015 - 01:53 AM

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
      ...
      ..
   }
}

Thanks & regards,

ROHIT SUTHAR
Mumbai(India)

Follow me - @rohisuthar

yii.at

If you found your solutions.... Don't hesitate to click on '+1' button
0

#3 User is offline   rups g 

  • Standard Member
  • PipPip
  • Yii
  • Group: Validating
  • Posts: 146
  • Joined: 16-December 14
  • Location:India

Posted 20 April 2015 - 02:13 AM

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, 2);
else
store in database.


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

#4 User is offline   xmatzx01 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 10-March 15

Posted 20 April 2015 - 04:46 AM

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:

Attached File(s)

  • Attached File  123.png (206.85K)
    Number of downloads: 5

0

#5 User is offline   rups g 

  • Standard Member
  • PipPip
  • Yii
  • Group: Validating
  • Posts: 146
  • Joined: 16-December 14
  • Location:India

Posted 20 April 2015 - 04:54 AM

View Postxmatzx01, on 20 April 2015 - 04:46 AM, said:

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


<?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.
0

#6 User is offline   xmatzx01 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 10-March 15

Posted 20 April 2015 - 04:57 AM

here for more info in my question :mellow:


thank a lot every one

Attached File(s)


0

#7 User is offline   rups g 

  • Standard Member
  • PipPip
  • Yii
  • Group: Validating
  • Posts: 146
  • Joined: 16-December 14
  • Location:India

Posted 20 April 2015 - 05:00 AM

http://www.yiiframew...post__p__279003
read this
0

#8 User is offline   rups g 

  • Standard Member
  • PipPip
  • Yii
  • Group: Validating
  • Posts: 146
  • Joined: 16-December 14
  • Location:India

Posted 20 April 2015 - 06:43 AM

View Postrups g, on 20 April 2015 - 05:00 AM, said:


got this or still have doubt.
if yes then give me ur mail id will communicate there.
0

#9 User is offline   xmatzx01 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 10-March 15

Posted 23 April 2015 - 07:44 PM

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;
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users