Re: Submitting form inputs as an array

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Submitting form inputs as an array

Justin Purdie
Thanks Wade. I appreciate your help. Now what if I wanted to make it a
little more complicated and had this as the html:

*
*
*<input type="text" name="friend[0][firstname][name]"
id="friend_0_firstname" />
<input type="text" name="friend[0][middlename]**[name]**"
id="friend_0_middlename" />*
*<input type="text" name="friend[0][lastname]**[name]**"
id="friend_0_lasttname" />*
*
*
*<input type="text" name="friend[1][firstname]**[name]**"
id="friend_1_firstname" />*
*<input type="text" name="friend[1][middlename]**[name]**"
id="friend_1_middlename" />*
*<input type="text" name="friend[1][lastname]**[name]**"
id="friend_1_lasttname" />*

I won't know the values in the numeric index, nor the number of inputs. The
numbers could be 0,1,2. Or could be 0,3,7,8. I want to loop through all the
"friend" params and have the names correlated with each other.

Using:

*Loop: (Action_Param: 'friend', -Count);*

* (Action_Param: 'friend', Loop_Count);*

*/Loop;*

Yields a count of 0. Thoughts?

Thanks again. I appreciate it.

Justin Purdie
SkyVantage Development
US Ph. +1-801-649-2925 option 305
US Fax. +1-419-828-6643
Skype (Calls only - no chat): skyvantage
Email: [hidden email]
twitter:  http://twitter.com/skyvantage
facebook: http://www.facebook.com/SkyVantage

---
This message may contain confidential and/or privileged information of
SkyVantage Corporation and  its affiliated companies.  If you are not the
intended recipient, please (i) do not disclose,  copy, distribute, or use
this information, (ii) advise the sender by return e-mail, and (iii)
delete  all copies from your computer.  Your cooperation is greatly
appreciated.


On Tue, Oct 2, 2012 at 6:24 PM, Wade Maxfield <[hidden email]>wrote:

> On 3/10/2012, at 1:10 PM, Justin Purdie <[hidden email]> wrote:
>
> > I basically have the same problem that is outlined on this page:
> >
> >
> http://www.johnrockefeller.net/html-input-forms-sending-in-an-array-in-php/
> >
> > But obviously I need to do it in Lasso 8.6, and am having trouble. Any
> > solution in Lasso?
> >
> > Thanks in advance.
> >
> > Justin Purdie
>
>
> Loop: (Action_Param: 'friend', -Count);
>   if: (Action_Param: 'friend', Loop_Count)->(Size) > 0;
>     (Action_Param: 'friend', Loop_Count);
>     '<br />';
>   /if;
> /Loop;
>
>
> From the Lasso Reference:
>
> -----------------
> To return all the repetitions of a named parameter:
>
> Use the [Action_Param] tag to return each repetition of a named parameter
> for the current database action. The following example returns each
> repetition of the First_Name parameter.
>
> [Loop: (Action_Param: 'First_Name', -Count)]
>   <br>[Action_Param: 'First_Name', Loop_Count]
> [/Loop]
>
> <br>John
> <br>John
> <br>Mary
> <br>Joe
> <br>Sarah
>
> -----------------
>
>
>  - Wade
>
>
> #############################################################
> This message is sent to you because you are subscribed to
>   the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>
>
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Submitting form inputs as an array

Brad Lindsay-2
On Oct 3, 2012, at 11:00 AM, Justin Purdie <[hidden email]> wrote:

> Thanks Wade. I appreciate your help. Now what if I wanted to make it a
> little more complicated and had this as the html:
>
> *
> *
> *<input type="text" name="friend[0][firstname][name]"
> id="friend_0_firstname" />
> <input type="text" name="friend[0][middlename]**[name]**"
> id="friend_0_middlename" />*
> *<input type="text" name="friend[0][lastname]**[name]**"
> id="friend_0_lasttname" />*
> *
> *
> *<input type="text" name="friend[1][firstname]**[name]**"
> id="friend_1_firstname" />*
> *<input type="text" name="friend[1][middlename]**[name]**"
> id="friend_1_middlename" />*
> *<input type="text" name="friend[1][lastname]**[name]**"
> id="friend_1_lasttname" />*
>
> I won't know the values in the numeric index, nor the number of inputs. The
> numbers could be 0,1,2. Or could be 0,3,7,8. I want to loop through all the
> "friend" params and have the names correlated with each other.
>
> Using:
>
> *Loop: (Action_Param: 'friend', -Count);*
>
> * (Action_Param: 'friend', Loop_Count);*
>
> */Loop;*
>
> Yields a count of 0. Thoughts?
>
> Thanks again. I appreciate it.

Lots of different ways of doing this. to make it a bit easier on me, I'm going to assume that your inputs look like this:

friend_id_x
friend_x_firstname
friend_x_lastname

and assume that all the friend_x stuff goes together. Here's some untested code that should point you in the right direction:

iterate(action_params, local('param'));
  if(#param->first->beginsWith('friend_id_');
    local('index') = #param->first->split('_')->last;
    #param->second + ' ' + action_param('friend_' + #index + '_firstname') +
    ' ' + action_param('friend_' + #index + '_lastname') + '<br />'
  /if;
/iterate;

HTH
Brad
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Submitting form inputs as an array

Wade Maxfield
In reply to this post by Justin Purdie
On 4/10/2012, at 4:00 AM, Justin Purdie <[hidden email]> wrote:

> Thanks Wade. I appreciate your help. Now what if I wanted to make it a
> little more complicated and had this as the html:
>
> *
> *
> *<input type="text" name="friend[0][firstname][name]"
> id="friend_0_firstname" />
> <input type="text" name="friend[0][middlename]**[name]**"
> id="friend_0_middlename" />*
> *<input type="text" name="friend[0][lastname]**[name]**"
> id="friend_0_lasttname" />*
> *
> *
> *<input type="text" name="friend[1][firstname]**[name]**"
> id="friend_1_firstname" />*
> *<input type="text" name="friend[1][middlename]**[name]**"
> id="friend_1_middlename" />*
> *<input type="text" name="friend[1][lastname]**[name]**"
> id="friend_1_lasttname" />*
>
> I won't know the values in the numeric index, nor the number of inputs. The
> numbers could be 0,1,2. Or could be 0,3,7,8. I want to loop through all the
> "friend" params and have the names correlated with each other.
>
> Using:
>
> *Loop: (Action_Param: 'friend', -Count);*
>
> * (Action_Param: 'friend', Loop_Count);*
>
> */Loop;*
>
> Yields a count of 0. Thoughts?
>
> Thanks again. I appreciate it.

Well, that's a little bit different to what you first asked about (well, actually totally different).

You have no input called friend so that's why you get 0.

I'd follow Brad's suggestion, or tweak the sending page to include an extra hidden field to the form and use that to store the numeric indices in use. Something like:

<input type="hidden" name="fieldindex" value="0,3,7,8" />

Then on the resulting page, grab that value, split on , to an array, iterate the array

Var: 'fieldindex' = (Action_Param: 'fieldindex')->(Split: ',');

Iterate: $fieldindex, (Var: 'temp');

        Var: 'firstname' = (Action_Param: ('friend' + $temp + 'firstname'));
        Var: 'middlename' = (Action_Param: ('friend' + $temp + 'middlename'));
        Var: 'lastname' = (Action_Param: ('friend' + $temp + 'lastname'));

        // do stuff here, store new values, etc.
        // clear out $firstname, $middlename, etc. for the next run.

/Iterate;


 - Wade




#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Submitting form inputs as an array

Justin Purdie
Yeah, that led me in the right direction. thanks for the help.

Justin Purdie
SkyVantage Development
US Ph. +1-801-649-2925 option 305
US Fax. +1-419-828-6643
Skype (Calls only - no chat): skyvantage
Email: [hidden email]
twitter:  http://twitter.com/skyvantage
facebook: http://www.facebook.com/SkyVantage

---
This message may contain confidential and/or privileged information of
SkyVantage Corporation and  its affiliated companies.  If you are not the
intended recipient, please (i) do not disclose,  copy, distribute, or use
this information, (ii) advise the sender by return e-mail, and (iii)
delete  all copies from your computer.  Your cooperation is greatly
appreciated.


On Wed, Oct 3, 2012 at 3:31 PM, Wade Maxfield <[hidden email]>wrote:

> On 4/10/2012, at 4:00 AM, Justin Purdie <[hidden email]> wrote:
>
> > Thanks Wade. I appreciate your help. Now what if I wanted to make it a
> > little more complicated and had this as the html:
> >
> > *
> > *
> > *<input type="text" name="friend[0][firstname][name]"
> > id="friend_0_firstname" />
> > <input type="text" name="friend[0][middlename]**[name]**"
> > id="friend_0_middlename" />*
> > *<input type="text" name="friend[0][lastname]**[name]**"
> > id="friend_0_lasttname" />*
> > *
> > *
> > *<input type="text" name="friend[1][firstname]**[name]**"
> > id="friend_1_firstname" />*
> > *<input type="text" name="friend[1][middlename]**[name]**"
> > id="friend_1_middlename" />*
> > *<input type="text" name="friend[1][lastname]**[name]**"
> > id="friend_1_lasttname" />*
> >
> > I won't know the values in the numeric index, nor the number of inputs.
> The
> > numbers could be 0,1,2. Or could be 0,3,7,8. I want to loop through all
> the
> > "friend" params and have the names correlated with each other.
> >
> > Using:
> >
> > *Loop: (Action_Param: 'friend', -Count);*
> >
> > * (Action_Param: 'friend', Loop_Count);*
> >
> > */Loop;*
> >
> > Yields a count of 0. Thoughts?
> >
> > Thanks again. I appreciate it.
>
> Well, that's a little bit different to what you first asked about (well,
> actually totally different).
>
> You have no input called friend so that's why you get 0.
>
> I'd follow Brad's suggestion, or tweak the sending page to include an
> extra hidden field to the form and use that to store the numeric indices in
> use. Something like:
>
> <input type="hidden" name="fieldindex" value="0,3,7,8" />
>
> Then on the resulting page, grab that value, split on , to an array,
> iterate the array
>
> Var: 'fieldindex' = (Action_Param: 'fieldindex')->(Split: ',');
>
> Iterate: $fieldindex, (Var: 'temp');
>
>         Var: 'firstname' = (Action_Param: ('friend' + $temp +
> 'firstname'));
>         Var: 'middlename' = (Action_Param: ('friend' + $temp +
> 'middlename'));
>         Var: 'lastname' = (Action_Param: ('friend' + $temp + 'lastname'));
>
>         // do stuff here, store new values, etc.
>         // clear out $firstname, $middlename, etc. for the next run.
>
> /Iterate;
>
>
>  - Wade
>
>
>
>
> #############################################################
> This message is sent to you because you are subscribed to
>   the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>
>
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>