xxxxxxxxxx
const onSubmit = async (data: PropertyFormValues) => {
setValue('isPublished', true);
const {
title,
description,
price,
location,
type,
address,
parish,
island,
bedroomNumber,
bathroomNumber,
area,
isPublished,
images,
amenities,
} = data;
// Watch updated form state (optional, for debugging)
// const updatedData = watch();
// Convert form data to FormData object
const formData = new FormData();
formData.append('title', title);
formData.append('description', description);
formData.append('price', price.toString());
formData.append('location', JSON.stringify(location));
formData.append('type', type);
formData.append('address', address);
formData.append('parish', parish);
formData.append('island', island);
formData.append('bedroomNumber', bedroomNumber.toString());
formData.append('bathroomNumber', bathroomNumber.toString());
formData.append('area', area.toString());
formData.append('isPublished', isPublished.toString());
formData.append('amenities', JSON.stringify(amenities));
// Add images and amenities
if(images && images.length) images.forEach((image) => formData.append('images', image)); // Assuming `images` is an array of files
// if(amenities && images.length) amenities.forEach((amenity) => formData.append('amenities[]', amenity)); // If amenities is an array of strings
try {
const res: Response = await postNewProperty(formData);
console.log('Updated property posted:', res);
if (res) {
toast({
title: 'Property updated successfully',
description: 'This property details has been updated successfully',
});
if (typeof window !== 'undefined') {
router.push('/admin/manage-properties');
}
}
} catch (error) {
console.log('Error updating property:', error);
toast({
variant: 'destructive',
title: 'Error updating property',
description: 'An error occurred while updating property',
});
}
};
return (
<main className="p-6 pb-24 bg-neutral-offWhite space-y-5 font-sans" id='form-container'>
<Hero
title="Update Property Listing"
subtitle="Update your property details below"
/>
<Form {form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
<FormStep1 form={form} />
<FormStep2 form={form} handleMarkdownChange={handleMarkdownChange} />
<FormStep3 form={form} />
<FormStep4 />
<div className="flex items-center justify-end gap-4">
<Button
type="button"
variant="ghost"
className="w-[242px] h-auto py-3 rounded-full bg-blue-400/10 text-body font-bold text-blue-400 my-9 text-right"
>
Save as Draft
</Button>
<Button
type="submit"
className="w-[242px] h-auto py-3 rounded-full bg-blue-400 text-body font-bold text-white my-9 text-right"
disabled={form.formState.isSubmitting}
>
{form.formState.isSubmitting ? (
<span className="animate-spin">
<LoaderCircleIcon />
</span>
) : (
<span>Update Property</span>
)}
</Button>
</div>
</form>
</Form>
</main>
);
};
xxxxxxxxxx
var form_data = new FormData();
for ( var key in item ) {
form_data.append(key, item[key]);
}
$.ajax({
url : 'http://example.com/upload.php',
data : form_data,
processData : false,
contentType : false,
type: 'POST'
}).done(function(data){
// do stuff
});
xxxxxxxxxx
let form_data = new FormData(e.target);
let data = Object.formEntries(form_data.entries());
xxxxxxxxxx
const fd = new FormData();
fd.append("email", data.username);
fd.append("password", data.password);
xxxxxxxxxx
const handleSubmit = async (e) => {
e.preventDefault();
const { userName, firstName, lastName, wallet_address, email, password } =
data;
try {
let fd = new FormData();
fd.append("userName", userName);
fd.append("firstName", firstName);
fd.append("lastName", lastName);
fd.append("wallet_address", wallet_address);
fd.append("email", email);
fd.append("password", password);
const res = await getSignUp(fd);
console.log(res);
window.alert(`${res.data.message}`);
} catch (err) {
window.alert(`${err}`);
navigate("/signin");
}
};
xxxxxxxxxx
const form = document.getElementById("form");
const submitter = document.querySelector("button[value=save]");
const formData = new FormData(form, submitter);
const output = document.getElementById("output");
for (const [key, value] of formData) {
output.textContent += `${key}: ${value}\n`;
}
xxxxxxxxxx
<form id="form">
<input type="text" name="text1" value="foo" />
<input type="text" name="text2" value="bar" />
<input type="text" name="text2" value="baz" />
<input type="checkbox" name="check" checked disabled />
<button name="intent" value="save">Save</button>
<button name="intent" value="saveAsCopy">Save As Copy</button>
</form>
<output id="output"></output>
xxxxxxxxxx
#!/bin/bash
SECRET_FILE=/tmp/mounted_secret
if test -f "$SECRET_FILE";then
## Silence any outputs this command might give
## Otherwise the secret value might get exposed in the container logs
export DB_URI=$(cat $SECRET_FILE) &>/dev/null
fi
/path/app "$@"
xxxxxxxxxx
#!/usr/bin/env bash
set -e
if [ "$1" = 'postgres' ]; then
chown -R postgres "$PGDATA"
if [ -z "$(ls -A "$PGDATA")" ]; then
gosu postgres initdb
fi
exec gosu postgres "$@"
fi
exec "$@"
xxxxxxxxxx
#!/usr/bin/env bash
set -e
if [ "$1" = 'postgres' ]; then
chown -R postgres "$PGDATA"
if [ -z "$(ls -A "$PGDATA")" ]; then
gosu postgres initdb
fi
exec gosu postgres "$@"
fi
exec "$@"