php-general Digest 9 Mar 2013 19:07:47 -0000 Issue 8154

Topics (messages 320440 through 320445):

Re: Populate input from another form
        320440 by: Jim Giner
        320441 by: Jim Giner
        320442 by: tamouse mailing lists
        320443 by: Jim Giner
        320444 by: Curtis Maurand
        320445 by: Jim Giner

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On 3/8/2013 3:43 PM, John Taylor-Johnston wrote:
Scratch that, IE does not like form elements outside the </form>!!?? :,(
I can't a form within a form either, unless ... I float a div??.

John Taylor-Johnston wrote:
I have a form

<form action="CRTP_Query.php" id="CRTP_Query" method="post"
target="_CRTP"><input value="Query" form="CRTP_Query"
type="submit"></form>

OnSubmit, I want to include data from another form (form="DPRform").

<input name="DPRsurname" type="text" form="DPRform" size="20"
value="<?php echo stripslashes($_POST["DPRsurname"]);?>">

I should use a hidden identical field and use form="CRTP_Query":

<input name="DPRsurname" type="hidden" form="CRTP_Query" value="<?php
echo stripslashes($_POST["DPRsurname"]);?>">

But I have no idea how to populate the hidden field with the data from
the viewable field. PHP cannot do this onsubmit, can it?

Anyone have an example to show me please?

Do I need to use jquery?

no.

--- End Message ---
--- Begin Message ---
On 3/8/2013 2:45 PM, John Taylor-Johnston wrote:
I have a form

<form action="CRTP_Query.php" id="CRTP_Query" method="post"
target="_CRTP"><input value="Query" form="CRTP_Query" type="submit"></form>

OnSubmit, I want to include data from another form (form="DPRform").

<input name="DPRsurname" type="text" form="DPRform" size="20"
value="<?php echo stripslashes($_POST["DPRsurname"]);?>">

I should use a hidden identical field and use form="CRTP_Query":

<input name="DPRsurname" type="hidden" form="CRTP_Query" value="<?php
echo stripslashes($_POST["DPRsurname"]);?>">

But I have no idea how to populate the hidden field with the data from
the viewable field. PHP cannot do this onsubmit, can it?

Anyone have an example to show me please?

Do I need to use jquery?
I assume that you really, really need to have multiple forms here? Different targets? Otherwise, why the two forms?

Realizing that you are using html 5 syntax here, and that html5 is not supported fully on many browsers (that you may have to support), you are going to have to use some javascript to grab the input from elements outside your form and populate the hidden ones inside your form. Not a difficult thing.

In your onsubmit handler, simply do

document.getElementById(fld1_hidden).value = document.getElementById(fld1).value;


--- End Message ---
--- Begin Message ---
On Fri, Mar 8, 2013 at 9:17 PM, Jim Giner <jim.gi...@albanyhandball.com> wrote:
> On 3/8/2013 2:45 PM, John Taylor-Johnston wrote:
>>
>> I have a form
>>
>> <form action="CRTP_Query.php" id="CRTP_Query" method="post"
>> target="_CRTP"><input value="Query" form="CRTP_Query"
>> type="submit"></form>
>>
>> OnSubmit, I want to include data from another form (form="DPRform").
>>
>> <input name="DPRsurname" type="text" form="DPRform" size="20"
>> value="<?php echo stripslashes($_POST["DPRsurname"]);?>">
>>
>> I should use a hidden identical field and use form="CRTP_Query":
>>
>> <input name="DPRsurname" type="hidden" form="CRTP_Query" value="<?php
>> echo stripslashes($_POST["DPRsurname"]);?>">
>>
>> But I have no idea how to populate the hidden field with the data from
>> the viewable field. PHP cannot do this onsubmit, can it?
>>
>> Anyone have an example to show me please?
>>
>> Do I need to use jquery?
>
> I thought that the new 'form' attrib did that for you?  No?

My understanding is that the new form attribute on input lets you put
an input tag *outside* any forms, and use the form= attribute to
indicate which form it should go with. I think this may be more useful
for mobile web apps than desktop browser apps. It doesn't let you copy
a form element from one form to another.

If you have multiple forms on one page, and want to submit data that
is placed in one form with another one, you will have to do that with
JS/jQeury. I don't have a ready example, but the basic concept is:

* capture the form submit using an onclick
* which calls a function that can gather up all the information from
the other forms, and
* build hidden form elements on the fly for the form you want to submit, and
* then programmatically perform the submit

This seems interesting enough that I might do up a tutorial on it when
I have some time.  Maybe Tedd already has one?

--- End Message ---
--- Begin Message ---
On 3/8/2013 11:07 PM, tamouse mailing lists wrote:
On Fri, Mar 8, 2013 at 9:17 PM, Jim Giner <jim.gi...@albanyhandball.com> wrote:
On 3/8/2013 2:45 PM, John Taylor-Johnston wrote:

I have a form

<form action="CRTP_Query.php" id="CRTP_Query" method="post"
target="_CRTP"><input value="Query" form="CRTP_Query"
type="submit"></form>

OnSubmit, I want to include data from another form (form="DPRform").

<input name="DPRsurname" type="text" form="DPRform" size="20"
value="<?php echo stripslashes($_POST["DPRsurname"]);?>">

I should use a hidden identical field and use form="CRTP_Query":

<input name="DPRsurname" type="hidden" form="CRTP_Query" value="<?php
echo stripslashes($_POST["DPRsurname"]);?>">

But I have no idea how to populate the hidden field with the data from
the viewable field. PHP cannot do this onsubmit, can it?

Anyone have an example to show me please?

Do I need to use jquery?

I thought that the new 'form' attrib did that for you?  No?

My understanding is that the new form attribute on input lets you put
an input tag *outside* any forms, and use the form= attribute to
indicate which form it should go with. I think this may be more useful
for mobile web apps than desktop browser apps. It doesn't let you copy
a form element from one form to another.

If you have multiple forms on one page, and want to submit data that
is placed in one form with another one, you will have to do that with
JS/jQeury. I don't have a ready example, but the basic concept is:

* capture the form submit using an onclick
* which calls a function that can gather up all the information from
the other forms, and
* build hidden form elements on the fly for the form you want to submit, and
* then programmatically perform the submit

This seems interesting enough that I might do up a tutorial on it when
I have some time.  Maybe Tedd already has one?

That's a different take than I thought it meant (the docs that is). Makes sense tho, if true. I thought from reading "one or more forms" in the docs I've seen, that it meant "allowing the input to be included in *all* of the forms mentioned in the attrib.

Something that should be tested by our OP here.

Of course the real problem is html 5 support.

--- End Message ---
--- Begin Message ---
No, but javascript can.



Jim Giner <jim.gi...@albanyhandball.com> wrote:

>On 3/8/2013 3:43 PM, John Taylor-Johnston wrote:
>> Scratch that, IE does not like form elements outside the </form>!!??
>:,(
>> I can't a form within a form either, unless ... I float a div??.
>>
>> John Taylor-Johnston wrote:
>>> I have a form
>>>
>>> <form action="CRTP_Query.php" id="CRTP_Query" method="post"
>>> target="_CRTP"><input value="Query" form="CRTP_Query"
>>> type="submit"></form>
>>>
>>> OnSubmit, I want to include data from another form (form="DPRform").
>>>
>>> <input name="DPRsurname" type="text" form="DPRform" size="20"
>>> value="<?php echo stripslashes($_POST["DPRsurname"]);?>">
>>>
>>> I should use a hidden identical field and use form="CRTP_Query":
>>>
>>> <input name="DPRsurname" type="hidden" form="CRTP_Query"
>value="<?php
>>> echo stripslashes($_POST["DPRsurname"]);?>">
>>>
>>> But I have no idea how to populate the hidden field with the data
>from
>>> the viewable field. PHP cannot do this onsubmit, can it?
>>>
>>> Anyone have an example to show me please?
>>>
>>> Do I need to use jquery?
>>
>no.
>
>-- 
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

--- End Message ---
--- Begin Message ---
Did some testing with a form.
Tried it with IE9, Chrome 25.0.xxx and Safari 5.7.1
Mixed results - good and bad

IE - forget it. The new form attrib does not work.

Chrome - only works if the input element is in the form but has NO form attrib OR if it is NOT in the form and has only ONE form attrib value
Can't use an input element in multiple forms.

Safari - works kinda like I expected originally!! Depending upon where the elements are declared with regards to the forms themselves, you get different sets of values captured from the submits. Some multiple form designations work, some don't and it's way to complicated to explain here. I tried to do it and failed miserably. But - Safari works a lot more like the docs say it should, but still not completely.

Of course - in the real world where currently it's Chrome and IE, these new features are not very useful since you can't include an input element in multiple forms which from the docs one would think could be done.
--- End Message ---

Reply via email to