Hi have the following form:
<form action="/admin/add_news_item" method="post" name="news-form" id="news-form" enctype="multipart/form-data">
<h2><?php echo $heading; ?></h2>
<p>Use the form below to add a new news item. To add a news item fill out a title and content in Dutch followed by a title and content in English , and choose a photo. When you're don click the <strong>Add news item</strong> button.</p>
<input name="language_abbr_nl" id="language_abbr_nl" type="hidden" value="nl">
<fieldset>
<label>News title (Dutch) <span>*</span></label>
<input name="news_title_nl" id="news_title_nl" type="text" class="textfield" tabindex="1" required>
</fieldset>
<fieldset >
<label>News content (Dutch)</label>
<textarea name="news_content_nl" id="news_content_nl" class="textarea h100" tabindex="2"></textarea>
</fieldset>
<input name="language_abbr_en" id="language_abbr_en" type="hidden" value="en">
<fieldset>
<label>News title (English) <span>*</span></label>
<input name="news_title_en" id="news_title_en" type="text" class="textfield" tabindex="3" required>
</fieldset>
<fieldset >
<label>News content (English)</label>
<textarea name="news_content_en" id="news_content_en" class="textarea h100" tabindex="4"></textarea>
</fieldset>
<fieldset>
<label>News photo <span>(<a href="#" title="The best dimensions for a photo are 1000 x 400 px." class="masterTooltip">?</a>)</span></label>
<input name="file" id="file" type="file" tabindex="5" required>
</fieldset>
<fieldset class="top-margin">
<button type="submit" class="form_button" tabindex="6">Add news item</button>
</fieldset>
</form>
I furthermore have the following action in the controller:
public function add_news_itemAction()
{
$photo_path = APP_PATH.'/../httpdocs/images/news_photos/';
include_once (APP_PATH.'/helpers/zebra_image.php');
$validextensions = array("jpeg", "jpg", "png");
$original_name = $_FILES['file']['name'];
$ext = explode('.', basename($original_name));
$file_extension = strtolower(end($ext));
$new_name = md5(uniqid()) . "." . $file_extension;
$new_photo_path = $photo_path . $new_name;
$language_abbr_nl = filter_input(INPUT_POST, 'language_abbr_nl', FILTER_SANITIZE_STRING);
$language_abbr_en = filter_input(INPUT_POST, 'language_abbr_en', FILTER_SANITIZE_STRING);
$news_title_nl = filter_input(INPUT_POST, 'news_title_nl', FILTER_SANITIZE_STRING);
$news_title_en = filter_input(INPUT_POST, 'news_title_en', FILTER_SANITIZE_STRING);
$news_content_nl = filter_input(INPUT_POST, 'news_content_nl', FILTER_UNSAFE_RAW);
$news_content_en = filter_input(INPUT_POST, 'news_content_en', FILTER_UNSAFE_RAW);
$news_id = $this->page->add_news_item($language_abbr_nl,$news_title_nl,$news_content_nl);
if ( is_uploaded_file($_FILES['file']['tmp_name']) )
{
$this->create_image($_FILES['file']['tmp_name'], $new_photo_path , 1000, 400, ZEBRA_IMAGE_CROP_CENTER);
$this->page->add_news_photo($news_id,$new_name);
$insert = $this->page->add_news_item($language_abbr_en,$news_title_en,$news_content_en);
}
}
As you can see from the form is this about inserting The content for one language first, followed by the upload in insert of a photo holding the news_id from the just inserted news_item, followed by the insert of the second language (this one doesn’t need a photo attached to it.
When I submit the form in inserts for the 2 languages are going well but I get the following errors for file
Undefined index: file in C:\wamp\www…on line 138
Undefined index: file in C:\wamp\www…on line 153
Does anyone see what i’m doing wrong?
Thank you in advance