[ciapug] Form submission

David Champion ciapug@cialug.org
Fri, 10 Sep 2004 13:29:19 -0500


Lathrop Preston wrote:

> Tim Perdue wrote:
> 
>> Jerry Weida wrote:
>>
>>> This generally occurs when the submit button is not of the type
>>> submit.  You can either change that to a submit type or your can write
>>> some javascript.
>>> can't remember how to get the keycode into the fuction, but I'm sure
>>> you can find that out somewhere online pretty easy, or maybe someone
>>> here on the list would know.
>>> some pseudo-code
>>>
>>> <input type="button" onChange="javascript:submitform()" />
>>>
>>> function submitform() {
>>>   if btn=chr(13)   # see if we hit the enter key
>>>     document.forms[0].submit()
>>> }
>>
>>
>>
>> I've had this happen when I do use the type="submit", and on the 
>> receiving end, my php is looking for "if ($submit) {"
>>
>> Since submit was never pressed, the if statement doesn't work out to 
>> true.
>>
>> So you can get around it by having an <input type="hidden" name="foo" 
>> value="1"> and then on the receiving end you do "if ($foo) "
>>
>> And it works out to true whether they hit submit button or not.
> 
> 
> for that matter you don't even need a special field.
> 
> just use
> if ( is_set($_POST['somefield']) )
> 
> as long as the page was the result of a post with 'somefield' as one of 
> the fields it will work even if the user leaves the field blank because 
> the variable is set (just as '')

The - "if ($foo)..." will return false when there's not a value 
supplied. In Tim's example, he supplied a value="1", so it will work.

The "isset()" is less ambiguous, and probably a more robust way of 
handling it.

-dc