The below code does file attachement without nid....I want this to be looped..as we get the "File Attachment option " 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(&$form_state)</div><div>{</div><div><br></div><div>$form['field1']=array(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>'#title'=>'',</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>'#type'=>'textfield',</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>'#prefix'=>'<table class="formtable"><tr><td class="labeltext">FIELD 1</td><td class="textbox">',</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>'#suffix'=>'</td></tr></table>',</div><div> );</div><div> </div><div> </div><div> </div><div> $form['#attributes']['enctype'] = "multipart/form-data";</div>
<div><br></div><div> // add a file upload file</div><div> $form['upload'] = array(</div><div> '#type' => 'file',</div><div> //'#title' => t('Attach a file'),</div><div>
<span class="Apple-tab-span" style="white-space:pre"> </span>'#prefix'=>'<tr><td class="labeltext">Attach a file</td><td class="textbox">',</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>'#suffix'=>'</td></tr></table>'</div>
<div> );</div><div> </div><div> // add a submit button</div><div> $form['submit'] = array(</div><div> '#type' => 'submit',</div><div> '#value' => 'Attach a file and submit',</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, &$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 = 'upload';</div><div> </div><div> // If a file was uploaded, process it.</div><div> if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name'][$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, 'Error uploading file.');</div>
<div> return;</div><div> }</div><div> </div><div> // set files to form_state, to process when form is submitted</div><div> $form_state['values']['file'] = $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, 'Error uploading file.');</div><div> return; </div><div> }</div><div> }</div><div> </div><div>
function my_form_submit($form, &$form_state) {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> $file =$form_state['values']['file'] ;</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("INSERT INTO {table3} VALUES ('%s')",$form_state['values']['productcode']);</div><div> </div><div> }</div>
-- <br><font face="'times new roman', serif"><b><i><font color="#009900">Cheers</font><br></i></b></font><font color="#C0C0C0"><b><br></b></font><br>
</div></div>