The below code does file attachement without nid....I want this to be looped..as we get the &quot;File Attachment option &quot; in page content type when we enable the Upload module..<div>I am trying to do file upload without nid created....</div>
<div>Thanks for your kind help in achieving this..</div><div><br></div><div><br><div><div>function my_form(&amp;$form_state)</div><div>{</div><div><br></div><div>$form[&#39;field1&#39;]=array(</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>&#39;#title&#39;=&gt;&#39;&#39;,</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>&#39;#type&#39;=&gt;&#39;textfield&#39;,</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>&#39;#prefix&#39;=&gt;&#39;&lt;table class=&quot;formtable&quot;&gt;&lt;tr&gt;&lt;td class=&quot;labeltext&quot;&gt;FIELD 1&lt;/td&gt;&lt;td class=&quot;textbox&quot;&gt;&#39;,</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>&#39;#suffix&#39;=&gt;&#39;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39;,</div><div>  );</div><div>   </div><div>   </div><div>   </div><div>   $form[&#39;#attributes&#39;][&#39;enctype&#39;] = &quot;multipart/form-data&quot;;</div>
<div><br></div><div>  // add a file upload file</div><div>  $form[&#39;upload&#39;] = array(</div><div>    &#39;#type&#39; =&gt; &#39;file&#39;,</div><div>    //&#39;#title&#39; =&gt; t(&#39;Attach a file&#39;),</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>&#39;#prefix&#39;=&gt;&#39;&lt;tr&gt;&lt;td class=&quot;labeltext&quot;&gt;Attach a file&lt;/td&gt;&lt;td class=&quot;textbox&quot;&gt;&#39;,</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>&#39;#suffix&#39;=&gt;&#39;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#39;</div>
<div>  );</div><div>   </div><div>  // add a submit button</div><div>  $form[&#39;submit&#39;] = array(</div><div>    &#39;#type&#39; =&gt; &#39;submit&#39;,</div><div>    &#39;#value&#39; =&gt; &#39;Attach a file and submit&#39;,</div>
<div>  );</div><div>  </div><div>  </div><div>  return $form;</div><div>  }</div><div>  </div><div>  </div><div>  </div><div>function my_form_validate($form, &amp;$form_state) {</div><div><br></div><div>  // define upload field name</div>
<div>  // NOTE: this should match the name of your form file field</div><div>  $fieldName = &#39;upload&#39;;</div><div>   </div><div>  // If a file was uploaded, process it.</div><div>  if (isset($_FILES[&#39;files&#39;]) &amp;&amp; is_uploaded_file($_FILES[&#39;files&#39;][&#39;tmp_name&#39;][$fieldName])) {</div>
<div><br></div><div>    // attempt to save the uploaded file</div><div>    $file = file_save_upload($fieldName);</div><div><br></div><div>    // set error if file was not uploaded</div><div>    if (!$file) {</div><div>      form_set_error($fieldName, &#39;Error uploading file.&#39;);</div>
<div>      return;</div><div>    }</div><div>       </div><div>    // set files to form_state, to process when form is submitted</div><div>    $form_state[&#39;values&#39;][&#39;file&#39;] = $file;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div>       </div><div>  }</div><div>  else {</div><div>    // set error</div><div>    form_set_error($fieldName, &#39;Error uploading file.&#39;);</div><div>    return;   </div><div>  }</div><div>  }</div><div>  </div><div>
 function my_form_submit($form, &amp;$form_state) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>  $file =$form_state[&#39;values&#39;][&#39;file&#39;] ;</div><div> file_set_status($file, FILE_STATUS_PERMANENT);</div>
<div> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>db_query(&quot;INSERT INTO {table3} VALUES (&#39;%s&#39;)&quot;,$form_state[&#39;values&#39;][&#39;productcode&#39;]);</div><div> </div><div> }</div>
-- <br><font face="&#39;times new roman&#39;, serif"><b><i><font color="#009900">Cheers</font><br></i></b></font><font color="#C0C0C0"><b><br></b></font><br>
</div></div>